整型日期做PPI,sql不走partition

miguelmin發表於2009-05-12
CREATE MULTISET TABLE tmp_tmp1,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
Date_Id INTEGER TITLE '日期' NOT NULL,
...
)
PRIMARY INDEX XIE1tmp_tmp1 ( ...)
PARTITION BY RANGE_N(Date_Id BETWEEN 20070101 AND 20101231 EACH 1 );
[@more@]
CASE 1:
select count(*)
FROM tmp_tmp1
where T1.Date_Id >= 20090401
Explanation:
........
2) Next, we do an all-AMPs SUM step to aggregate from 10831
partitions of tmp_tmp1with a condition
of ("tmp_tmp1.Date_Id >= 20090401").
...............
CASE 2:
select count(*)
FROM tmp_tmp1
where T1.Date_Id >= cast(CAST(ADD_MONTHS(DATE-1,-1) AS DATE FORMAT 'YYYYMM')||'01' as integer)
Explanation:
.......
2) Next, we do an all-AMPs SUM step to aggregate from all partitions
of tmp_tmp1with a condition of (
"tmp_tmp1.Date_Id >= ((ADD_MONTHS(((DATE )- 1 ),-1 )(VARCHAR(6), CHARACTER SET UNICODE,
NOT CASESPECIFIC, FORMAT 'YYYYMM'))||'01'(INTEGER, FORMAT '-(10)9'))").
..........
實驗得出,where條件中有任何的資料處理,將不會走group partitions,據說這是teradata老版本的bug,似乎老外用的已經沒有這個問題了,為什麼給我們用舊的呢?鄙視老外一下!
不知道當初為什麼要把date_id設計成integer而非date。定義成整型,定義範圍內的很多partition牙根不會用到,比如尾數大於30的任何數。上述CASE 1中,實際用到的partition也就40個,但執行計劃中為10831個,型別定義為罪魁禍首。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16723161/viewspace-1022020/,如需轉載,請註明出處,否則將追究法律責任。

相關文章