我在Windows Server 2003上安装了oracle 10g。
我在单个表中有22,000,000条记录,这是一个交易表,
增加同一表中的记录约。每月50,000。
我的问题是每当我对它运行查询时,我的查询总是太慢。 有没有什么方法可以提高查询的性能,比如分区表还是其他?
select a.prd_code
, a.br_code||'-'||br_title
, a.size_code||'-'||size_title
,size_in_gms
, a.var_code||'-'||var_title
, a.form_code||'-'||form_title
, a.pack_code||'-'||pack_title
, a.pack_type_code||'-'||pack_type_title
, start_date
, end_date
, a.price
from prices a
, brand br
, (select distinct prd_code
, br_code
, size_code
, var_code
, form_code
,packing_code
, pack_type_code
from cphistory
where prd_code = '01'
and flag = 'Y'
and project_yy = '2009' and '01' and '10') cp
, (select prd_code
, br_code
, size_code
, size_in_gms
from sizes
where prd_code = '01'
and end_date = '31-dec-2050'
and flag = 'Y') sz
, (select prd_code
, br_code
, var_code
, var_title
from varient) vt
, (select prd_code
, br_code
, form_code
, form_title
from form) fm
, (select prd_code
, pack_title
from package) pc
, (select prd_code
, pack_type_title
from pakck_type) pt
where a.prd_code = br.prd_code
and a.br_code = br_br_code
and a.prd_code = sz.prd_code
and a.br_code = sz.br_code
and a.size_code = sz.size_code
and a.prd_code = vt.prd_code
and a.br_code = vt.br_code
and a.var_code = vt.var_code
and a.prd_code = fm.prd_code
and a.br_code = fm.br_code
and a.form_code = fm.form_code
and a.prd_code = pc.prd_code
and a.br_code = pc.br_code
and a.pack_code = pc.pack_code
and a.prd_code = pt.prd_code
and a.pack_type_code = pt.pack_type_code
and end_date = '2009'
and prd_code = '01'
order by a.prd_code
, a.br_code
, a.size_code
, a.var_code
, a.pack_code
, a.form_code
此查询中使用的表是:
prices : has more than 2.1M rows
cphistory : has more than 2.2M rows
sizes : has more than 5000 rows
brand : has more than 1200 rows
varient : has more than 1800 rows
package : has more than 200 rows
pack_type : has more than 150 rows
答案 0 :(得分:5)
22M的记录并不是那么大。
答案 1 :(得分:1)
你应该从解释计划开始,但要这样做:
很多很多解释计划,但不仅仅是一点点小心。我希望我能提供更多帮助。
答案 2 :(得分:0)
为什么查询速度慢?他们在大桌子上做表扫描吗?通常,OLTP查询将基于主键或其他索引列获取相对较少数量的行。如果您的查询没有使用索引,并且它们是可以从使用索引中受益的典型OLTP查询,那么这将是开始的地方。
如果您经常需要从此表中查询大量行,以便表扫描是更有效的访问路径,您可以查看使用物化视图预先聚合数据或分区表。但是,在企业版许可证之上进行分区是一个额外的成本选项,因此您通常希望在沿着这条路径前耗尽其他选项。