0
我有兩個疑問甲骨文TO_DATE()的區別
select *
from T
where DATE_OF between to_date ('01.02.2012 00:00:00', 'DD.MM.YYYY hh24:mi:ss')
and to_date ('01.02.2012 23:59:59','DD.MM.YYYY hh24:mi:ss')
解釋計劃
SELECT STATEMENT ALL_ROWSCost: 146,313 Bytes: 55,799,142 Cardinality: 150,402
2 MAT_VIEW ACCESS BY INDEX ROWID MAT_VIEW T Cost: 146,313 Bytes: 55,799,142 Cardinality: 150,402
1 INDEX RANGE SCAN INDEX IND$T_05 Cost: 464 Cardinality: 150,402
第二個查詢
select *
from T
where DATE_OF >= to_date('201202','yyyyMM')
and DATE_OF < to_date('201203','yyyyMM')
解釋計劃
SELECT STATEMENT ALL_ROWSCost: 4,242,836 Bytes: 1,618,120,952 Cardinality: 4,361,512
2 MAT_VIEW ACCESS BY INDEX ROWID MAT_VIEW T Cost: 4,242,836 Bytes: 1,618,120,952 Cardinality: 4,361,512
1 INDEX RANGE SCAN INDEX IND$T_05 Cost: 13,368 Cardinality: 4,361,512
索引DDL
CREATE INDEX IND$T_05 ON T(DATE_OF, TP)
DATE_OF是日期輸入欄。 MVIEW未分區。
爲什麼查詢成本有如此大的差異?
有類似的問題。有一個DATE列TDATE的表,該列上有索引。在where子句中發出了一個select查詢,其中「where TDATE> = TO_TIMESTAMP('12 -MAR-12')」。執行計劃成本高。一旦我改變爲「TDATE> = TO_DATE('12-MAR-12')」,執行計劃成本顯着降低。 – 2012-03-13 14:02:39