A composite index, also called a concatenated index, is an index on multiple columns in a table.
Place columns in a composite index in the order that makes the most sense for the queries that will retrieve data. The columns need not be adjacent in the table.
kubernetes training courses malaysia
Composite indexes can speed retrieval of data for SELECT statements in which the WHERE clause references all or the leading portion of the columns in the composite index. Therefore, the order of the columns used in the definition is important. In general, the most commonly accessed columns go first.
juniper networks training courses malaysia
For example, suppose an application frequently queries the last_name, job_id, and salary columns in the employees table. Also assume that last_name has high cardinality, which means that the number of distinct values is large compared to the number of table rows. You create an index with the following column order:
CopyCREATE INDEX employees_ix
ON employees (last_name, job_id, salary);
Queries that access all three columns, only the last_name column, or only the last_name and job_id columns use this index. In this example, queries that do not access the last_name column do not use the index.
jboss training courses malaysia
Note
In some cases, such as when the leading column has very low cardinality, the database may use a skip scan of this index (see “Index Skip Scan”).
Multiple indexes can exist on the same table with the same column order when they meet any of the following conditions:
- The indexes are of different types.For example, you can create bitmap and B-tree indexes on the same columns.
- The indexes use different partitioning schemes.For example, you can create indexes that are locally partitioned and indexes that are globally partitioned.
- The indexes have different uniqueness properties.For example, you can create both a unique and a non-unique index on the same set of columns.
For example, a nonpartitioned index, global partitioned index, and locally partitioned index can exist for the same table columns in the same order. Only one index with the same number of columns in the same order can be visible at any one time.
jboss enterprise application platform training courses malaysia
This capability enables you to migrate applications without the need to drop an existing index and re-create it with different attributes. Also, this capability is useful in an OLTP database when an index key keeps increasing, causing the database to insert new entries into the same set of index blocks. To alleviate such “hot spots,” you could evolve the index from a nonpartitioned index into a global partitioned index.
If indexes on the same set of columns do not differ in type or partitioning scheme, then these indexes must use different column permutations. For example, the following SQL statements specify valid column permutations:
CopyCREATE INDEX employee_idx1 ON employees (last_name, job_id);
CREATE INDEX employee_idx2 ON employees (job_id, last_name);
Leave a Reply