Sql Db2查询占用了太多时间

Sql Db2查询占用了太多时间,sql,indexing,db2,partitioning,Sql,Indexing,Db2,Partitioning,我的任务是从表中获取特定年份某些员工的数据,但查询大约需要50分钟才能获取50000条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 In

我的任务是从表中获取特定年份某些员工的数据,但查询大约需要50分钟才能获取50000条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\u选项卡(name)

上放置一个索引,我已经尝试使用
t1.year=2012
,但它仍然没有使用partition@PuneetGupta . . . 分区出了问题。可以将
year
存储为字符串。使用错误的类型可能会混淆优化器。无法更改年份的数据类型,因为表中已有约600亿条记录用于发布计划(从
db2exfmt
)以及实际的表和索引DDL?