Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2006
    Posts
    104

    Unanswered: Basic question on SQL indexes

    I have a table xxx with cols c1, c2,c3,c4 in schema schema1

    ihave created index for table xxx as

    CREATE INDEX "SCHEMA1 "."IDX907092354290000" ON "SCHEMA1 "."XXX" ("C1" ASC, "C2" DESC, "C3" ASC) ALLOW REVERSE SCANS ;

    which of the the sql query will use the index

    SELECT C4 FROM SCHEMA1.XXX WHERE C1="A"
    SELECT C4 FROM SCHEMA1.XXX WHERE C2="B" AND C3="C"


    SELECT C4 FROM SCHEMA1.XXX WHERE C3="C"

    thanks

    harikumar

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Only the first query will use the b-tree of the index, which is by far the most efficient access path (assuming it is not a small table).

    The other queries "may" or "may not" use the index, but if they use it, DB2 will have to read the entire index, sort of like a table scan on the index. The reason for that is that the first column of the index is not in the predicate.

    You can google "b-tree index" to find out what that means if you don't understand.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •