CREATE INDEX my_table_index1ON my_tableUSING btree(c05, c01, c02)
TABLESPACE smart_history_index;CREATE INDEX my_table_index2ON my_tableUSING btree(c01, c02, c03, c04, c05)
TABLESPACE smart_history_index;
使用以下SQL1語句查詢,查詢時間為2分鐘。 SQL1:
select * from my_table t1
where (selectcount(*) from my_table t2 where
((t1.c01 = t2.c01 ) or (t1.c01 isnulland t2.c01 isnull)) and
((t1.c02 = t2.c02 ) or (t1.c02 isnulland t2.c02 isnull)) and
((t1.c03 = t2.c03 ) or (t1.c03 isnulland t2.c03 isnull)) and
((t1.c04 = t2.c04 ) or (t1.c04 isnulland t2.c04 isnull)) and
((t1.c05 = t2.c05 ) or (t1.c05 isnulland t2.c05 isnull)) and
((t1.c06 = t2.c06 ) or (t1.c06 isnulland t2.c06 isnull)) and
((t1.c07 = t2.c07 ) or (t1.c07 isnulland t2.c07 isnull)) and
((t1.c08 = t2.c08 ) or (t1.c08 isnulland t2.c08 isnull)) and
((t1.c09 = t2.c09 ) or (t1.c09 isnulland t2.c09 isnull)) and
((t1.c10 = t2.c10 ) or (t1.c10 isnulland t2.c10 isnull))
)>1;
使用以下SQL2語句查詢,查詢時間為2.8秒。 SQL2:
select * from my_table t1
where (selectcount(*) from my_table t2 where
((t1.c01 = t2.c01 ) or (t1.c01 isnulland t2.c01 isnull)) and
((t1.c02 = t2.c02 ) or (t1.c02 isnulland t2.c02 isnull)) and
((t1.c03 = t2.c03 ) or (t1.c03 isnulland t2.c03 isnull)) and
((t1.c04 = t2.c04 ) or (t1.c04 isnulland t2.c04 isnull)) and
((t1.c05 = t2.c05 ) or (t1.c05 isnulland t2.c05 isnull)) and
((t1.c06 = t2.c06 ) or (t1.c06 isnulland t2.c06 isnull)) and
((t1.c07 = t2.c07 ) or (t1.c07 isnulland t2.c07 isnull)) and
((t1.c08 = t2.c08 ) or (t1.c08 isnulland t2.c08 isnull)) and
((t1.c09 = t2.c09 ) or (t1.c09 isnulland t2.c09 isnull)) and
((t1.c10 = t2.c10 ) or (t1.c10 isnulland t2.c10 isnull)) and
(c01 >= '2017-04-20 00:00:00'and c01 < '2017-04-21 00:00:00')
)>1and (c01 >= '2017-04-20 00:00:00'and c01 < '2017-04-21 00:00:00');