4

if we have a table T1 with columns A,B,C,D,E and an index ( A,B,C) built for it

if we a SQL query joining on columns A,B or A,B,C or A, this index can still be used, but if the query is joining on B or C or B,C the index is totally useless

I know indexes are often implemented BTree , I want to know how is the implementation detail related with this ?

asked Jan 15, 2014 at 6:50
3

1 Answer 1

4

This is not necessarily the case. Oracle, for example, has an access path known as an "index skip scan". See http://docs.oracle.com/cd/B10501_01/server.920/a96533/optimops.htm#51553

Basically, if there are few distinct values in column A, and the query restricts on column B (and optionally, column C), the executor will substitute each of the distinct values of column A in turn and probe the index for the supplied value of column B (and optionally, column C).

Postgresql can do something similar, but it is still labelled as an "index scan", see Working of indexes in PostgreSQL

answered Jan 15, 2014 at 9:35
2
  • 1
    There is a Connect item that one can vote for implementing this in SQL-Server: MS Connect: Implement Index Skip Scan Commented Jan 15, 2014 at 10:11
  • I think this states that my assertion is not necessarily true. but without considering this, how does DB apply INDEX ABC on column AB join ? is that by comparing only the AB part of the index key ? Commented Jan 16, 2014 at 8:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.