简体   繁体   中英

Improve Oracle Query Structure

My query takes about 2 minutes to execute, any suggestions on how to improve the query in order to reduce this 2 minute wait time.

My Query:

SELECT
 PRICE, VOLUME, BLOCK
FROM 
 owner.table
WHERE
 basis = 'location_name" AND
 tableSource = 'DetailTable' AND
 type = 'Sales' AND
 contractMonth = '05' AND
 to_char(createDate,'YYYY-MM-DD') = '2016-01-01'

First, I would rewrite the query to look like this:

SELECT t.PRICE, t.VOLUME, t.BLOCK
FROM owner.table t
WHERE basis = 'location_name' AND
      tableSource = 'DetailTable' AND
      type = 'Sales' AND
      contractMonth = '05' AND
      createDate >= date '2016-01-01' AND
      createDate < date '2016-01-02';

Then, to improve performance, create an index on (basis, tableSource, type, contractMonth, createDate) .

You could also add price , volume , and block as the last three columns in the index. The index would then cover the query, meaning that the index has all columns and there is no need to load the original data pages.

Check your indexes and make sure that your index columns type is same type your values. For example; is contractMonth column number or varchar etc. Because if you want to use your index, each side in equation must be same type. Also, check your last analyzed date for true optimization based on actual histograms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM