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 8639147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:55:37+00:00 2026-06-12T10:55:37+00:00

I have a table in an Oracle DB wich has two indices, one for

  • 0

I have a table in an Oracle DB wich has two indices, one for table field A, one for table field B. Now I need to select all records that have a specific value in field A or another specific value in field B.

To make use of the indices I could of course make one SELECT on field A and then another SELECT on field B. So I can make sure both indices are being used.

However, I would rather do that with one SELECT and both fields in the WHERE clause connected with OR. In such a case and my setup as described above, do you know whether Oracle is smart enough to make use of my two indices, or isn’t that possible so that I should stick with those two SELECTs?

Thanks!

  • 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-06-12T10:55:39+00:00Added an answer on June 12, 2026 at 10:55 am

    You can use a UNION (or UNION ALL if you don’t want to eliminate duplicates).

    select ... from myTable where A = <something>
    UNION [ALL]
    select ... from myTable where B = <something>
    

    Or you can combine that in one query with an OR, as you have described, and take a look at the query plan to see if the index really is excluded.

    Oracle has a very smart optimizer and the whole point of making SQL declarative is that you then spend your time telling the database what you want, and leave the database to decide how best to get it (with a fairly loud caveat, it must be said, as there many situations where you can force the optimizer to make a bad choice: but in my experience, you tend to reach that hurdle somewhat later than with other databases).

    What Oracle will probably do, in your case, is to examine:

    • which indexes exist
    • the cardinality, i.e. the “spread” of different values for a specific
      index
    • the statistics, how much data etc.

    and then make an informed decision. And that decision will be based on the data current to the time the query is executed (or at least, the last time the statistics were updated). so it may be possible to use hints to force index use, but in doing so you could prevent Oracle from finding the most efficient path through your data at later date, when the data looks vastly different.

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

Sidebar

Related Questions

I have table A in Oracle that has a primary key (id). I need
I have a Oracle table where there is one date-time field. On select query
I have oracle table that holds more than 30 million records, I need to
I have a table in an Oracle Database that has, among others, a DATE
I have an application that records activity in a table (Oracle 10g). The logging
I have a table with three fields, one an identity field, and I need
Possible Duplicate: SELECT INTO using Oracle I have one table in my oracle database.
I have a table in Oracle that contains a field with the data type
I have a table in Oracle DB which has a field where procedure names
I have a table in Oracle that has the daily sum of values. My

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.