Documente Academic
Documente Profesional
Documente Cultură
The optimizer will take into account a composite index when the WHERE clause in a query refers to all the columns in the index or even the leading column. This was traditional behaviour. The introduction of INDEX SKIP SCAN changes this default behaviour. In earlier releases of the Oracle Database, a SQL statement used a composite index only if the statement's constructs used a leading portion of the index. The leading portion of an index is one or more columns in the index that are specified first in the list of columns. For example, say you have the following composite index:
EMPLOYEE_ENTITY.sql
No. of BLOCKS in the table = 251 STEP 2: INDEX the columns LASTNAME, JOB_ID, GENDER in 6 different orders LASTNAME has highest cardinality (all distinct values) JOB_ID has medium cardinality (few distinct values) GENDER has lowest cardinality (very few distinct values, only M and F)
IND.sql
INDEX NAME EE_GJL_CI EE_GLJ_CI EE_JGL_CI EE_JLG_CI EE_LGJ_CI EE_LJG_CI 9004 17805 9004 9886 25097 25097
CLUSTERING FACTOR
Based on the table above, EE_GJL_CI and EE_JGL_CI are the best ordered index (despite the clustering factor being much higher than the number of blocks) and even though GENDER column has low cardinality. STEP 4 : Performance statistics:
DEFAULT OPTION USED BY OTIMIZER
EE_LJG_CI
EE_LGJ_CI
EE_JGL_CI
EE_JLG_CI
EE_GLJ_CI
EE_GJL_CI
Q1.sql
EE_GJL_CI
Q2 Lastname cost = 3 INDEX RANGE SCAN cost = 3 INDEX RANGE SCAN cost = 12 INDEX SKIP SCAN cost = 12 INDEX SKIP SCAN cost = 4 INDEX SKIP SCAN cost = 12 INDEX SKIP SCAN
Q2.sql
Q3 JOB_ID
Q3.sql
Q4 GENDER
Q4.sql
Q5 LASTNAME, JOB_ID cost = 3 INDEX RANGE SCAN cost = 3 INDEX RANGE SCAN cost = 4 INDEX SKIP SCAN cost = 3 INDEX RANGE SCAN cost = 4 INDEX SKIP SCAN cost = 4 INDEX SKIP SCAN
Q5.sql
EE_JLG_CI
Q6 LASTNAME, GENDER cost = 3 INDEX RANGE SCAN cost = 3 INDEX RANGE SCAN cost = 12 INDEX SKIP SCAN cost = 12 INDEX SKIP SCAN cost = 3 INDEX RANGE SCAN cost = 13 INDEX SKIP SCAN
Q6.sql
Q7 JOB_ID, GENDER
Q7.sql
IF Full Table Scan is used for all these queries : the cost for all queries is 144 SELECT /*+ full(EMPLOYEE_ENTITY) * from EMPLOYEE_ENTITY WHERE
FTS.sql
CONCLUSION:
When creating a composite index, a big question is how to order the columns in the multi-column index. Oracle recommends that you place the most commonly accessed column first in the index. Traditionally, it was thought that you should avoid using a low cardinality column (a column with few distinct values) as the leading column in a composite index. However, regardless of the index order, the database can navigate straight to the leaf block containing the indexed column values because the index leaf branch entries contain column entries based on all indexed columns. In fact, a leading column with lower cardinality may have more advantages, as the optimizer is likely to at least consider using an index skip scan in these cases. It has also been suggested to use the clustering factor as a criterion when deciding which column should be the leading index column in a composite index. The clustering factor indicates how well ordered the tables rows are in comparison to the way the index entries are ordered in an index. FROM the table above, we can infer that concatenated/ composite indexes are good if we frequently query on columns : (LASTNAME,JOB_ID,GENDER) or (LASTNAME, JOB_ID) or (LASTNAME,GENDER) or (LASTNAME). From the above table, the index EE_LGJ_CI, though having a high clustering factor, is more beneficial* compared to other indexes.