Results 1 to 6 of 6
  1. #1
    Join Date
    May 2004
    Posts
    2

    Unanswered: Command SELECT... ORDER with index

    Hello,

    Is it possible to use index when we have to use only the clause ORDER ? (I needn't to use the clause WHERE)

    Can we have the possibility to use an index with the clause "ORDER" ?

    Example :
    Select *
    from view
    order by a, b, c

    I would like tio create an index ordered like a,b, c

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Yes, and DB2 will probably use the index and avoid a sort.

    Andy

  3. #3
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    Most likely db2 will use an index ...

    There may be occasions(based on statistics, of course) when there may be a tablescan ...

    I assume the columns a.b and c in the view are not based on functions ...

    HTH

    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  4. #4
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Yes, DB2 may decide to use an index in lieu of a sort. But there is no guarantee, and DB2 will use what it thinks is fastest based on the query and the statistics from a runstats.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  5. #5
    Join Date
    May 2004
    Posts
    2
    Quote Originally Posted by Marcus_A
    Yes, DB2 may decide to use an index in lieu of a sort. But there is no guarantee, and DB2 will use what it thinks is fastest based on the query and the statistics from a runstats.
    Can we force the use of an index ? I have 250000 records and the system doesn't take it (IBM AS400 V5R1)

  6. #6
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    Not sure about AS400 ...

    But what is the definition of the table and view ?

    I assume you have done RUNSTATS ...

    Cheers
    sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

Posting Permissions

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