This action might not be possible to undo. Are you sure you want to continue?
The row set can be a base table, a view, or the result of a join or a GROUP BY operator. The selectivity is tied to a query predicate, such as last_name = 'Smith', or a combination of predicates, such as last_name = 'Smith' AND job_type = 'Clerk'. A predicate filters a specific number of rows from a row set. Thus, the selectivity of a predicate indicates how many rows pass the predicate test. Selectivity ranges from 0.0 to 1.0. A selectivity of 0.0 means that no rows are selected from a row set, whereas a selectivity of 1.0 means that all rows are selected. A predicate becomes more selective as the value approaches 0.0 and less selective (or more unselective) as the value approaches 1.0.
A composite index contains multiple key columns. Composite indexes can provide additional advantages over single-column indexes: Improved selectivity - Sometimes you can combine two or more columns or expressions, each with poor selectivity, to form a composite index with higher selectivity. It reduces the number of indexes needed to support a range of queries. This increases performance by reducing index maintenance and decreases wasted space associated with multiple indexes.
A SQL statement can use an access path involving a composite index when the statement contains constructs that use a leading portion of the index. A leading portion of an index is a set of one or more columns that were specified first and consecutively in the list of columns in the CREATE INDEX statement that created the index. Consider this CREATE INDEX statement:
CREATE INDEX comp_index ON table1(x, y, z);
x, xy, and xyz combinations of columns are leading portions of the index yz, y, and z combinations of columns are not leading portions of the index
The index skip scan was introduced to allow Oracle to “skip” leading-edge predicates in a multi-column index. You can force an index skip scan with the /*+ index_ss */ hint. For example, consider the following concatenated index on a super-low cardinality column, following by a very selective column:
create index sex_emp_id on emp (sex, emp_id);
Prior to Oracle9i, this index could only be used with both sex and emp_id were present in the SQL query, or when the sex column was specified. The following query would not be able to use the concatenated index:
select emp_id from emp where emp_id = 123;
The Oracle9i/onwards skip scan execution plan allows for our concatenated index to be used, even though sex is not specified in the SQL query WHERE clause. The index skip scan promises that there is no need to build a second index on the emp_id column, since it is technically redundant to the multicolumn index. Oracle acknowledges that the index skip scan is not as fast as a direct index lookup, but states that the index skip scan is faster than a full-table scan.
com.com.com. the database searches the subindex with the value F first and then searches the subindex with the value M. especially if their combined selectivity is better than the selectivity of either key individually. the number of logical subindexes is determined by the number of distinct values in the leading column. When searching for the record for the customer whose email is Abbey@company.rowid F. Assume that a composite index exists on the columns (cust_gender.customers WHERE cust_email = 'Abbey@company.com' UNION ALL SELECT * FROM sh. Example 11–6 Composite Index Entries F. Skip scanning lets a composite index be split logically into smaller subindexes.rowid F.rowid F.customers (cust_gender. In skip scanning.com.rowid F. the leading column has two possible values.Wolf@company. Often.com. In a skip scan.Wood@company.customers WHERE cust_gender = 'F' AND cust_email = 'Abbey@company.Abbassi@company.rowid M.rowid M. For example. assume that you run the following query for a customer in the sh. In other words.Wolsey@company.com. Conceptually.Woodman@company.rowid The database can use a skip scan of this index even though cust_gender is not specified in the WHERE clause. The customers table has a column cust_gender whose values are either M or F. then consider creating a composite index containing all of these keys.Zimmerman@company. The database logically splits the index into one subindex with the key F and a second subindex with the key M. The database may choose an index skip scan when the leading column of the composite index is not specified in a query predicate. ■ If several queries select the same set of keys based on one or more key values. the database processes the query as follows: SELECT * FROM sh.com. Skip scanning is advantageous when there are few distinct values in the leading column of the composite index and many distinct values in the nonleading key of the index. Example 11–6 shows a portion of the index entries. it is skipped.customers table: SELECT * FROM sh.com. cust_email) that was created as follows: CREATE INDEX customers_gender_email ON sh.Yang@company. consider the guidelines associated with the general performance .com'. cust_email). Of course.rowid F.com. scanning index blocks is faster than scanning table data blocks. Choosing Keys for Composite Indexes Follow these guidelines for choosing keys for composite indexes: ■ Consider creating a composite index on keys that appear together frequently in WHERE clause conditions combined with AND operators.Index Skip Scans Index skip scans improve index scans by nonprefix columns.Abbey@company. The database determines the number of logical subindexes by the number of distinct values in the initial column.customers WHERE cust_gender = 'M' AND cust_email = 'Abbey@company.com'. In Example 11–6. the initial column of the composite index is not specified in the query.
The result is several separate searches of a single index that. when combined. Each of these distinct values is then used as a starting point for a regular index search. . In these situations skip scanning reduces the impact of makeing the "wrong" decision.advantages and trade-offs of indexes described in the previous sections. then place this key first in the composite index. eliminate the affect of the prefix column. ■ If some keys appear in WHERE clauses more frequently. The optimizer uses statistics to decide if a skip scan would be more efficient than a full table scan. then create the index so that the more frequently selected keys make up a leading portion to allow the statements that use only these keys to use the index. How It Works Rather than restricting the search path using a predicate from the statement. Skip Scans are initiated by probing the index for distinct values of the prefix column. Ordering Keys for Composite Indexes Follow these guidelines for ordering keys in composite indexes: ■ Create the index so the keys used in WHERE clauses make up a leading portion. These two conditions do not always go hand in hand which makes the decision difficult. This approach is advantageous because: The prefix column should be the most discriminating and the most widely used in queries. the index has been searched from the second level down. Essentially. ■ If all keys appear in WHERE clauses equally often but the data is physically ordered on one of the keys.