Returns true if expr
can be evaluated using only the output of plan
.
Returns true if expr
can be evaluated using only the output of plan
. This method
can be used to determine when it is acceptable to move expression evaluation within a query
plan.
For example consider a join between two relations R(a, b) and S(c, d).
canEvaluate(EqualTo(a,b), R)
returns true
where as canEvaluate(EqualTo(a,c), R)
returns
false
.
Name for this rule, automatically inferred based on class name.
Name for this rule, automatically inferred based on class name.
Rewrite the Exists In with left semi join or anti join.
1. Some of the key concepts: Correlated: References the attributes of the parent query within subquery, we call that Correlated. e.g. We reference the "a.value", which is the attribute in parent query, in the subquery.
SELECT a.value FROM src a WHERE a.key in ( SELECT b.key FROM src1 b WHERE a.value > b.value)
Unrelated: Do not have any attribute reference to its parent query in the subquery. e.g. SELECT a.value FROM src a WHERE a.key IN (SELECT key FROM src WHERE key > 100);
2. Basic Logic for the Transformation EXISTS / IN => LEFT SEMI JOIN NOT EXISTS / NOT IN => LEFT ANTI JOIN
In logical plan demostration, we support the cases like below:
e.g. EXISTS / NOT EXISTS SELECT value FROM src a WHERE (NOT) EXISTS (SELECT 1 FROM src1 b WHERE a.key < b.key)
> SELECT a.value FROM src a LEFT (ANTI) SEMI JOIN src1 b WHERE a.key < b.key
e.g. IN / NOT IN SELECT value FROM src a WHERE key (NOT) IN (SELECT key FROM src1 b WHERE a.value < b.value)
> SELECT value FROM src a LEFT (ANTI) SEMI JOIN src1 b ON a.key = b.key AND a.value < b.value
e.g. IN / NOT IN with other conjunctions SELECT value FROM src a WHERE key (NOT) IN ( SELECT key FROM src1 b WHERE a.value < b.value ) AND a.key > 10
> SELECT value (FROM src a WHERE a.key > 10) LEFT (ANTI) SEMI JOIN src1 b ON a.key = b.key AND a.value < b.value
3. There are also some limitations:
4. TODOs