Evaluation order of WHERE Conditions #15568
Unanswered
AntonPeniaziev
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello community, I've noticed that there's no consistent behaviour in regard of short-circuit evaluation in filter conditions.
Considering that I have a table visits_table (year, month, day_of_month, place, visits_num) which is partitioned by 3 columns - year, month, day_of_month , which is a "big" table (10B rows), and trying to join it with a "small" table (100 rows) - person_visits(year, month, day_of_month, place)
WITH SELECT_QUERY AS (
SELECT
year,
month,
dayofmonth,
total_visitors
FROM
visits_table
)
SELECT
SELECT_QUERY.* // changing it to just '*' improves performance dramatically!
FROM
SELECT_QUERY
JOIN
person_visits TMP_TABLE
ON
SELECT_QUERY.year = TMP_TABLE.year AND
SELECT_QUERY.month = TMP_TABLE.month AND
SELECT_QUERY.dayofmonth = TMP_TABLE.dayofmonth AND
WHERE
SELECT_QUERY.year = 2020 AND SELECT_QUERY.month = 5 AND (SELECT_QUERY.dayofmonth = 1 OR SELECT_QUERY.dayofmonth = 2 OR ... OR SELECT_QUERY.dayofmonth = 15)
Since there are only 2019,2020 data, my keys are unbalanced and its critical to query on year , month, day in that order so the huge performance difference is caused by that that in case of '' instead of SELECT_QUERY. the filter is somehow evaluated in the same order it is written.
My question is: is it documented somewhere that certain queries "enforce" order of filter condition?
Forgive me for the long question and thanks for any help !
Anton
Beta Was this translation helpful? Give feedback.
All reactions