简体   繁体   English

改善Oracle查询结构

[英]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. 我的查询大约需要2分钟才能执行,有关如何改进查询以减少2分钟等待时间的任何建议。

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) . 然后,为了提高性能,在(basis, tableSource, type, contractMonth, createDate)上创建索引。

You could also add price , volume , and block as the last three columns in the index. 您还可以添加pricevolumeblock作为索引的最后三列。 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. 是contractMonth列号或varchar等。因为如果要使用索引,则方程式的每一侧都必须是同一类型。 Also, check your last analyzed date for true optimization based on actual histograms. 另外,根据实际直方图检查上次分析的日期,以进行真正的优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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