oracle first_rows怎么用,优化模式区别(all_rows first_rows_n)

Why is my index not used?

* The table is indexed isn’t it? 🙂

* Why SHOULD the index be used?

* Are the indexed columns/leading column of the index supplied in the where clause of the query (predicate list) as a single table (non-join) predicate?

No:

At least the leading column of an index is required in the predicate list to use an index in a query (but see Skip Scan below.)

Example:

You have defined index EMPNO_I1 on single column EMP.EMPNO, and defined concatenated index EMPNO_DEPT_I2 on columns EMP.EMPNO and EMP.DEPT (note, EMP.EMPNO is leading column).

You must use the column EMP.EMPNO in the predicate list (WHERE clause) in order for the optimizer to consider either index:

Select ename, sal, deptno from emp where empno<100;

Exceptions:

+ CBO can use a Index Fast Full Scan (INDEX_FFS) as long as the index contains all the columns that are needed for the query, and at least one column in the index key has the NOT NULL constraint. The leading column of an index is not required for an INDEX_FFS to be performed. Note that the use of an INDEX_FFS does not necessarily return the rows in sorted order. Ordering is dependent on the order that the index blocks are read and rows are only guaranteed to be returned in a sorted order if an 'order by' clause is used. See: Note 344135.1 Ordering of Result Data

Note:70135.1 Index Fast Full Scan Usage To Avoid Full Table Scans

+ CBO can use an Index Skip Scan (INDEX_SS). The leading column of an index is not required for an INDEX_SS to be performed.

See Note:212391.1 Index Skip Scan Feature

+ CBO can choose to use an index to avoid sorting. The indexed columns would need to be in the order by clause for this to happen.

See Note:67409.1, and Note:10577.1

Are the indexed columns part of join predicates? e.g. emp.deptno= dept.deptno

*

If Yes then:

What type of join is used?

Only a Nested loops join can allow index lookups on the inner table that are based solely on the join column(s):

Hash / Sort Merge Join:

With Hash joins and Sort Merge joins, information from the outer table is not available at join time to enable row look ups on the inner table; rather both tables are accessed separately and then the resultant data is joined. The inner table of a Hash or Sort Merge cannot be probed solely using an index based on the join columns . This is an inherent limitation of the implementation mechanisms used by these join types. Nested Loops joins are different in as much as they allow index lookups on the join columns.

Nested Loops Join:

Nested loop joins work by reading the outer table and then using the information gathered to probe the inner table. This algorithm allows index lookups to occur on the inner table.

Does the join order allow index usage?

Due to this limitation, the join order of the tables is important. The outer table of a nested loops join must have been vistied BEFORE an index can be used on the inner table. Check the explain plan for the query to determine which access path has been used. For example: If there is an index on EMP.DEPTNO and, assuming ther eare no other predicates that relate to EMP.DEPTNO int the query, EMP is visited before DEPT, then no values are present that can be used to lookup rows in the EMP.DEPTNO index. The only way the index could be used is with a full index scan or a index fast full scan. In this case it is possible that a Full Table Scan (FTS) will cost less and be chosen instead. The RBO would not even consider using the index.

* Are the indexed columns part of an IN list or multiple OR's? e.g. emp.deptno IN (10,23,34,….)

It is possible that the query has been transformed in to something that cannot use an index. See Note:62153.1

* Are the indexed columns modified by functions?

Indexes cannot be used on columns modified by functions. Oracle 8i adds function based indexes.

Is implicit type conversion going on?

*

If the datatypes of two values being compared are different, then Oracle has to implement type conversion on one of the values to enable comparisons to be made. This is called implicit type conversion. Typically this causes problems when developers store numbers in character columns. At runtime oracle is forced to convert one of the values and (due to fixed rules) places a to_number around the indexed character column. Adding any function to an indexed column prevents use of the index. The fact that Oracle has to do this type conversion is an indication of a design problem with the application. Because conversion is performed on EVERY ROW RETRIEVED, this will also result in a performance hit.

