[英]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.