planner: fix wrong TopN's ByItem with expression.ScalarFunction when to PushDownTopN#60822
Conversation
|
/check-issue-triage-complete |
c4ba304 to
51218a0
Compare
|
/test fast_tiprow_test |
|
@ti-chi-bot[bot]: 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. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #60822 +/- ##
================================================
+ Coverage 73.1429% 73.5929% +0.4499%
================================================
Files 1722 1722
Lines 476948 481220 +4272
================================================
+ Hits 348854 354144 +5290
+ Misses 106703 105535 -1168
- Partials 21391 21541 +150
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/retest |
There was a problem hiding this comment.
Pull Request Overview
This PR addresses a bug that causes the wrong schema to be used when pushing down TopN into a projection. Key changes include:
- Removing an extra blank line in optimizer.go.
- Adding a new unit test to verify the TopN push down behavior in projection.
- Updating the push down logic in logical_projection.go with an additional check using a new helper method (isSetTopNChild).
Reviewed Changes
Copilot reviewed 3 out of 6 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/planner/core/optimizer.go | Removed an unnecessary blank line to improve code clarity. |
| pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go | Added unit tests that verify the correct behavior for projection push down TopN. |
| pkg/planner/core/operator/logicalop/logical_projection.go | Updated TopN push down logic and added the helper method isSetTopNChild to better determine if the TopN child is set appropriately. |
Files not reviewed (3)
- pkg/planner/core/operator/logicalop/logicalop_test/BUILD.bazel: Language not supported
- tests/integrationtest/r/planner/core/plan.result: Language not supported
- tests/integrationtest/t/planner/core/plan.test: Language not supported
Comments suppressed due to low confidence (1)
pkg/planner/core/operator/logicalop/logical_projection.go:228
- [nitpick] The helper function name 'isSetTopNChild' is ambiguous. Consider renaming it to something like 'areTopNByItemsInChildSchema' so that its purpose is clearer.
if !p.Children()[0].Schema().Contains(col) {
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue with the TopN push down logic in the planner when dealing with projections that generate columns with ID=0. The changes update the push-down behavior in LogicalProjection and add new unit tests to verify the correct operator tree under different configuration scenarios.
- Update LogicalProjection.PushDownTopN to create a TopN operator without by-items when a projection-generated column is detected.
- Add unit tests in logical_operator_test to ensure the correct handling of TopN push down.
Reviewed Changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go | Adds tests validating the TopN push down logic with projections. |
| pkg/planner/core/operator/logicalop/logical_projection.go | Adjusts the push-down logic to generate a new TopN operator when the child schema is missing a projection-generated column. |
Files not reviewed (3)
- pkg/planner/core/operator/logicalop/logicalop_test/BUILD.bazel: Language not supported
- tests/integrationtest/r/planner/core/plan.result: Language not supported
- tests/integrationtest/t/planner/core/plan.test: Language not supported
Comments suppressed due to low confidence (2)
pkg/planner/core/operator/logicalop/logical_projection.go:228
- The condition checking for a projection-generated column (col.ID == 0) may inadvertently trigger the creation and push down of a TopN operator without by-items even for cases that are not truly projection-related. Consider refining this condition with additional checks to ensure that only columns generated by projection result in this behavior.
if !p.Children()[0].Schema().Contains(col) {
pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go:128
- [nitpick] Consider adding more granular assertions on the plan structure rather than relying on exact string matching, to reduce brittleness if plan formatting changes.
AS s
|
/retest |
2 similar comments
|
/retest |
|
/retest |
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: AilinKid, winoros 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 |
|
/cherrypick release-8.5 |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
|
@hawkingrei: new pull request created to branch 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 ti-community-infra/tichi repository. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
|
@hawkingrei: new pull request created to branch 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 ti-community-infra/tichi repository. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
|
@hawkingrei: new pull request created to branch 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 ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: close #60655
Problem Summary:
In the #40593,
There is a column in topN.ByItems is generated by proj, when topN is pushed down below proj, topN cannot obtain the column from datasource, to fix this, we can check whether topN.ByItems contains a column(with ID=0) generated by proj, if so, proj will prevent the optimizer from pushing topN down.
What changed and how does it work?
If you find that the TopN you can push down cannot actually be pushed down, you should use the original TopN to assemble into a structure of
TopN -> Projection, rather than using the processed TopN to assemble.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.