dongjoon-hyun commented on PR #60782: URL: https://github.com/apache/spark/pull/60782#issuecomment-7087214567
Thank you for the review. I checked the findings with a temporary suite (not included) on the head of this PR, a239bd0853a, and on its base, c2cc05a3965, in ANSI mode: - With the `IN` subquery and `rand() < 0.5`, the optimizer reached its iteration limit, while the base optimizes the query. - The inner join of three streams failed with "Stream-stream join without equality predicate is not supported", while the base returns its row. - Six stacked filters made the plan expressions 1837 nodes, against 163 on the base. - `isnotnull(v)` and `isnotnull(w)` were no longer inferred for the query in the description, and `fact.dt >= '2024-01-01'` above a filter on another table no longer pruned the partitions of `fact`. - The query with the cross join returned no rows with a NULL `g` on both, as `isnotnull(g)` is inferred, and failed with `DIVIDE_BY_ZERO` on both when `t1.f > t2.g` is FALSE. So I changed `guard` in fa55a547cbd. A condition is guarded only if it can go into a join condition, it can fail once its constant parts are folded, and the plan is not streaming. A condition over one plan is guarded only by the conjuncts of the filters that only read that plan, and any other one by the conditions of the filters as written, once each. `IS NOT NULL` checks of the columns that make a guarded condition NULL follow it. On the findings: 1. **Rewrapped conditions (P1):** `guard` now leaves a condition written after a non-deterministic or throwable one, which `ReorderJoin` keeps in a filter above all the joins, and one that `canEvaluateWithinJoin` rejects, e.g. an `IN` subquery. A new test runs the optimizer rules of the suite on a lower filter with an `IN` subquery, with an `IN` subquery, `rand(0) > 0.5` and a division after it above, and checks that none of them is guarded. Without the change, it reaches the iteration limit. I could not make the variant with a throwable lower join condition loop with the plans I tried, but the same rule leaves its throwable condition above. 2. **Streaming joins (P1):** `guard` now leaves the conditions of a streaming plan as written. The plan test covers a streaming variant, and the inner join of three streams returns its row again. `StreamingInnerJoinWithoutVCFSuite` passes. 3. **Conditions that also read an upper plan (P2):** I kept them as they are. Your query fails on the base too, and also when `t1.f > t2.g` is FALSE instead of NULL, since reordering evaluates the division in a join below the one with the filter condition. That is the same for any condition that reads a plan joined first, e.g. in one `WHERE` clause over the joins, so it is not the `NULL AND x` evaluation that this PR fixes. Widening the guard would also need to skip the filters that the pushdown puts back between the joins, as you noted. The Scaladoc and the PR description now say this. 4. **Guard size (P2):** `flatten` now records the conjuncts of each filter as written, and a condition is guarded by the condition of each filter once, the lower one outermost. Six stacked filters now make 457 nodes. 5. **Nested guards (P2):** a new test checks the exact guards above two stacked filters whose conditions can be NULL. 6. **Column that can fail (P3):** the plan test now also guards `q > d`, where `q` is a projected division in ANSI mode. 7. **Conditions with no references (P3):** the Scaladoc now says that such a condition is guarded too. 8. **Cases that still fail (P3):** the Scaladoc says that the condition of a lower join guards nothing and which conditions are left as is. The PR description lists the cases that still fail. On the decision challenges: - **IS NOT NULL checks:** `guard` now returns `IsNotNull` of each nullable column that makes a guarded condition NULL, after it. The query in the description infers `isnotnull(v)` and `isnotnull(w)` for the scans again. - **Conditions that can not fail:** `guard` now folds the constant parts as `ConstantFolding` does before it checks whether a condition can fail, so `fact.dt >= '2024-01-01'` is not guarded. An `IN`, `NOT IN` or `EXISTS` subquery is left as is, as on the base. A condition over one plan is also no longer guarded by the conjuncts of the filters that read other plans, so it is still pushed down to that plan. That keeps the pruning of `fact` when the filter is on another table. I updated the PR description, including that a guarded equality is no longer a join key. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
