Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Planner: Run full partition pruning if convertToPointGet converted keys to SortKey #59918

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

mjonss
Copy link
Contributor

@mjonss mjonss commented Mar 5, 2025

What problem does this PR solve?

Issue Number: close #59827

Problem Summary:
TODO: Also apply same change and tests for BatchPointGet

What changed and how does it work?

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.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Copy link

ti-chi-bot bot commented Mar 5, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 5, 2025
Copy link

tiprow bot commented Mar 5, 2025

Hi @mjonss. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@mjonss
Copy link
Contributor Author

mjonss commented Mar 5, 2025

/test all

Copy link

tiprow bot commented Mar 5, 2025

@mjonss: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test all

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.

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 6, 2025
@mjonss
Copy link
Contributor Author

mjonss commented Mar 6, 2025

/retest

Copy link

tiprow bot commented Mar 6, 2025

@mjonss: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

Copy link

codecov bot commented Mar 6, 2025

Codecov Report

Attention: Patch coverage is 62.38532% with 41 lines in your changes missing coverage. Please review.

Project coverage is 73.2498%. Comparing base (d392685) to head (48b16d5).
Report is 37 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #59918        +/-   ##
================================================
+ Coverage   72.9654%   73.2498%   +0.2844%     
================================================
  Files          1699       1703         +4     
  Lines        469477     475179      +5702     
