expression, planner: guard mixed outer-join filter propagation | tidb-test=pr/2729 - #67804
Conversation
📝 WalkthroughWalkthroughTighten constant-propagation for outer joins so WHERE-derived predicates contribute to new join filters only if they are fully from the preserved (outer) schema. Add a regression test for the COALESCE+LEFT JOIN case and update several expected plan_tree outputs to reflect removed or simplified pushed predicates. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/expression/constant_propagation.go (1)
867-869: Mark rejected mixed-side filters as visited.This guard is independent of the current
outerCol = innerColpair, so leaving the predicate unvisited makesderiveCondsre-check the same skippedWHEREitem for every equivalent-column pair.Suggested change
if filterConds && !ExprFromSchema(cond, s.outerSchema) { + visited[k+offset] = true continue }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/expression/constant_propagation.go` around lines 867 - 869, The loop skipping mixed-side filters currently does "if filterConds && !ExprFromSchema(cond, s.outerSchema) { continue }" but doesn't mark the predicate as visited, so deriveConds will revisit it for each equivalent-column pair; fix by marking the condition as visited before continuing (use the same visit-tracking mechanism deriveConds uses—e.g., call the visitor helper such as s.markVisited(cond) or add cond to s.visited/set) so the predicate is skipped in subsequent iterations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/expression/constant_propagation.go`:
- Around line 867-869: The loop skipping mixed-side filters currently does "if
filterConds && !ExprFromSchema(cond, s.outerSchema) { continue }" but doesn't
mark the predicate as visited, so deriveConds will revisit it for each
equivalent-column pair; fix by marking the condition as visited before
continuing (use the same visit-tracking mechanism deriveConds uses—e.g., call
the visitor helper such as s.markVisited(cond) or add cond to s.visited/set) so
the predicate is skipped in subsequent iterations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4f263ff4-a3a4-474f-8d4d-b47608ad6765
📒 Files selected for processing (2)
pkg/expression/constant_propagation.gopkg/planner/core/casetest/rule/rule_outer2inner_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #67804 +/- ##
================================================
+ Coverage 77.6037% 77.6063% +0.0025%
================================================
Files 1982 1966 -16
Lines 548713 551334 +2621
================================================
+ Hits 425822 427870 +2048
- Misses 122081 123444 +1363
+ Partials 810 20 -790
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/retest |
|
/retest |
|
/retest |
[LGTM Timeline notifier]Timeline:
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: AilinKid, terry1purcell, windtalker The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest |
2 similar comments
|
/retest |
|
/retest |
|
/retest |
|
/test unit-test |
|
@hawkingrei: The specified target(s) for Use DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/retest |
9 similar comments
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
What problem does this PR solve?
Issue Number: close #66833
Problem Summary:
PropConstForOuterJoincould derive a new join-side filter from aWHEREpredicate that mixed preserved-side and inner-side columns. ForLEFT JOIN ... WHERE COALESCE(...), that derived filter could remove the matched inner row before null extension and produce a wrong result.What changed and how does it work?
filterConds -> joinCondsderivation to predicates that are fully on the preserved side.TestOuter2Innerfor the exactLEFT JOIN + WHERE COALESCE(...)wrong-result shape from#66833.Check List
Tests
Test details:
./tools/check/failpoint-go-test.sh pkg/planner/core/casetest/rule -run TestOuter2Inner -count=1./tools/check/failpoint-go-test.sh pkg/planner/core/casetest/rule -run TestOuter2Inner -count=1make lintSide effects
Documentation
Release note
Summary by CodeRabbit
Bug Fixes
Behavior
Tests