Index on date-fields with NULL values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aad Aldus

    Index on date-fields with NULL values

    Ik have created an index on a date field.
    99% of all data in the table has a filled in date. 1 % is NULL
    When I do a select with clause ... WHERE ADATE IS NULL,
    Oracle does not use the index.

    Is this correct? or How can I force Oracle to use the index.

    Kind reagrds,
    Aad.

    PS: I am using Oracle 8.1.7 and 9.2


  • sybrandb@yahoo.com

    #2
    Re: Index on date-fields with NULL values

    "Aad Aldus" <a.aldus@modali ty.nlwrote in message news:<3f030622$ 0$49107$e4fe514 c@news.xs4all.n l>...
    Ik have created an index on a date field.
    99% of all data in the table has a filled in date. 1 % is NULL
    When I do a select with clause ... WHERE ADATE IS NULL,
    Oracle does not use the index.
    >
    Is this correct? or How can I force Oracle to use the index.
    >
    Kind reagrds,
    Aad.
    >
    PS: I am using Oracle 8.1.7 and 9.2
    This is correct. If all of the columns of an index are null that
    record is not included in the index.
    NULL means *nothing*.
    Hence IS NULL will NEVER use an index.

    You cannot force Oracle to use the index (this is documented behavior,
    and has always worked this way) other than
    - use a function based index (Oracle EE edition only, and in that case
    -especially if only 1 percent is null- you are killing an insect with
    a sledgehammer)
    - use a dummy date for the null values

    Regards

    Sybrand Bakker
    Senior Oracle DBA

    Comment

    • Michael Willer

      #3
      Re: Index on date-fields with NULL values

      Aad Aldus wrote:
      Ik have created an index on a date field.
      99% of all data in the table has a filled in date. 1 % is NULL
      When I do a select with clause ... WHERE ADATE IS NULL,
      Oracle does not use the index.
      >
      Is this correct? or How can I force Oracle to use the index.
      >
      Kind reagrds,
      Aad.
      >
      PS: I am using Oracle 8.1.7 and 9.2
      >
      >
      Given that 99% of the table-data is returned by the query a Full table
      scan is actually faster than using an index.




      Michael Willer
      Oracle/J2EE architect
      Cyber Com Consulting a/s

      Comment

      Working...