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

  • Home
  • SEARCH
  • 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 51195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:42:44+00:00 2026-05-10T16:42:44+00:00

Suppose I have a database table with two fields, foo and bar. Neither of

  • 0

Suppose I have a database table with two fields, ‘foo’ and ‘bar’. Neither of them are unique, but each of them are indexed. However, rather than being indexed together, they each have a separate index.

Now suppose I perform a query such as SELECT * FROM sometable WHERE foo='hello' AND bar='world'; My table a huge number of rows for which foo is ‘hello’ and a small number of rows for which bar is ‘world’.

So the most efficient thing for the database server to do under the hood is use the bar index to find all fields where bar is ‘world’, then return only those rows for which foo is ‘hello’. This is O(n) where n is the number of rows where bar is ‘world’.

However, I imagine it’s possible that the process would happen in reverse, where the fo index was used and the results searched. This would be O(m) where m is the number of rows where foo is ‘hello’.

So is Oracle smart enough to search efficiently here? What about other databases? Or is there some way I can tell it in my query to search in the proper order? Perhaps by putting bar='world' first in the WHERE clause?

  • 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. 2026-05-10T16:42:45+00:00Added an answer on May 10, 2026 at 4:42 pm

    Oracle will almost certainly use the most selective index to drive the query, and you can check that with the explain plan.

    Furthermore, Oracle can combine the use of both indexes in a couple of ways — it can convert btree indexes to bitmaps and perform a bitmap ANd operation on them, or it can perform a hash join on the rowid’s returned by the two indexes.

    One important consideration here might be any correlation between the values being queried. If foo=’hello’ accounts for 80% of values in the table and bar=’world’ accounts for 10%, then Oracle is going to estimate that the query will return 0.8*0.1= 8% of the table rows. However this may not be correct – the query may actually return 10% of the rwos or even 0% of the rows depending on how correlated the values are. Now, depending on the distribution of those rows throughout the table it may not be efficient to use an index to find them. You may still need to access (say) 70% or the table blocks to retrieve the required rows (google for ‘clustering factor’), in which case Oracle is going to perform a ful table scan if it gets the estimation correct.

    In 11g you can collect multicolumn statistics to help with this situation I believe. In 9i and 10g you can use dynamic sampling to get a very good estimation of the number of rows to be retrieved.

    To get the execution plan do this:

    explain plan for SELECT * FROM   sometable WHERE  foo='hello' AND bar='world' / select * from table(dbms_xplan.display) / 

    Contrast that with:

    explain plan for SELECT /*+ dynamic_sampling(4) */        * FROM   sometable WHERE  foo='hello' AND bar='world' / select * from table(dbms_xplan.display) / 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 304k
  • Answers 304k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ran into the same issue when using sqlite, I… May 13, 2026 at 8:54 pm
  • Editorial Team
    Editorial Team added an answer Why do you think a username and password is weak?… May 13, 2026 at 8:54 pm
  • Editorial Team
    Editorial Team added an answer You may want to search for "php code coverage." That… May 13, 2026 at 8:54 pm

Related Questions

I made a people maintenance screen. The client want me to store the photo
I have a Products table in a SQL Server database and I am having
I want to ask a question about how you would approach a simple object-oriented
I have a MDB (Message driven bean) that receives messages with String which represent

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.