Is it semantically impossible to use an index?

*

Because of cost considerations on the query as a whole, a plan may have been chosen that means that the use of an index at a lower level is now not possible. The index may have been considered in other join orders/methods but the method with the lowest cost makes the index unusable. Because of the way the query has been executed (i.e. join orders/methods) it is now 'semantically impossible' to use an index.

Is the 'wrong type' of index scan made? e.g. Index fast full scan as opposed to index range scan

*

It is possible that the optimizer has chosen the desired index but a different scan method would be preferable to the user. In this case utilise the INDEX_FFS, INDEX_ASC and INDEX_DESC hints to force the scan type that you require.

See Note:62339.1 for more information.

@ PAA content management, action #23093

Since Oracle8i indexes alternatively can be defined with ascending or decending sort order. Oracle treats descending indexes as if it were function-based indexes and therefore a different execution plan might be used compared to that used for a default ascending sort order. By examine the execution plan you do not see whether the default ascending order or the descending sort order will be used therefore additionally check the 'DESCEND' column of view DBA_IND_COLUMNS.

Are Accurate and Appropriate statistics in place?

*

The CBO relies on accurate, up to date and complete statistics to enable it to determine the optimal access plan for a particular query. Ensure that statistics have been gathered if the intention is to use the CBO. Using CBO with no statistics will force the CBO to use predefined defaults which are unlikely to produce a good plan or promote index usage with your application. See Note:35934.1 for more details.

Remember that the CBO may choose a different index because the costs indicate that this is appropriate. The RBO uses a rigid system of rules to determine what access method to use.

In addition to basic table and index statistics, column statistics should be gathered for columns with a non-uniform data distribution. For advice on gathering statistics see Note:44961.1 TECH: Comments on Frequency of using ANALYZE

@ PAA content management, action #23093

In general, new statistics should be gathered after a schema object’s data or structure are modified in ways that make the previous statistics inaccurate. For example, after loading a significant number of rows into a table, collect new statistics on the number of rows. It is also recommended to gather new statistics information after having installed a new patchset. The table access works best when the statistics have been generated by the same version as currently executing. More information about "Why is my querries slow since upgrading the database" can be found in note <>

Does the index have the same rank or cost as another index?

*

If there is a choice between equally ranked access methods, then the RBO uses the order in the row cache to decide on which index to use (with equally ranked tables it uses from clause order from right to left). With equally costed indexes, the CBO uses various ways to break the tie e.g. alphabetical order of index name, bigger NDK for fully matched indexes (not for fast full scans) or index with lower number of leaf blocks. Note that this is unlikely to be a common occurrence.

See Note:73167.1 for more information.

Is the index unselective?

*

The index is unselective

It may not be a good idea to use it anyway… The column data does not have a uniform distribution

The CBO assumes that column data is not skewed and is uniformly distributed. If this is not the case then the statistics may not reflect the actuality and indexes may not be chosen for some selective values because of the unselective nature of the column as a whole. If this is the case then consideration should be given to the creation of histograms to record a more accurate picture of column data distribution or alternatively use hints. The optimizer statistics are inadequate making indexes appear unselective

Possible workarounds:

gather more accurate stats. See Note:44961.1 TECH: Comments on Frequency of using ANALYZE

consider gathering column statistics where column data is not uniform

use hints. See Note:29236.1 QREF: SQL Statement HINTS and Note:50607.1 How to specify an INDEX Hint

Are the indexed columns NULLable?

*

Indexes do NOT store NULL values unless the index is concatenated (i.e. multi-column indexes), or it is a Bitmap index.

For concatenated indexes NULLs are only stored if at least one of the indexed columns is filled. Trailing NULLs in concatenated indexes are stored. Rows are not stored if all the indexed columns are NULL. Operations that need to return the NULL values (such as count) may be prevented from using the index because of the lack of NULL values in the index. This is because the optimizer cannot guarantee that it can retrieve the necessary information using the index alone. There are also considerations with using NOT IN predicates and NULL values. See Note 28934.1

