Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 331155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:44:53+00:00 2026-05-12T09:44:53+00:00

I used to think that Oracle does not index a row when one of

  • 0

I used to think that Oracle does not index a row when one of the column values is null.

Some simple experimentation shows this to be not the case. I was able to run some queries unexpectedly accessing only indexes even though some columns were nullable (which of course was a pleasant surprise).

A Google search led to some blogs with conflicting answers: I have read that a row gets indexed unless all indexed columns are null, and also that a row gets indexed unless the leading column value for the index is null.

So, in what cases does a row not enter an index? Is this Oracle version specific?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:44:54+00:00Added an answer on May 12, 2026 at 9:44 am

    If any indexed column contains a non-null value that row will be indexed. As you can see in the following example only one row doesn’t get indexed and that’s the row which has NULL in both indexed columns. You can also see that Oracle definitely does index a row when the leading index column has a NULL value.

    SQL> create table big_table as
      2       select object_id as pk_col
      3               , object_name as col_1
      4               , object_name as col_2
      5  from all_objects
      6  /
    
    Table created.
    
    SQL> select count(*) from big_table
      2  /
    
      COUNT(*)
    ----------
         69238
    
    SQL> insert into big_table values (9999990, null, null)
      2  /
    
    1 row created.
    
    SQL> insert into big_table values (9999991, 'NEW COL 1', null)
      2  /
    
    1 row created.
    
    SQL> insert into big_table values (9999992, null, 'NEW COL 2')
      2  /
    
    1 row created.
    
    SQL> select count(*) from big_table
      2  /
    
      COUNT(*)
    ----------
         69241
    
    SQL> create index big_i on big_table(col_1, col_2)
      2  /
    
    Index created.
    
    SQL> exec dbms_stats.gather_table_stats(user, 'BIG_TABLE', cascade=>TRUE)
    
    PL/SQL procedure successfully completed.
    
    
    SQL> select num_rows from user_indexes where index_name = 'BIG_I'
      2  /
    
      NUM_ROWS
    ----------
         69240
    
    SQL> set autotrace traceonly exp
    SQL>
    SQL> select pk_col from big_table
      2  where col_1 = 'NEW COL 1'
      3  /
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1387873879
    
    -----------------------------------------------------------------------------------------
    | Id  | Operation                   | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |           |     2 |    60 |     4   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| BIG_TABLE |     2 |    60 |     4   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | BIG_I     |     2 |       |     3   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       2 - access("COL_1"='NEW COL 1')
    
    SQL> select pk_col from big_table
      2  where col_2 = 'NEW COL 2'
      3  /
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 3993303771
    
    -------------------------------------------------------------------------------
    | Id  | Operation         | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    -------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |           |     2 |    60 |   176   (1)| 00:00:03 |
    |*  1 |  TABLE ACCESS FULL| BIG_TABLE |     2 |    60 |   176   (1)| 00:00:03 |
    -------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter("COL_2"='NEW COL 2')
    
    SQL> select pk_col from big_table
      2  where col_1 is null
      3  and col_2 = 'NEW COL 2'
      4  /
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1387873879
    
    -----------------------------------------------------------------------------------------
    | Id  | Operation                   | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |           |     1 |    53 |     4   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| BIG_TABLE |     1 |    53 |     4   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | BIG_I     |     2 |       |     3   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       2 - access("COL_1" IS NULL AND "COL_2"='NEW COL 2')
           filter("COL_2"='NEW COL 2')
    
    SQL> select pk_col from big_table
      2  where col_1 is null
      3  and col_2 is null
      4  /
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 3993303771
    
    -------------------------------------------------------------------------------
    | Id  | Operation         | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    -------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |           |     1 |    53 |   176   (1)| 00:00:03 |
    |*  1 |  TABLE ACCESS FULL| BIG_TABLE |     1 |    53 |   176   (1)| 00:00:03 |
    -------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter("COL_1" IS NULL AND "COL_2" IS NULL)
    
    SQL>
    

    This example run on Oracle 11.1.0.6. But I’m pretty confident it holds true for all versions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've used ConfigParser for quite a while for simple configs. One thing that's bugged
So... I used to think that when you accessed a file but specified the
I think that it used to the be the case that in Liferay 4,
We used to use SourceSafe, and one thing I liked about it was that
I used to think that once a module was loaded, no re-importing would be
This example works but I think that the memory leaks. Function used in the
I currently don't know any thing about web services, except that they are used
I'm used to doing Java programming, where you never really have to think about
Never used a cache like this before. The problem is that I want to
Caveats: Let me first clarify that this is not a question about whether to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.