Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do composite indexes work?

I've created composite indexes (indices for you mathematical folk) on tables before with an assumption of how they worked. I was just curious if my assumption is correct or not.

I assume that when you list the order of columns for the index, you are also specifying how the indexes will be grouped. For instance, if you have columns a, b, and c, and you specify the index in that same order a ASC, b ASC, and c ASC then the resultant index will essentially be many indexes for each "group" in a.

Is this correct? If not, what will the resultant index actually look like?

like image 781
Joe Phillips Avatar asked Apr 27 '09 19:04

Joe Phillips


People also ask

What is a composite index How does it work?

A composite index is a statistical tool that groups together many different equities, securities, or indexes in order to create a representation of overall market or sector performance. Typically, the elements of a composite index are combined in a standardized way so that large amounts of data can be presented easily.

How are composite indexes stored?

How does composite index work? The columns used in composite indices are concatenated together, and those concatenated keys are stored in sorted order using a B+ Tree.

How do composite indexes work Oracle?

A composite index, also called a concatenated index, is an index on multiple columns in a table. Columns in a composite index should appear in the order that makes the most sense for the queries that will retrieve data and need not be adjacent in the table.


1 Answers

Composite indexes work just like regular indexes, except they have multi-values keys.

If you define an index on the fields (a,b,c) , the records are sorted first on a, then b, then c.

Example:

| A | B | C | ------------- | 1 | 2 | 3 | | 1 | 4 | 2 | | 1 | 4 | 4 | | 2 | 3 | 5 | | 2 | 4 | 4 | | 2 | 4 | 5 | 
like image 96
Rik Avatar answered Sep 22 '22 00:09

Rik