|
Archives of the TeradataForumMessage Posted: Fri, 04 Jun 2004 @ 15:55:39 GMT
Martin O'Brien wrote:
This is true, if the optimizer uses conditions in the order you define it, left to right. Most users don't care about that, but it might be a huge difference in CPU time.
IMHO No. Some time ago i did run some checks with statistics and the order was always the same. I don't know if any DBMS has an optimizer which will re-order those conditions if it knows about selectivity (from statistics). For some time i believed that Teradata does it always right to left, but this is wrong. Maybe only the Teradata developers know it right ;- ) Just run some Explains: select * from tpcd100m.lineitem where l_partkey = 17000 AND l_linestatus = 'O'; "(tpcd100m.lineitem.L_LINESTATUS = 'O') AND (tpcd100m.lineitem.L_PARTKEY = 17000)") into Spool 1 (group_amps), select * from tpcd100m.lineitem where l_partkey = 17000 OR l_linestatus = 'O'; "(tpcd100m.lineitem.L_PARTKEY = 17000) OR (tpcd100m.lineitem.L_LINESTATUS = 'O')") into Spool 1 (group_amps), select count(*) from tpcd100m.lineitem where l_partkey = 17000 OR l_linestatus = 'O'; "(tpcd100m.lineitem.L_PARTKEY = 17000) OR (tpcd100m.lineitem.L_LINESTATUS = 'O')"). Aggregate Intermediate select count(*) from tpcd100m.lineitem where l_partkey = 17000 AND l_linestatus = 'O'; "(tpcd100m.lineitem.L_PARTKEY = 17000) AND (tpcd100m.lineitem.L_LINESTATUS = 'O')"). Aggregate Intermediate So the rules might be: If it's an aggregation or if it's an ORed condition -> left to right If it's ANDed -> right to left But you never know, so i always check Explain to see if it's an efficient order. Dieter
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright 2016 - All Rights Reserved | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Last Modified: 15 Jun 2023 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||