Home > Ask the Oracle Experts > (Archive) Database Performance Tuning Questions & Answers > Optimize SQL query on table with 50 million records
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Optimize SQL query on table with 50 million records

Paul Baumgartel EXPERT RESPONSE FROM: Paul Baumgartel

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Oracle tips, scripts, and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 30 January 2007

We have a table with about 50 million records with the following structure:

  • column1: integer
  • column2: integer
  • column3: varchar
  • column4: varchar
  • column5: date

The primary key of the table is (column1,column2).

We need to execute the following query on this table:

select * from table where column1 in (...set of values...) and 
column2 in (...set of values...)

Both the sets of values used for the "in" clause have a size which may be from 30 to 60 distinct values.

Now this query needs about one or two seconds to complete in Oracle 10g, but we need this query to be executed in less than half a second, in the fastest possible way.

What could be a solution to optimize this query?

Thanks!


>
EXPERT RESPONSE
You should examine the optimizer execution plan for the query using EXPLAIN PLAN, and also trace the execution using DBMS_SUPPORT.START_TRACE. These will tell you exactly what Oracle is doing to execute the query. How many rows are typically returned by the query? If more than about 20% of the table, a full table scan may be more efficient than a lookup using the primary key index -- but again, first you must observe the current execution plan.

Are the in-list values available in the database? If so, a join or subquery may be more efficient than specifying them as literals. You can also experiment with optimizer hints; take a look at the Oracle Performance Tuning manual for additional ideas.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
(Archive) Database Performance Tuning
How tkprof works for tuning
Import of dump file took 20 hours
Windows reporting high number of handles for oracle.exe processes
Performance problems in Unix vs. Windows
Insertion speed goes down with context index
Buffer busy waits on primary key index
Do indexes affect performance of updates and inserts?
Creating partitions on fastest area of disk
Slow queries on table; can't create index
Function-based index or Oracle Text?

Oracle database performance problems and tuning
Oracle 11g data compression
Varchar or number for better performance?
Do statistics on SYS-owned objects hurt performance in 10g?
Inside the Oracle 11g SQL Performance Advisor, part 1
Inside the Oracle 11g SQL Performance Advisor, part 2
Difference between driving table and driver table in Oracle
Best design for E-Business Suite on hard drive
20GB data dictionary causing performance problems
Using the cost-based optimizer to improve Database 10g performance
Online tablespace reorganization in Oracle 9i

Oracle database design
Weighing remote database administration pros and cons takes care
Oracle Database 11g makes waves at Burlington Coat Factory
How to create a database link in Oracle
Data modeling tools no substitute for hard work
How do I do that in Oracle?
The Oracle Database user's guide to Oracle OpenWorld 2007
Oracle OpenWorld 2007 Special Report
How many redo log files?
How to move tables from system tablespace to user tablespace
ORA-12560 error with Oracle 10g Instant Client

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
extent  (SearchOracle.com)
field  (SearchOracle.com)
flexfield  (SearchOracle.com)
foreign key  (SearchOracle.com)
quad tree  (SearchOracle.com)
record  (SearchOracle.com)
row  (SearchOracle.com)
splay tree  (SearchOracle.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts