You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
planner: pull up IN-list predicates in constant propagation | tidb-test=pr/2829 - #73349
Constant propagation pulls col <op> const predicates out of a join child so that a join equality can carry them to the other child, but ValidCompareConstantPredicate only accepts =, >, >=, <, <=. An IN list of constants is left behind, so the other child loses a predicate that the equality version gets.
A left join that hydrates the child rows of a page of parent ids hits this. With id = ? the child side is a point read; with id in (?, ?) it scans every child row under the shared key prefix and filters the rest of the key row by row.
What changed and how does it work?
ValidCompareConstantPredicate also accepts col IN (const, ...) when every constant has the column's collation, the same requirement it applies to a single comparison.
Nothing after the pull-up changes: the outer-join solver (propagateColumnEQ / deriveConds) and the inner-join solver already derive the other side's IN once they see the predicate.
Check List
Tests
Unit test
Integration test
Manual test (add detailed scripts or steps below)
No need to test
I checked and no code files have been changed.
TestInListConstantPropagation in tests/integrationtest/t/planner/core/rule_constant_propagation.test: inner join, left join from the outer child, no propagation from the inner child of a left or right join, through a projection, matching and mismatched collation, a non-constant item, NOT IN, and the results of three of the queries.
go test -tags=intest ./pkg/planner/core/casetest/... ./pkg/expression/ with failpoints enabled: passes, no recorded plan changes.
tests/integrationtest/run-tests.sh: every case passes; no other recorded plan changes.
The optimizer propagates an `IN` list of constants on a join key from one side of a join to the other, so a join filtered by `IN` on its key can read only the matching rows of the other table.
Queries using IN filters may benefit from constant propagation across joins, including supported inner- and outer-join cases and queries with projections.
Propagation follows join semantics: it does not flow from nullable sides of outer joins, and does not apply to NOT IN.
Propagation is limited when an IN list contains non-constant values or string collations do not match.
Bug Fixes
Predicates containing expressions with mutable effects are excluded from constant propagation.
Constant propagation pulls `col <op> const` predicates out of a join child
so that a join equality can carry them to the other child. `col IN (const,
...)` was not pulled up, so a derived table filtered by an IN list on a join
key left the other side without the derived IN, and a left join that
hydrates child rows for a page of ids scanned the whole id prefix.
Accept `col IN (const, ...)` in ValidCompareConstantPredicate when every
constant has the column's collation, the same requirement as a single
comparison. The outer-join solver already derives the inner-side IN.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ti-chi-botBot
added
release-note
Denotes a PR that will be considered when it comes time to generate release notes.
size/L
Denotes a PR that changes 100-499 lines, ignoring generated files.
labels
Nov 17, 2026
No actionable comments were generated in the recent review.
Walkthrough
Eligible column IN predicates with constant list values can pass the constant-predicate check when their collations match. Predicate pull-up also excludes expressions with mutable effects. Integration cases cover propagation across joins and related conditions.
Changes: IN-list Constant Propagation
Layer / File(s)
Summary
Validate and pull up constant predicates pkg/expression/constant_propagation.go, pkg/planner/core/operator/logicalop/logical_selection.go
ValidCompareConstantPredicate now accepts IN predicates when the first argument is a column and every remaining argument is a constant with matching collation. PullUpConstantPredicates excludes predicates that contain mutable-effect expressions.
Exercise propagation across joins tests/integrationtest/t/planner/core/rule_constant_propagation.test, tests/integrationtest/r/planner/core/rule_constant_propagation.result, pkg/planner/core/casetest/rule/BUILD.bazel
Integration cases cover inner and outer joins, projections, collation matches and mismatches, non-constant list items, NOT IN, query results, and prepared-plan-cache predicates. The rule-test target’s shard count increases from 27 to 28.
The change lets constant IN lists propagate across joins and skips mutable predicates during pull-up. No concrete merge-blocking defect was found. A known Index Join estimate inflation is tracked in separate follow-up issues.
Pre-merge checks: 4
Check name
Status
Explanation
Description check
The description follows the repository template. It includes the required Issue Number line (close #73348), a problem summary, a description of what changed and how it works, a checked integration-tes…
Linked Issues check
[#73348] Requirement: constant propagation must pull up constant IN-list predicates out of a join child so a join equality can carry them to the other child. The whole-PR diff (merge base 8c05d01 to …
Out of Scope Changes check
Changes since the previous review: pkg/planner/core/operator/logicalop/logical_selection.go now skips predicates for which expression.IsMutableEffectsExpr is true during PullUpConstantPredicates. The …
Title check
The title 'planner: pull up IN-list predicates in constant propagation' matches the main change. The changeset extends ValidCompareConstantPredicate to accept IN predicates with constant list items th…
Full details: Description check
Explanation
The description follows the repository template. It includes the required Issue Number line (close #73348), a problem summary, a description of what changed and how it works, a checked integration-test box with a list of the tests added, and a release note. The Side effects and Documentation boxes are unchecked, and the description does not explain why the mutable-predicate exclusion in logical_selection.go was added. The commit message mentions that change, but the description does not.
Full details: Linked Issues check
Explanation
[#73348] Requirement: constant propagation must pull up constant IN-list predicates out of a join child so a join equality can carry them to the other child. The whole-PR diff (merge base 8c05d01 to head 65bf4d4) adds an ast.In branch to ValidCompareConstantPredicate in pkg/expression/constant_propagation.go. This dispatches to validInConstantPredicate, which accepts only [Column IN (Constant, ...)] where every constant has the column's collation. Non-constant list items and NOT IN are rejected. The change addresses the gap the issue names. The issue states that the outer-join and inner-join solvers already derive the other side once they see the predicate, and this PR does not change them. The integration test TestInListConstantPropagation (tests/integrationtest/t/planner/core/rule_constant_propagation.test and its result file) covers inner joins, left joins from the outer child, projections, and collation match and mismatch. No unit test was added. I did not re-run the plans; plan evidence comes from the result file. Remaining uncertainty: the new mutable-effect guard in LogicalSelection.PullUpConstantPredicates (see out-of-scope assessment) can exclude some predicates. The issue example uses plain literal constants, which the guard does not exclude.
Full details: Out of Scope Changes check
Explanation
Changes since the previous review: pkg/planner/core/operator/logicalop/logical_selection.go now skips predicates for which expression.IsMutableEffectsExpr is true during PullUpConstantPredicates. The commit message and code comment state that pull-up copies the predicate and a Constant may wrap a mutable deferred expression. This guard protects the same pull-up path that the IN support widens. The integration test file adds prepared-plan-cache cases that use RANDOM_BYTES in IN, equality, and range predicates, which exercise this guard. The guard is therefore connected to the objective of #73348 and is not unrelated. It does change behavior for existing comparison predicates as well, not only IN predicates. Other changes: the constant_propagation.go change limited to ValidCompareConstantPredicate and validInConstantPredicate; the integration test and result file; and the rule_test Bazel shard count from 27 to 28 for the added test cases. All of these support the objective. Limit: test and result file contents were checked through their summaries and the source diffs above, not by a full read of the test files.
Full details: Title check
Explanation
The title 'planner: pull up IN-list predicates in constant propagation' matches the main change. The changeset extends ValidCompareConstantPredicate to accept IN predicates with constant list items that share the column's collation, and LogicalSelection.PullUpConstantPredicates now skips mutable predicates. The title names the primary change. It includes the tracking tag 'tidb-test=pr/2829', which is noise but does not make the title misleading.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
golangci-lint (2.15.0)
Command failed
golangci-lint (2.15.0) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.0620%. Comparing base (8c05d01) to head (65bf4d4). ⚠️ Report is 109 commits behind head on master.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Approval recommended
No active review issues were identified in the supplied diff and review context, though tests were not run locally.
No open issues 🎉
What changed in this PR
Extends constant propagation to pull constant IN predicates out of join children, allowing existing solvers to propagate them across join equalities and enable more selective reads. This addresses #73348.
Changes:
Accepts column IN (constant, ...) when every list item is a constant with the column’s collation.
Adds integration coverage for join direction, projection, collation compatibility, unsupported predicates, and query results.
Validation was limited to the supplied diff and review context; no tests were run locally.
The derived IN helps the original composite-primary-key case, but it also exposes #73372 in Index Join. When the probe already binds both (a, b) from an outer row that passed b IN (10, 20), the copied t2.b IN (10, 20) is redundant. In my local comparison, it increased the probe scan estimate from 25 to 12,500 while the scan still returned 3 rows.
Please follow up with #73373 to complete the Index Join side of this change. I ran the stacked version locally and confirmed that the redundant filter disappeared, the probe scan estimate returned to 25, and the original #73348 query still used a six-key Batch_Point_Get on the right.
This pull-request has been approved by: winoros Once this PR has been reviewed and has the lgtm label, please assign windtalker for approval. For more information see the Code Review Process. Please ensure that each of them provides their approval before proceeding.
The full list of commands accepted by this bot can be found here.
Details
Needs approval from an approver in each of these files:
@winoros Thanks for running the stacked version. #73373 is the Index Join follow-up for #73372; I'll rebase it onto master and keep it moving alongside this PR.
@windtalker Could you review this one? It needs an approver for pkg/expression. It extends constant propagation to pull up IN-list predicates across equality joins (#73348); winoros has approved.
terry1purcell
changed the title
planner: pull up IN-list predicates in constant propagation
planner: pull up IN-list predicates in constant propagation | tidb-test=pr/2829
Nov 29, 2026
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. I understand the commands that are listed here.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: close #73348
Problem Summary:
Constant propagation pulls
col <op> constpredicates out of a join child so that a join equality can carry them to the other child, butValidCompareConstantPredicateonly accepts=,>,>=,<,<=. AnINlist of constants is left behind, so the other child loses a predicate that the equality version gets.A left join that hydrates the child rows of a page of parent ids hits this. With
id = ?the child side is a point read; withid in (?, ?)it scans every child row under the shared key prefix and filters the rest of the key row by row.What changed and how does it work?
ValidCompareConstantPredicatealso acceptscol IN (const, ...)when every constant has the column's collation, the same requirement it applies to a single comparison.propagateColumnEQ/deriveConds) and the inner-join solver already derive the other side'sINonce they see the predicate.Check List
Tests
Unit test
Integration test
Manual test (add detailed scripts or steps below)
No need to test
TestInListConstantPropagationintests/integrationtest/t/planner/core/rule_constant_propagation.test: inner join, left join from the outer child, no propagation from the inner child of a left or right join, through a projection, matching and mismatched collation, a non-constant item,NOT IN, and the results of three of the queries.go test -tags=intest ./pkg/planner/core/casetest/... ./pkg/expression/with failpoints enabled: passes, no recorded plan changes.tests/integrationtest/run-tests.sh: every case passes; no other recorded plan changes.Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
🤖 Generated with Claude Code
Summary by CodeRabbit
INfilters may benefit from constant propagation across joins, including supported inner- and outer-join cases and queries with projections.NOT IN.INlist contains non-constant values or string collations do not match.