================================================
+ Hits         342556     348068      +5512     
+ Misses       105828     105779        -49     
- Partials      21093      21332       +239     
Flag Coverage Δ
integration 42.7428% <30.2752%> (?)
unit 72.3433% <61.4678%> (+0.1829%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 45.0532% <ø> (+0.0251%) ⬆️
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mjonss
Copy link
Contributor Author

mjonss commented Mar 6, 2025

KEY partitioning does not seem to be affected, since it is using val.ToHashKey() which is using the value's collation, meaning that if it already is converted to binary SortKey, it will get the same hash/key partition as if it is a non-converted values with the original collation, which will be converted in val.ToHashKey()

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 6, 2025
@mjonss mjonss marked this pull request as ready for review March 6, 2025 18:08
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 6, 2025
Copy link

ti-chi-bot bot commented Mar 7, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hawkingrei for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mjonss
Copy link
Contributor Author

mjonss commented Mar 7, 2025

This PR also fixes other issues.

Like using plan_cache_partition_table_test.go:309: seed: 1741359028167964000 on 5bb1b5c with the following patch (i.e. disable this fix):

diff --git a/pkg/planner/core/point_get_plan.go b/pkg/planner/core/point_get_plan.go
index 030fd88139..671522f454 100644
--- a/pkg/planner/core/point_get_plan.go
+++ b/pkg/planner/core/point_get_plan.go
@@ -348,6 +348,9 @@ func (p *PointGetPlan) LoadTableStats(ctx sessionctx.Context) {
 // error
 // TODO: Also supporting BatchPointGet? Problem is that partition ID must be mapped to handle/IndexValue.
 func needsPartitionPruning(sctx sessionctx.Context, tblInfo *model.TableInfo, pt table.PartitionedTable, dbName string, indexInfo *model.IndexInfo, indexCols []*expression.Column, indexValues []types.Datum, conds []expression.Expression, partitionNames []ast.CIStr) ([]int, bool, error) {
+       if tblInfo != nil {
+               return nil, false, nil
+       }
        for i := range indexValues {
                if tblInfo.Columns[indexInfo.Columns[i].Offset].FieldType.EvalType() != types.ETString ||
                        indexValues[i].Collation() == tblInfo.Columns[indexInfo.Columns[i].Offset].GetCollate() {

I get this stack trace:

--- FAIL: TestPartitionVarcharFullCover (0.41s)
panic: runtime error: index out of range [2] with length 2 [recovered]
	panic: runtime error: index out of range [2] with length 2 [recovered]
	panic: runtime error: index out of range [2] with length 2

goroutine 32 [running]:
testing.tRunner.func1.2({0x10966d180, 0x1400839a408})
	/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1632 +0x1bc
testing.tRunner.func1()
	/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1635 +0x334
panic({0x10966d180?, 0x1400839a408?})
	/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:785 +0x124
github.com/pingcap/tidb/pkg/executor.(*ExecStmt).Exec.func1()
	/pkg/executor/adapter.go:491 +0x428
panic({0x10966d180?, 0x1400839a408?})
	/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:785 +0x124
github.com/pingcap/tidb/pkg/util/collate.decodeRune({0x1400839a108?, 0x140086b9090?}, 0x14006317308?)
	/pkg/util/collate/collate.go:307 +0x15c
github.com/pingcap/tidb/pkg/util/collate.(*unicode0900AICICollator).Compare(0x1400839a348?, {0x1400839a108, 0x2}, {0x10ce5dcc0, 0x1})
	/pkg/util/collate/unicode_0900_ai_ci_generated.go:47 +0x2a8
github.com/pingcap/tidb/pkg/types.CompareString({0x1400839a108, 0x2}, {0x10ce5dcc0, 0x1}, {0x1400839a348?, 0x14000800008?})
	/pkg/types/compare.go:86 +0x58
github.com/pingcap/tidb/pkg/expression.CompareStringWithCollationInfo({0x109a6c920, 0x1400160fe20}, {0x109ab6718?, 0x14007362420?}, {0x109ab6a58, 0x14008fded80}, {0x140086b9090?, 0x14006317420?}, {0x140086b9090?, 0x1400611de00?}, ...)
	/pkg/expression/builtin_compare.go:3430 +0xf8
github.com/pingcap/tidb/pkg/expression.(*builtinLTStringSig).evalInt(0x109a6c868?, {0x109a6c920?, 0x1400160fe20?}, {0x140086b9090?, 0x140063174d8?})
	/pkg/expression/builtin_compare.go:2267 +0x7c
github.com/pingcap/tidb/pkg/expression.(*ScalarFunction).EvalInt(0x14007dcfe30, {0x109a6c868?, 0x1400611de00?}, {0x140086b9090?, 0x0?})
	/pkg/expression/scalar_function.go:499 +0x7c
github.com/pingcap/tidb/pkg/table/tables.(*partitionedTable).locateRangeColumnPartition.func1(0x1)
	/pkg/table/tables/partition.go:1505 +0x158
sort.Search(0x14008fe4370?, 0x14006317658)
	/go/pkg/mod/golang.org/[email protected]/src/sort/search.go:65 +0x48
github.com/pingcap/tidb/pkg/table/tables.(*partitionedTable).locateRangeColumnPartition(0x140063176f8?, {0x109a6c868, 0x1400611de00}, 0x140001e1f80?, {0x140001e0b60, 0x3, 0x3})
	/pkg/table/tables/partition.go:1503 +0x128
github.com/pingcap/tidb/pkg/table/tables.(*partitionedTable).locatePartitionCommon(0x14008fe41e0, {0x109a6c868?, 0x1400611de00?}, 0x10ee41878?, 0x10?, 0x10?, 0x72?, {0x140001e0b60?, 0x140070d9a10?, 0x0?})
	/pkg/table/tables/partition.go:1420 +0x58
github.com/pingcap/tidb/pkg/table/tables.(*partitionedTable).locatePartitionIdx(0x14006317868?, {0x109a6c868?, 0x1400611de00?}, {0x140001e0b60?, 0x10d1ae001?, 0x72?})
	/pkg/table/tables/partition.go:1460 +0x7c
github.com/pingcap/tidb/pkg/table/tables.(*partitionedTable).GetPartitionIdxByRow(0x140017fcf80?, {0x109a6c868?, 0x1400611de00?}, {0x140001e0b60?, 0x0?, 0x0?})
	/pkg/table/tables/partition.go:1691 +0x28
github.com/pingcap/tidb/pkg/planner/core.(*PointGetPlan).PrunePartitions(0x1400b2b9a40, {0x109ab9400, 0x14006986a08})
	/pkg/planner/core/point_get_plan.go:483 +0x904
github.com/pingcap/tidb/pkg/executor.(*executorBuilder).buildPointGet(0x1400737a700, 0x1400b2b9a40)
	/pkg/executor/point_get.go:58 +0x98
github.com/pingcap/tidb/pkg/executor.(*executorBuilder).build(0x10c5f25b0?, {0x109a53140?, 0x1400b2b9a40})
	/pkg/executor/builder.go:197 +0xf78
github.com/pingcap/tidb/pkg/executor.(*executorBuilder).buildSelection(0x1400737a700, 0x140001e09a0)
	/pkg/executor/builder.go:2041 +0x68
github.com/pingcap/tidb/pkg/executor.(*executorBuilder).build(0x10c5f25f0?, {0x109a529c0?, 0x140001e09a0})
	/pkg/executor/builder.go:273 +0x900
github.com/pingcap/tidb/pkg/executor.(*executorBuilder).buildProjection(0x1400737a700, 0x140001e08c0)
	/pkg/executor/builder.go:2089 +0x68
github.com/pingcap/tidb/pkg/executor.(*executorBuilder).build(0x109ab9400?, {0x109a52a40?, 0x140001e08c0})
	/pkg/executor/builder.go:279 +0xa54
github.com/pingcap/tidb/pkg/executor.(*ExecStmt).buildExecutor(0x140001e0a80)
	/pkg/executor/adapter.go:1230 +0x150
github.com/pingcap/tidb/pkg/executor.(*ExecStmt).Exec(0x140001e0a80, {0x109a23a68, 0x1400681a570})
	/pkg/executor/adapter.go:571 +0x7a8
github.com/pingcap/tidb/pkg/session.runStmt({0x109a23890?, 0x10d1ae088?}, 0x14006986a08, {0x109a41e38, 0x140001e0a80})
	/pkg/session/session.go:2305 +0x274
github.com/pingcap/tidb/pkg/session.(*session).ExecuteStmt(0x14006986a08, {0x109a23890?, 0x10d1ae088?}, {0x109a3e4b8, 0x140012e88c0})
	/pkg/session/session.go:2167 +0xc60
github.com/pingcap/tidb/pkg/testkit.(*TestKit).ExecWithContext(0x1400679a460, {0x109a23890, 0x10d1ae088}, {0x14008c4c8d0, 0x2a}, {0x0, 0x0, 0x0})
	/pkg/testkit/testkit.go:425 +0x744
github.com/pingcap/tidb/pkg/testkit.(*TestKit).MustQueryWithContext(0x1400679a460, {0x109a23890, 0x10d1ae088}, {0x14008c4c8d0, 0x2a}, {0x0, 0x0, 0x0})
	/pkg/testkit/testkit.go:240 +0xc8
github.com/pingcap/tidb/pkg/testkit.(*TestKit).MustQuery(0x1400679a460, {0x14008c4c8d0, 0x2a}, {0x0, 0x0, 0x0})
	/pkg/testkit/testkit.go:176 +0x8c
github.com/pingcap/tidb/pkg/planner/core_test.preparedStmtPointGet(0x1400138e340, {0x14005e10008, 0x3e8, 0x0?}, 0x1400679a460, {{0x14006319c30, 0x3, 0x3}, {0x14006319f48, 0x1, ...}, ...}, ...)
	/pkg/planner/core/plan_cache_partition_table_test.go:588 +0x474
github.com/pingcap/tidb/pkg/planner/core_test.testPartitionFullCover(0x1400138e340, {0x14006319ce0, 0x5, 0x10a98bd93?}, {0x14006319c60, 0x2, 0x140000d7c58?}, 0x1)
	/pkg/planner/core/plan_cache_partition_table_test.go:426 +0xa74
github.com/pingcap/tidb/pkg/planner/core_test.TestPartitionVarcharFullCover(0x1400138e340?)
	/pkg/planner/core/plan_cache_partition_table_test.go:489 +0x328
testing.tRunner(0x1400138e340, 0x1099c7eb0)
	/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1690 +0xe4
created by testing.(*T).Run in goroutine 1
	/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1743 +0x314

@mjonss mjonss requested review from Defined2014 and Copilot March 7, 2025 15:30
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR refines partition pruning for point get and batch point get plans by propagating a new case‐sensitivity flag through various test and plan functions and restructuring error returns. Key changes include:

  • Propagation of an isCaseSensitive flag and corresponding adjustments in functions like getRowData and prepared/non-prepared statement functions.
  • Updates to partition pruning logic in point_get_plan.go including introducing needsPartitionPruning to handle SortKey conversion.
  • Enhancements in executor functions to properly handle error returns from the revised pruning functions.

Reviewed Changes

File Description
pkg/planner/core/plan_cache_partition_table_test.go Updated test helper functions to support case sensitivity adjustments and apply collation settings.
pkg/planner/core/point_get_plan.go Revised partition pruning logic and error handling; introduced needsPartitionPruning.
pkg/server/conn.go Modified prefetchPointPlanKeys to handle new error returns from partition pruning calls.
pkg/executor/point_get.go Adjusted buildPointGet to consider the new return types from pruning functions.
pkg/planner/core/find_best_task.go Updated comments regarding the inability to support BatchPointGet when keys are converted.
pkg/executor/builder.go Updated handling of BatchPointGet plans by checking for errors from the pruning phase.

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

pkg/planner/core/plan_cache_partition_table_test.go:620

  • Verify that changing the threshold from 't' to 'x' for filtering string keys in getRowData is intentional, as this adjustment alters which rows may be skipped.
if isCaseSensitive { if x >= "x" {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong Ranges for partition pruning
1 participant