Bitmap indexes are allowed to store NULLs. Therefore, they are considered NULLable and the optimizer may use them whether they are NULL safe or not. Indexing of nulls can be useful for some types of SQL statements, such as queries with the aggregate function COUNT. Example: SELECT COUNT(*) FROM EMP; For more information on Bitmap indexes See Note 70067.1 All about Bitmap Indexes, or Oracle Concepts Database Concepts Manual.

Are views/subqueries involved?

*

Queries involving these structures are likely to be rewritten which may result in indexes not being used (even though one of the goals of the rewrite is to open up additional access paths). This rewrite is known as merging. See Note.199070.1 Optimizing statements that contain views or subqueries

Are any of the tables remote?

*

Often indexes are not used against remote tables. Index usage in distributed queries is dependant on the query that is sent to the remote site. Often, with RBO, the query sent to the remote site does not contain indexed predicates. this can often result in a FTS. The CBO costs the remote access and will evaluates and compare the costs with and without indexed predicates sent to the remote site. Thus the CBO should make a more informed decision about index usage on remote tables. Building a view on the remote site containing relevant predicates to force index usage and then referencing that in your local query can often help. See Note:68809.1 Distributed Queries

Is Parallel Execution (PX) involved?

*

The index access paths available under Parallel Execution are more restricted than under serial execution. A quick test is to disable parallelism for the query and see if this enables the index to be used.

Is the query an update with a subquery?

*

There may be cases, due to cost considerations why an index is not chosen because it depends on values returned from a subquery. It may be possible to force the index to be used by implementing hints. See Note:68084.1 Using hints to optimize an Update with a subquery that is not using an index on the updated table.

Does the query use bind variables?

*

The CBO cannot generate accurate cost figures for like or range predicates against bind variables. This may result in indexes not being chosen. See Note:68992.1 Predicate Selectivity

Index hints don’t work

*

Remember to use table aliases. See Note:69992.1 Why is my hint ignored? and Note:50607.1 How to specify an INDEX Hint

Useful hints: Also See Note:29236.1 QREF: SQL Statement HINTS

FIRST_ROWS Likely to promote the use of indexes

ORDERED Forces the join order of a query

INDEX Forces an Index scan. Disables use of FAST mode (INDEX_FFS)

INDEX_FFS Forces an Index to be scanned in FAST mode

INDEX_ASC Forces an Ascending Index Range Scan

INDEX_DESC Forces a Descending Index Range Scan

* Deletes do not necessarily free up allocated index space

Reorganization, Truncation or Deletion of data may or may not have cost implications for queries. Remember that deletes do not necessarily free up allocated space from objects. In addition, deletes do not reset the highwatermark for a table. Truncate does. Empty blocks may make indexes/tables appear more expensive than they potentially could be. Dropping and recreating the object will reorganise the structure and may potentially help (or may hinder). This problem is usually most noticeable when comparing the query performance of two different systems with the same data.

Are partition views involved?

*

Is the partition view setup correctly? See Note:28426.1 Partition Views and the use of Indexes (7.1 & 7.2) and Note:43194.1 Partition Views in 7.3: Examples and Tests

Is NLS_SORT set to BINARY?

*

If NLS_SORT is not set to BINARY, indexes will not be used. This is because indexes are built according to a binary order of keys (pre-sorted using binary values). Setting NLS_SORT to anything other than BINARY causes a sort to use a full table scan, regardless of the path chosen by the optimizer. For more detail on NLS_SORT and index use please reference: Note 30779.1 Init.ora Parameter “NLS_SORT” Reference, and Note 227335.1 Linguistic Sorting – Frequently Asked Questions (section 4.)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/547610.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

svn 客户端批量备份数据(图+文)

