-
Notifications
You must be signed in to change notification settings - Fork 6.2k
*: support descending-order indexes (#2519) #68049
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
Draft
takaidohigasi
wants to merge
25
commits into
pingcap:master
Choose a base branch
from
takaidohigasi:feature/desc-index
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
85171de
*: plumb per-column DESC flag through index metadata (phase 1 of #2519)
takaidohigasi e92b461
planner: honor IndexColumn.Desc when matching sort property (phase 2 …
takaidohigasi a23319b
codec: add EncodeKeyWithDesc/DecodeOneWithDesc primitives (phase 3a o…
takaidohigasi e414040
tablecodec: encode DESC index columns with complemented bytes (phase …
takaidohigasi 686a9dc
distsql,executor,tables: wire DESC encoding through read paths (phase…
takaidohigasi adb81f0
codec: auto-detect DESC flag bytes in chunk Decoder (phase 3d-A of #2…
takaidohigasi a2407dd
planner,model: enforce IndexInfo.IsServable at plan time (#2519)
takaidohigasi b05e420
ddl: gate CREATE INDEX on TiKV cluster version (#2519)
takaidohigasi 385d13f
planner: support mixed-direction composite indexes (#2519)
takaidohigasi 82006d0
ddl: regression test for DESC on expression-index parts (#2519)
takaidohigasi 7f506a5
ddl: lock down sysvar create-time-only semantics for DESC indexes (#2…
takaidohigasi be86ba2
ddl: clarify MinTiKVVersionForDescIndex is a release-coordinated TODO…
takaidohigasi 61a14ea
ddl: reject DESC on the columns of a clustered PRIMARY KEY (#2519)
takaidohigasi f40e70d
executor: propagate IndexRangesToKVRangesWithDesc error in IndexMerge…
takaidohigasi 3f246ba
planner: extend IsServable fence to LOAD DATA and IMPORT INTO (#2519)
takaidohigasi fcff441
ddl: bake tidb_enable_descending_index decision at SQL frontend (#2519)
takaidohigasi 4ce9687
ddl: delay DESC preflight until after OnExistIgnore short-circuit (#2…
takaidohigasi 3faacae
ddl: bound PD GetAllStores call with a 5s timeout (#2519)
takaidohigasi ffa8638
ddl: accept pre-release TiKV at the DESC index version floor (#2519)
takaidohigasi f89329e
planner: extend IsServable fence to writable non-public indexes (#2519)
takaidohigasi e9200da
ddl: clarify checkTiKVSupportsDescIndex docstring (#2519)
takaidohigasi 49bbaca
ddl: assert idx_a presence in TestDescendingIndexSysvarIsCreateTimeOn…
takaidohigasi 7fb5348
ddl: skip TiKV version gate for hypothetical DESC indexes (#2519)
takaidohigasi 37f2288
planner: run IMPORT INTO servability fence on latest schema (#2519)
takaidohigasi 8eec79a
tests: add tiup-playground e2e smoke test for descending-order indexe…
takaidohigasi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // Copyright 2026 PingCAP, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package ddl | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/pingcap/kvproto/pkg/metapb" | ||
| "github.com/pingcap/tidb/pkg/ddl/placement" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // store builds a synthetic *metapb.Store for the version-check tests. | ||
| // Pass an empty version to simulate a store that hasn't reported one yet. | ||
| func storeAt(id uint64, version string, isTiFlash bool) *metapb.Store { | ||
| s := &metapb.Store{Id: id, Version: version, Address: "mock"} | ||
| if isTiFlash { | ||
| s.Labels = []*metapb.StoreLabel{{Key: placement.EngineLabelKey, Value: placement.EngineLabelTiFlash}} | ||
| } | ||
| return s | ||
| } | ||
|
|
||
| func TestCheckStoresMeetDescIndexMinVersion(t *testing.T) { | ||
| const minVer = "9.0.0" | ||
| const failClosed = false // production semantics | ||
|
|
||
| t.Run("all TiKV stores are new enough", func(t *testing.T) { | ||
| stores := []*metapb.Store{ | ||
| storeAt(1, "9.0.0", false), | ||
| storeAt(2, "9.1.0", false), | ||
| storeAt(3, "v9.0.0", false), // leading-v normalisation | ||
| } | ||
| require.NoError(t, checkStoresMeetDescIndexMinVersion(stores, minVer, failClosed)) | ||
| }) | ||
|
|
||
| t.Run("an old TiKV store fails the gate", func(t *testing.T) { | ||
| stores := []*metapb.Store{ | ||
| storeAt(1, "9.0.0", false), | ||
| storeAt(2, "8.5.0", false), | ||
| } | ||
| err := checkStoresMeetDescIndexMinVersion(stores, minVer, failClosed) | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "store 2") | ||
| require.Contains(t, err.Error(), "8.5.0") | ||
| require.Contains(t, err.Error(), minVer) | ||
| require.Contains(t, err.Error(), "upgrade TiKV") | ||
| }) | ||
|
|
||
| t.Run("TiFlash stores are excluded from the check", func(t *testing.T) { | ||
| // A TiFlash store on an old version must not block the gate; the | ||
| // check is for TiKV only because TiKV alone runs the coprocessor | ||
| // path that needs the new decoder. | ||
| stores := []*metapb.Store{ | ||
| storeAt(1, "9.0.0", false), | ||
| storeAt(2, "1.0.0", true), // ancient TiFlash, ignored | ||
| } | ||
| require.NoError(t, checkStoresMeetDescIndexMinVersion(stores, minVer, failClosed)) | ||
| }) | ||
|
|
||
| t.Run("tombstone stores are skipped", func(t *testing.T) { | ||
| old := storeAt(2, "8.0.0", false) | ||
| old.State = metapb.StoreState_Tombstone | ||
| stores := []*metapb.Store{ | ||
| storeAt(1, "9.0.0", false), | ||
| old, | ||
| } | ||
| require.NoError(t, checkStoresMeetDescIndexMinVersion(stores, minVer, failClosed)) | ||
| }) | ||
|
|
||
| t.Run("empty version fails closed in production", func(t *testing.T) { | ||
| // A store that hasn't reported a clean semver yet cannot prove it | ||
| // can decode descending-order keys. The gate must reject the DDL | ||
| // rather than fall through and risk silent corruption. The operator | ||
| // can retry once PD has reconciled. | ||
| stores := []*metapb.Store{ | ||
| storeAt(1, "9.0.0", false), | ||
| storeAt(2, "", false), | ||
| } | ||
| err := checkStoresMeetDescIndexMinVersion(stores, minVer, failClosed) | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "store 2") | ||
| require.Contains(t, err.Error(), "has not reported a version") | ||
| }) | ||
|
|
||
| t.Run("empty version is tolerated in tests", func(t *testing.T) { | ||
| // In `intest` builds the mock store fixture reports empty versions | ||
| // for every replica, so the gate must let DDL through to allow | ||
| // integration tests to run. | ||
| stores := []*metapb.Store{ | ||
| storeAt(1, "9.0.0", false), | ||
| storeAt(2, "", false), | ||
| } | ||
| require.NoError(t, checkStoresMeetDescIndexMinVersion(stores, minVer, true)) | ||
| }) | ||
|
|
||
| t.Run("garbage version always fails closed", func(t *testing.T) { | ||
| // Unparsable version strings are unambiguously a bug or a | ||
| // misconfigured store; never tolerate them, even in tests. | ||
| stores := []*metapb.Store{ | ||
| storeAt(1, "9.0.0", false), | ||
| storeAt(2, "not-a-semver", false), | ||
| } | ||
| err := checkStoresMeetDescIndexMinVersion(stores, minVer, true) | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "store 2") | ||
| require.Contains(t, err.Error(), "unparsable") | ||
| }) | ||
|
|
||
| t.Run("malformed minVersion is reported", func(t *testing.T) { | ||
| err := checkStoresMeetDescIndexMinVersion(nil, "definitely-not-semver", failClosed) | ||
| require.Error(t, err) | ||
| }) | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.