perf: Split ifnull into two conditions
This produces better query plan with index intersection using 2 conditions instead of fulltable scan on dumb condition TODO: LOTS OF TESTS
This commit is contained in:
parent
c317462379
commit
23ffdc87ae
1 changed files with 6 additions and 1 deletions
|
|
@ -912,7 +912,12 @@ from {tables}
|
|||
f.operator = "ilike"
|
||||
condition = f"{column_name} {f.operator} {value}"
|
||||
else:
|
||||
condition = f"ifnull({column_name}, {fallback}) {f.operator} {value}"
|
||||
# PERF: try to transform ifnull into two conditions, this way query plan can use index
|
||||
# intersection instead of full table scans.
|
||||
if fallback == value and f.operator == "=":
|
||||
condition = f"( {column_name} is NULL OR {column_name} {f.operator} {value} )"
|
||||
else:
|
||||
condition = f"ifnull({column_name}, {fallback}) {f.operator} {value}"
|
||||
|
||||
return condition
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue