简体   繁体   English

db2查询花费太多时间

[英]Db2 query is taking too much time

I have a task to fetch the data from table for some of the employees for specific years, but the query is taking approx. 我有一项任务是要从特定年份的某些员工的表中获取数据,但是查询大约需要花费时间。 50 mins to fetch 50 000 emp records. 50分钟即可获取50,000个emp记录。

Table has approx. 表约。 6 billion (6*10^9) data 60亿(6 * 10 ^ 9)数据

Query : 查询:

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

I have checked the Access plan and surprised to see that neither partition nor index is getting used. 我检查了访问计划,很惊讶地看到分区和索引都没有被使用。

First, try this query: 首先,尝试以下查询:

select a, b
from t1
where t1.year = 2012 and
      t1.name in (select name from name_tab fetch first 50000 rows only)

Does it recognize the partition? 它可以识别分区吗? If it does, try writing the query as: 如果是这样,请尝试将查询编写为:

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)

You might want to put an order by in the subquery, so the names are guaranteed to be the same. 您可能要在子查询中下order by ,因此可以保证名称相同。

Then, put an index on name_tab(name) . 然后,在name_tab(name)上放置一个索引。

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

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