[英]Db2 query is taking too much time
我有一项任务是要从特定年份的某些员工的表中获取数据,但是查询大约需要花费时间。 50分钟即可获取50,000个emp记录。
表约。 60亿(6 * 10 ^ 9)数据
查询:
select a, b
from t1
where t1.year in (2012,2013) and
t1.name in (select name from name_tab fetch first 50000 rows only)
Partitioned table: t1
partitioned col: t1.year
Index col: t1.name
我检查了访问计划,很惊讶地看到分区和索引都没有被使用。
首先,尝试以下查询:
select a, b
from t1
where t1.year = 2012 and
t1.name in (select name from name_tab fetch first 50000 rows only)
它可以识别分区吗? 如果是这样,请尝试将查询编写为:
select a, b
from t1
where t1.year = 2012 and
t1.name in (select name from name_tab fetch first 50000 rows only)
union all
select a, b
from t1
where t1.year = 2013 and
t1.name in (select name from name_tab fetch first 50000 rows only)
您可能要在子查询中下order by
,因此可以保证名称相同。
然后,在name_tab(name)
上放置一个索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.