缘由 商业用途的规则&#xff0c;数据与谨慎便成了不可替代的王道&#xff0c;我今天也说svn&#xff0c;在客户端批量备份数据。 前提 考虑跨平台与易用性&#xff0c;选择批处理&#xff08;.bat&#xff09;&#xff0c;既然是批处理&#xff0c;少不了的便是命令和执行命…

Vue项目 报错TypeError [ERR INVALID ARG TYPE]: The “path“ argument must be of type string

# Vue项目 报错TypeError [ERR INVALID ARG TYPE]: The “path“ argument must be of type string 卡了半天&#xff0c;原来是sassloader版本过高导致的&#xff0c; 解决方法: 回退7.版本npm uninstall sass-loader&#xff08;卸载当前版本&#xff09; npm install sass…

使用python来访问Hadoop HDFS存储实现文件的操作

在调试环境下&#xff0c;咱们用hadoop提供的shell接口测试增加删除查看&#xff0c;但是不利于复杂的逻辑编程查看文件内容www.xiaorui.cc用python访问hdfs是个很头疼的事情。。。。这个是pyhdfs的库import pyhdfs fs pyhdfs.connect("192.168.1.1", 9000) pyhdfs.…

Jquery取得iframe中元素的几种方法Javascript Jquery获取Iframe的元素、内容或者ID,反之也行!

