Function mz_sql::plan::transform_expr::try_simplify_quantified_comparisons
source · pub fn try_simplify_quantified_comparisons(expr: &mut HirRelationExpr)
Expand description
Rewrites quantified comparisons into simpler EXISTS operators.
Note that this transformation is only valid when the expression is
used in a context where the distinction between FALSE
and NULL
is immaterial, e.g., in a WHERE
clause or a CASE
condition, or
when the inputs to the comparison are non-nullable. This function is careful
to only apply the transformation when it is valid to do so.
ⓘ
WHERE (SELECT any(<pred>) FROM <rel>)
=>
WHERE EXISTS(SELECT * FROM <rel> WHERE <pred>)
WHERE (SELECT all(<pred>) FROM <rel>)
=>
WHERE NOT EXISTS(SELECT * FROM <rel> WHERE (NOT <pred>) OR <pred> IS NULL)
See Section 3.5 of “Execution Strategies for SQL Subqueries” by M. Elhemali, et al.