jquery取得iframe中元素的几种方法 在iframe子页面获取父页面元素 代码如下:$(#objId, parent.document);// 搞定...在父页面 获取iframe子页面的元素代码如下:$("#objid",document.frames(iframename).document) $(document.getElementById(iframeId).contentWind…

oracle中trunc x-1,oracle中trunc函数的说明

一、oracle trunc()函数的用法TRUNC(for dates)精确到天 select trunc(sysdate,dd) from dual 结果为&#xff1a;2010-9-17精确到月 select trunc(sysdate,mm) from dual 结果为&#xff1a;2010-9-1精确到年 select trunc(sysdate,yy) from dual 结果为&#xff1a;2010-1-1T…

Html去掉链接虚线边框

html去除图片链接边框及其链接虚线οnfοcus"this.blur();"用图片做为链接后&#xff0c;在图片的周围出现了一个带颜色边框用<a href"#"><img src"" border"0"></a>就去掉了边框当点击图片时&#xff0c;又出现了虚…

vue+axios请求时设置request header请求头(带上token)

vueaxios请求时设置请求头&#xff08;带上token&#xff09; 1.在vue中&#xff0c;向后台发送请求&#xff0c;不管是get或post&#xff0c;url要带上userId&#xff0c;headers要带上token值&#xff08;本地存储的token&#xff0c;window.localStorage[‘token’]&#x…

LINQ能不能用系列(一)LINQ to Object 效率比对

前言 简介&#xff1a;LINQ&#xff0c;语言集成查询&#xff08;Language INtegrated Query&#xff09;是一组用于c#和Visual Basic语言的扩展。 分类&#xff1a;LINQ to Object, LINQ to XML, LINQ to SQL, LINQ to DataSet&#xff0c;LINQ to ADO.NET。 相关&#xff…

oracle应收模块核销点不上,详解EBS接口开发之应收款处理

(一)应收款常用标准表简介1.1常用标准表如下表中列出了与应收款处理相关的表和说明&#xff1a;表名说明其他信息AR_BATCHES_ALLAR收款批表AR_BATCH_SOURCES_ALLAR收款类型表对应视图AR_CASH_RECEIPTS_ALLAR收款表对应视图AR_CASH_RECEIPT_HISTORY_ALLAR收款历史表对应视图AR_M…

防雷避险手册

为什么80%的码农都做不了架构师&#xff1f;>>> 防雷避险手册 防雷避险手册.pdf 转载于:https://my.oschina.net/tadcat/blog/148504

OpenCV调用YOLOv4进行目标检测

目标检测就是对目标进行动态实时跟踪定位&#xff0c;常见的目标检测算法有 R-CNN、Fast R-CNN、Faster R-CNN、SSD、Yolo 等&#xff0c;其中 Yolo 的速度和精确度都比较高&#xff0c;且只需训练一次&#xff0c;使用起来比较方便。 这里我们就使用官方现成的模型来检测图片…

2024年3月电子学会青少年编程等级考试时间安排

1考试方式 1. 在线居家考试&#xff08;全国&#xff09;&#xff1b; 2. 对于符合线下考试要求的考试服务网点&#xff0c;经地方实地调研报学会总部批准后&#xff0c;可组织线下考试。 2报名时间 报名时间&#xff1a;2023年12月21日-2024年3月12日16:00&#xff1b; 考…

Sql Server常用时间段查询汇总

前言 本文对应Sql Server 中常用的时间查询的进行一些汇总&#xff0c;例如查询当天的、本周的、本月的、本季度的&#xff0c;某个时间段内的时间。 实例 实例&#xff08;我的&#xff09;表名&#xff1a;mytable 字段名&#xff1a;mydate &#xff08;一&#xff09;、…

scan-cvs-user.sh

为什么80%的码农都做不了架构师&#xff1f;>>> scan-cvs-user.sh #! /bin/sh export LC_ALLzh_CN.UTF-8 cd /bin2/ sh scan-cvs-user-daily.sh > scan-cvs-user-daily.sh.log 2>&1 /usr/bin/mutt -s "scan-cvs-user-daily" scm-svr-mtrsc…

CV2 puttext不能显示中文问题

CV2 puttext不能显示中文问题&#xff0c;还是这个方法管用&#xff1a; 解决方法&#xff1a;将图片格式转化为PIL库的格式&#xff0c;用PIL的方法写入中文&#xff0c;然后在转化为CV的格式 但是采用如下方案会导致性能降低&#xff0c;毕竟多加了一次转化格式。 from P…

LINQ能不能用系列(二)LINQ to SQL 效率比对

前言 很多人听说过LINQ TO SQL与ADO.NET传统方式用于不同的环境&#xff0c;LINQ TO SQL与ADO.NET传统方式也没有可比性&#xff0c;就像公交车与私家车一样&#xff0c;虽然是车但用途完全不同&#xff0c;但很少有人去探究&#xff0c;究竟为什么他们不同&#xff0c;他们不…

libgdx游戏引擎开发笔记(十三)SuperJumper游戏例子的讲解(篇七)----各个物体的创建及其碰撞检测...

接着上一篇&#xff0c;我们完成后续的扫尾工作&#xff1a;游戏中个物体创建及其碰撞检测,分数保存&#xff0c;音效处理。1.World类&#xff1a;&#xff08;加入所有物体&#xff0c;及其碰撞检测&#xff0c;代码里有详细注解&#xff09;package com.zhf.mylibgdx; import…

oracle交流 提问,Oracle相关提问的智慧技巧

《很久以前的一篇对初学Oracle建议的文章》曾提到了提问的智慧&#xff0c;这个问题确实很值得说&#xff0c;我在学生时期&#xff0c;尤其是在本硕阶段中&#xff0c;作为非科班出身&#xff0c;要接触很多新的计算机技术&#xff0c;日常做的最多的&#xff0c;可能就是问问…

yolov5的flask部署python调用

yolov5 github&#xff1a;https://github.com/ultralytics/yolov5 跟踪&#xff1a;https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch TensorRT&#xff1a;https://github.com/TrojanXu/yolov5-tensorrt NCNN&#xff1a;https://github.com/WZTENG/YOLOv5_NCNN …

Sql Server内置函数实现MD5加密

实例 MD5加密“123456”&#xff1a; HashBytes(MD5,123456) 结果&#xff1a;0xE10ADC3949BA59ABBE56E057F20F883E &#xff08;提示&#xff1a;看完最后&#xff0c;结果要进行转换。&#xff09; 函数 函数描述返回值 HashBytes HashBytes (加密方式, 待加密的值)加密方…