Skip to content

*: use user keyspace's collation mode for DXF tasks (#69677)#69702

Merged
ti-chi-bot[bot] merged 3 commits into
pingcap:release-nextgen-202603from
ti-chi-bot:cherry-pick-69677-to-release-nextgen-202603
Jul 7, 2026
Merged

*: use user keyspace's collation mode for DXF tasks (#69677)#69702
ti-chi-bot[bot] merged 3 commits into
pingcap:release-nextgen-202603from
ti-chi-bot:cherry-pick-69677-to-release-nextgen-202603

Conversation

@ti-chi-bot

@ti-chi-bot ti-chi-bot commented Jul 7, 2026

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #69677

What problem does this PR solve?

Issue Number: ref #69563

Problem Summary:

In next-gen deployments, DXF workers may run in a keyspace whose mysql.tidb.new_collation_enabled differs from the submitting user keyspace. If ADD INDEX or IMPORT INTO encodes user-table data with the worker-global setting, generated keys or restored row data can become inconsistent with the user table.

What changed and how does it work?

  • Store the submitting table snapshot's new-collation mode in ADD INDEX reorg metadata and IMPORT INTO plans.
  • Build DXF table, index, and codec helpers with that snapshot for affected encode/decode paths.
  • Fall back to the current process default for old task metadata that does not carry the snapshot.

Fix scope in this PR:

Supported:

  • DXF ADD INDEX and IMPORT INTO key/data encoding for non-partitioned tables.
  • Ordinary string transformation expressions whose result is encoded into table/index keys. This is covered for LOWER(), UPPER(), CONCAT(), and SUBSTR() in generated columns, expression indexes, and IMPORT INTO column assignments.

Out of scope / not validated in this PR:

  • Partitioned tables.
  • Partial indexes.
  • Expressions whose result depends on collation-sensitive comparison, search, ordering, or weight semantics, including =, <=>, !=, <, <=, >, >=, IN, LIKE/ILIKE/REGEXP, IF/CASE branches using those predicates, STRCMP(), FIELD(), LOCATE()/INSTR(), GREATEST()/LEAST(), and WEIGHT_STRING().

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.

Manual test setup:

  • Local next-gen CSE cluster.
  • User keyspace: mysql.tidb.new_collation_enabled = False.
  • System keyspace: mysql.tidb.new_collation_enabled = True.
  • Compared master local build with this PR local build.
  • For every test below, validation includes ADMIN CHECK TABLE, forced index reads vs primary reads, and post-load/post-backfill DML (INSERT, UPDATE, DELETE) followed by another ADMIN CHECK TABLE and forced index reads.

IMPORT INTO:

Case Master result This PR result
Clustered VARCHAR PK + secondary VARCHAR index Fails: secondary covering read decodes empty strings; ADMIN CHECK TABLE fails. Passes.
Clustered VARCHAR PK + secondary INT index Fails: secondary read decodes empty VARCHAR handle values. Passes.
Composite clustered PK with VARCHAR part + secondary INT index Fails: secondary read decodes empty id1 values. Passes.
Composite clustered INT PK + secondary VARCHAR index Fails: secondary read decodes the VARCHAR index value incorrectly. Passes.
Composite CHAR PK + secondary VARCHAR index Fails: secondary read reports missing decoded columns or table/index inconsistency. Passes.
Clustered VARCHAR PK + prefix secondary VARCHAR index Fails: IndexLookUp through idx_fk_prefix reports index-count:3 != record-count:0. Passes.
Clustered VARCHAR PK + secondary VARCHAR index + extra payload Fails: primary/table reads succeed, but secondary IndexLookUp reports index-count:1 != record-count:0. Passes.
Generated columns with string transformations Fails: ADMIN CHECK TABLE reports data inconsistency; forced reads through all four generated-column indexes report index-count:3 != record-count:0. Passes, including DML after import.
Assignment expressions with string transformations Fails: ADMIN CHECK TABLE reports data inconsistency; forced reads through all four assignment indexes report index-count:3 != record-count:0. Passes, including DML after import.
Controls without mismatched string collation in encoded keys Passes. Passes.
IMPORT INTO SQL details

Clustered VARCHAR PK + secondary VARCHAR index

Schema:

CREATE TABLE trigger_varchar_pk_varchar_idx (
  id varchar(32),
  fk varchar(32),
  PRIMARY KEY (id),
  KEY idx_fk (fk)
);

Import mapping:

IMPORT INTO trigger_varchar_pk_varchar_idx(@1,id,fk);

Clustered VARCHAR PK + secondary INT index

Schema:

CREATE TABLE trigger_varchar_pk_int_idx (
  id varchar(32),
  fk int,
  PRIMARY KEY (id),
  KEY idx_fk (fk)
);

Import mapping:

IMPORT INTO trigger_varchar_pk_int_idx(fk,id,@3);

Composite clustered PK with VARCHAR part + secondary INT index

Schema:

CREATE TABLE trigger_composite_varchar_int_pk_int_idx (
  id1 varchar(32),
  id2 int,
  fk int,
  PRIMARY KEY (id1, id2) CLUSTERED,
  KEY idx_fk (fk)
);

Import mapping:

IMPORT INTO trigger_composite_varchar_int_pk_int_idx(id2,fk,id1);

Composite clustered INT PK + secondary VARCHAR index

Schema:

CREATE TABLE trigger_composite_int_int_pk_varchar_idx (
  id1 int,
  id2 int,
  fk varchar(32),
  PRIMARY KEY (id1, id2) CLUSTERED,
  KEY idx_fk (fk)
);

Import mapping:

IMPORT INTO trigger_composite_int_int_pk_varchar_idx(id1,id2,fk);

Composite CHAR PK + secondary VARCHAR index

Schema:

CREATE TABLE trigger_composite_char_char_pk_varchar_idx (
  id1 char(32),
  id2 char(32),
  fk varchar(32),
  PRIMARY KEY (id1, id2) CLUSTERED,
  KEY idx_fk (fk)
);

Import mapping:

IMPORT INTO trigger_composite_char_char_pk_varchar_idx(fk,id1,id2);

Clustered VARCHAR PK + prefix secondary VARCHAR index

Schema:

CREATE TABLE trigger_varchar_pk_prefix_varchar_idx (
  id varchar(32),
  fk varchar(32),
  PRIMARY KEY (id) CLUSTERED,
  KEY idx_fk_prefix (fk(2))
);

Import mapping:

IMPORT INTO trigger_varchar_pk_prefix_varchar_idx(@1,id,fk);

Clustered VARCHAR PK + secondary VARCHAR index + extra payload

Schema:

CREATE TABLE trigger_record_ok_index_bad_extra_payload (
  id varchar(32),
  fk varchar(32),
  payload varchar(32) DEFAULT 'payload',
  PRIMARY KEY (id) CLUSTERED,
  KEY idx_fk (fk)
);

Import mapping:

IMPORT INTO trigger_record_ok_index_bad_extra_payload(@1,id,fk);

Generated columns with string transformations

Schema:

CREATE TABLE t_import_generated (
  id varchar(32),
  raw varchar(32),
  g_lower varchar(32) GENERATED ALWAYS AS (lower(raw)) STORED,
  g_upper varchar(32) GENERATED ALWAYS AS (upper(raw)) STORED,
  g_concat varchar(80) GENERATED ALWAYS AS (concat(id, ':', raw)) STORED,
  g_substr varchar(32) GENERATED ALWAYS AS (substr(raw, 1, 2)) STORED,
  PRIMARY KEY (id) CLUSTERED,
  KEY idx_lower (g_lower),
  KEY idx_upper (g_upper),
  KEY idx_concat (g_concat),
  KEY idx_substr (g_substr)
);

Import mapping:

IMPORT INTO t_import_generated(@1,id,raw);

Assignment expressions with string transformations

Schema:

CREATE TABLE t_import_assignment (
  id varchar(32),
  raw varchar(32),
  a_lower varchar(32),
  a_upper varchar(32),
  a_concat varchar(80),
  a_substr varchar(32),
  PRIMARY KEY (id) CLUSTERED,
  KEY idx_lower (a_lower),
  KEY idx_upper (a_upper),
  KEY idx_concat (a_concat),
  KEY idx_substr (a_substr)
);

Import mapping / SET:

IMPORT INTO t_import_assignment(@1,@2,@3)
SET id=@2,
    raw=@3,
    a_lower=lower(@3),
    a_upper=upper(@3),
    a_concat=concat(@2, ':', @3),
    a_substr=substr(@3, 1, 2);

Controls without mismatched string collation in encoded keys

Cases:

ok_int_pk_varchar_idx
ok_varchar_pk_no_secondary
ok_nonclustered_varchar_pk_varchar_idx
ok_char_pk_char_idx
ok_composite_int_int_pk_int_idx
ok_composite_varbinary_int_pk_int_idx
ok_composite_char_char_pk_int_idx

ADD INDEX:

Case Master result This PR result
Clustered VARCHAR PK + new secondary VARCHAR index Fails: ADMIN CHECK TABLE or secondary-index reads show table/index inconsistency. Passes.
Composite clustered PK with VARCHAR part + new secondary INT index Fails: ADMIN CHECK TABLE or secondary-index reads show table/index inconsistency. Passes.
Generated columns with string transformations Fails: ADMIN CHECK TABLE reports data inconsistency; forced reads through all four generated-column indexes report table/index count mismatch. Passes, including DML after ADD INDEX.
Expression indexes with string transformations Fails: ADMIN CHECK TABLE reports data inconsistency; forced reads through all four expression indexes report index-count:3 != record-count:0. Passes, including DML after ADD INDEX.
ADD INDEX SQL details

Clustered VARCHAR PK + new secondary VARCHAR index

Schema / DML:

CREATE TABLE t_varchar_pk (
  id varchar(32),
  fk varchar(32),
  PRIMARY KEY (id) CLUSTERED
);
INSERT INTO t_varchar_pk VALUES ('aaa', 'abc'), ('bbb', 'bbc'), ('ccc', 'cbc');

ADD INDEX DDL:

ALTER TABLE t_varchar_pk ADD INDEX idx_fk(fk);

Composite clustered PK with VARCHAR part + new secondary INT index

Schema / DML:

CREATE TABLE t_composite_varchar_pk (
  id1 varchar(32),
  id2 int,
  fk int,
  PRIMARY KEY (id1, id2) CLUSTERED
);
INSERT INTO t_composite_varchar_pk VALUES ('ax', 1, 10), ('by', 2, 20), ('cz', 3, 30);

ADD INDEX DDL:

ALTER TABLE t_composite_varchar_pk ADD INDEX idx_fk(fk);

Generated columns with string transformations

Schema / DML:

CREATE TABLE t_add_generated_column_index (
  id varchar(32),
  raw varchar(32),
  g_lower varchar(32) GENERATED ALWAYS AS (lower(raw)) VIRTUAL,
  g_upper varchar(32) GENERATED ALWAYS AS (upper(raw)) VIRTUAL,
  g_concat varchar(80) GENERATED ALWAYS AS (concat(id, ':', raw)) VIRTUAL,
  g_substr varchar(32) GENERATED ALWAYS AS (substr(raw, 1, 2)) VIRTUAL,
  PRIMARY KEY (id) CLUSTERED
);
INSERT INTO t_add_generated_column_index(id, raw) VALUES ('aaa', 'abc'), ('bbb', 'bbc'), ('ccc', 'cbc');

ADD INDEX DDL:

ALTER TABLE t_add_generated_column_index ADD INDEX idx_g_lower(g_lower);
ALTER TABLE t_add_generated_column_index ADD INDEX idx_g_upper(g_upper);
ALTER TABLE t_add_generated_column_index ADD INDEX idx_g_concat(g_concat);
ALTER TABLE t_add_generated_column_index ADD INDEX idx_g_substr(g_substr);

Expression indexes with string transformations

Schema / DML:

CREATE TABLE t_add_expression_index (
  id varchar(32),
  raw varchar(32),
  PRIMARY KEY (id) CLUSTERED
);
INSERT INTO t_add_expression_index VALUES ('aaa', 'abc'), ('bbb', 'bbc'), ('ccc', 'cbc');

ADD INDEX DDL:

ALTER TABLE t_add_expression_index ADD INDEX idx_lower ((lower(raw)));
ALTER TABLE t_add_expression_index ADD INDEX idx_upper ((upper(raw)));
ALTER TABLE t_add_expression_index ADD INDEX idx_concat ((concat(id, ':', raw)));
ALTER TABLE t_add_expression_index ADD INDEX idx_substr ((substr(raw, 1, 2)));

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

Fix possible index and row data inconsistency when DXF ADD INDEX or IMPORT INTO encodes string data with a new-collation mode different from the submitting keyspace.

Summary by CodeRabbit

  • New Features

    • Extended “new collation” handling across IMPORT INTO, index backfill/reorganization, and DDL reorg workflows.
    • Added persisted “new collation” metadata support to carry collation mode through reorg jobs.
    • Improved cross-keyspace scenarios to validate mixed collation configurations.
  • Bug Fixes

    • Improved raw row and restored-handle decoding so restored index/table data matches the table’s collation mode.
  • Tests

    • Added/expanded unit and real-TiKV tests covering collation-aware table creation, job metadata persistence, and import/index correctness.

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added component/import do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/cherry-pick-for-release-nextgen-202603 labels Jul 7, 2026
@ti-chi-bot

Copy link
Copy Markdown
Member Author

@D3Hunter This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot

ti-chi-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

Details

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.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 26fefd95-c710-4232-88d8-f4b8923db8fe

📥 Commits

Reviewing files that changed from the base of the PR and between b7fd7d0 and 5d73035.

📒 Files selected for processing (4)
  • pkg/ddl/backfilling_dist_executor.go
  • pkg/ddl/backfilling_dist_scheduler.go
  • pkg/executor/importer/BUILD.bazel
  • pkg/infoschema/BUILD.bazel
💤 Files with no reviewable changes (3)
  • pkg/infoschema/BUILD.bazel
  • pkg/executor/importer/BUILD.bazel
  • pkg/ddl/backfilling_dist_executor.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/ddl/backfilling_dist_scheduler.go

📝 Walkthrough

Walkthrough

Threads a fixed UseNewCollate mode from table snapshots and reorg metadata into DDL backfill, IMPORT INTO/DXF, and decode/encode helpers, while updating tests and cross-keyspace harnesses to cover the new behavior.

Changes

Collation mode plumbing

Layer / File(s) Summary
Table contract and construction
pkg/table/table.go, pkg/table/tables/tables.go, pkg/table/tables/partition.go, pkg/table/tables/tables_test.go, pkg/table/tables/BUILD.bazel
Adds UseNewCollate() bool to table types, refactors collate-aware table construction, and updates partition initialization and table construction tests.
CopContext and reorg metadata
pkg/ddl/copr/copr_ctx.go, pkg/ddl/copr/copr_ctx_test.go, pkg/ddl/backfilling_txn_executor.go, pkg/ddl/executor.go, pkg/meta/model/reorg.go, pkg/meta/model/job_test.go
Threads a fixed collation flag through cop context creation, persists it in DDLReorgMeta, and stores the current mode when building reorg metadata.
DDL backfill and index reorg
pkg/ddl/backfilling_dist_executor.go, pkg/ddl/backfilling_dist_scheduler.go, pkg/ddl/backfilling_operators.go, pkg/ddl/index.go, pkg/ddl/index_cop.go, pkg/ddl/reorg.go, pkg/ddl/export_test.go, pkg/ddl/job_scheduler.go
Uses table-scoped collation for backfill table lookup, index creation, handle encoding, and restored-data lookup, and removes the old transaction-based table helper.
IMPORT INTO and DXF planning
pkg/executor/importer/import.go, pkg/executor/importer/import_test.go, pkg/executor/importer/sampler.go, pkg/executor/importer/table_import.go, pkg/executor/importer/chunk_process_testkit_test.go, pkg/dxf/importinto/planner.go, pkg/dxf/importinto/task_executor.go, pkg/dxf/importinto/conflictedkv/handler.go, pkg/dxf/importinto/BUILD.bazel, tests/realtikvtest/testkit.go, tests/realtikvtest/configs/next-gen/pd.toml, tests/realtikvtest/importintotest3/*, tests/realtikvtest/addindextest1/*
Captures per-plan collation state, constructs IMPORT INTO/DXF tables with that mode, and expands the real-TiKV cross-keyspace test harness and scenarios.
Decode and generated-column call sites
lightning/pkg/errormanager/errormanager.go, pkg/executor/batch_checker.go, pkg/executor/admin.go, pkg/lightning/backend/kv/base.go, pkg/lightning/backend/kv/kv2sql.go, pkg/lightning/backend/kv/sql2kv.go, pkg/table/tables/mutation_checker_test.go, pkg/expression/expression.go, pkg/infoschema/tables.go, pkg/infoschema/BUILD.bazel
Passes table objects into row decoding, updates generated-column helpers to accept a table and collation flag, and adds UseNewCollate() to infoschema tables.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • pingcap/tidb#69023: Shares the DDL backfill runtime and table-lookup area in pkg/ddl/backfilling_dist_executor.go and pkg/ddl/backfilling_dist_scheduler.go.
  • pingcap/tidb#69566: Covers the same explicit collate-aware decode/encode API direction used by these DecodeRawRowData and TryGetHandleRestoredDataWrapper changes.
  • pingcap/tidb#69677: Touches the same tables.DecodeRawRowData call site in lightning/pkg/errormanager/errormanager.go.

Suggested labels: approved, lgtm

Suggested reviewers: D3Hunter, joechenrh, wjhuang2016, GMHDBJD

Poem

A bunny hops through keyspaces neat and bright,
With collate mode now tagged just right.
Handles, rows, and plans agree,
Snapshot-bound, not global decree.
🐰✨ Thump! The tests all sing along,
And every decode lands where it belongs.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: using the user keyspace's collation mode for DXF tasks.
Description check ✅ Passed The description matches the template well, with an issue link, problem summary, change details, checklist, and release note.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="Running error: context loading failed: failed to load packages: failed to load packages: failed to load with go/packages: context deadline exceeded"
level=error msg="Timeout exceeded: try increasing it by passing --timeout option"


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/ddl/backfilling_dist_scheduler.go (1)

209-231: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Unresolved git merge-conflict markers left in source (compile-breaking).

Lines 209, 211, and 224 contain literal conflict markers. Beyond the invalid syntax, naively resolving by keeping both sides would leave a duplicate tbl declaration (line 219 vs. line 228) and an unassigned tblInfo reference inside the collate-resolution branch, since only the HEAD side (line 210) calls getTblInfo.

🔧 Suggested conflict resolution
-<<<<<<< HEAD
 	tblInfo, err := getTblInfo(ctx, store, job)
-=======
+	if err != nil {
+		return nil, nil, err
+	}
 	// we don't touch table data during add-index, a fake Allocators is enough.
 	defaultUseNewCollate := collate.NewCollationEnabled()
 	failpoint.Inject("overrideDefaultUseNewCollateForBackfillStep", func(val failpoint.Value) {
 		defaultUseNewCollate = val.(bool)
 	})
 	useNewCollate := job.ReorgMeta.GetUseNewCollateOrDefault(defaultUseNewCollate)
 	failpoint.InjectCall("afterResolveUserTableNewCollateForBackfillStep", job, defaultUseNewCollate, useNewCollate)
 	tbl, err := tables.TableFromMetaWithCollate(
 		useNewCollate,
 		autoid.NewAllocators(tblInfo.SepAutoInc()),
 		tblInfo,
 	)
->>>>>>> 09d214004a2 (*: use user keyspace's collation mode for DXF tasks (`#69677`))
 	if err != nil {
 		return nil, nil, err
 	}
-	tbl, err := getTable(d.ddlCtx.getAutoIDRequirement(), job.SchemaID, tblInfo)
-	if err != nil {
-		return nil, nil, err
-	}
 	return store, tbl, nil
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/ddl/backfilling_dist_scheduler.go` around lines 209 - 231, Resolve the
merge conflict in backfilling_dist_scheduler.go by removing all literal conflict
markers and choosing a single coherent flow in the backfill setup around the
getTblInfo/getTable/TableFromMetaWithCollate logic. Keep the initial tblInfo
fetch from getTblInfo, then use that same tblInfo when resolving collation and
constructing the table so there is only one tbl declaration and no uninitialized
tblInfo reference; make sure the final code path compiles cleanly with one err
check sequence.
🧹 Nitpick comments (1)
pkg/executor/importer/sampler.go (1)

338-342: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate table-construction logic with table_import.go's newEncodingTable.

This block (allocator + tables.TableFromMetaWithCollate + annotated error) duplicates newEncodingTable in table_import.go, same package. Consider generalizing newEncodingTable to accept a table.Table (instead of *LoadDataController) so both call sites share one implementation — reduces risk of the collation flag being wired inconsistently in the future.

♻️ Proposed consolidation
-func newEncodingTable(e *LoadDataController) (table.Table, error) {
-	idAlloc := kv.NewPanickingAllocators(e.Table.Meta().SepAutoInc())
-	tbl, err := tables.TableFromMetaWithCollate(e.Table.UseNewCollate(), idAlloc, e.Table.Meta())
-	if err != nil {
-		return nil, errors.Annotatef(err, "failed to tables.TableFromMeta %s", e.Table.Meta().Name)
-	}
-	return tbl, nil
-}
+func newEncodingTable(srcTbl table.Table) (table.Table, error) {
+	idAlloc := kv.NewPanickingAllocators(srcTbl.Meta().SepAutoInc())
+	tbl, err := tables.TableFromMetaWithCollate(srcTbl.UseNewCollate(), idAlloc, srcTbl.Meta())
+	if err != nil {
+		return nil, errors.Annotatef(err, "failed to tables.TableFromMeta %s", srcTbl.Meta().Name)
+	}
+	return tbl, nil
+}

Then call newEncodingTable(s.table) in sampleOneFile and newEncodingTable(e.Table) in table_import.go.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/executor/importer/sampler.go` around lines 338 - 342, The
table-construction block in sampleOneFile duplicates the logic already
implemented by newEncodingTable, including allocator setup,
TableFromMetaWithCollate, and error annotation. Refactor newEncodingTable in
table_import.go to accept a table.Table instead of *LoadDataController, then
update both sampleOneFile and the existing import path to call the shared helper
so the collation flag and error handling stay consistent in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/ddl/export_test.go`:
- Line 36: The test helper using ConvertRowToHandleAndIndexDatum is deriving its
handle encoder from the process-global collation setting instead of the
passed-in copCtx. Update the helper to use the collation mode from copCtx (or
the table snapshot context it represents) when creating the encoder, and remove
any reliance on collate.NewCollationEnabled() so cross-keyspace tests reflect
the context under test. Also update the second related usage noted in the diff
to keep both helper paths consistent.

In `@pkg/executor/importer/BUILD.bazel`:
- Around line 120-124: Remove the unresolved merge-conflict markers from the
BUILD.bazel entry and keep only the intended shard_count value in the importer
target. Clean up the conflict block around the shard_count setting so
pkg/executor/importer/BUILD.bazel contains valid Bazel syntax with no literal
<<<<<<<, =======, or >>>>>>> markers.

In `@pkg/infoschema/BUILD.bazel`:
- Around line 52-56: Resolve the merge conflict in the BUILD.bazel deps list by
removing the literal conflict markers and keeping the intended dependency
entries. Update the infoschema BUILD target so the deps section is valid Bazel
syntax again, using the surrounding target definition and the package dependency
names in this block to locate and clean up the conflict.

---

Outside diff comments:
In `@pkg/ddl/backfilling_dist_scheduler.go`:
- Around line 209-231: Resolve the merge conflict in
backfilling_dist_scheduler.go by removing all literal conflict markers and
choosing a single coherent flow in the backfill setup around the
getTblInfo/getTable/TableFromMetaWithCollate logic. Keep the initial tblInfo
fetch from getTblInfo, then use that same tblInfo when resolving collation and
constructing the table so there is only one tbl declaration and no uninitialized
tblInfo reference; make sure the final code path compiles cleanly with one err
check sequence.

---

Nitpick comments:
In `@pkg/executor/importer/sampler.go`:
- Around line 338-342: The table-construction block in sampleOneFile duplicates
the logic already implemented by newEncodingTable, including allocator setup,
TableFromMetaWithCollate, and error annotation. Refactor newEncodingTable in
table_import.go to accept a table.Table instead of *LoadDataController, then
update both sampleOneFile and the existing import path to call the shared helper
so the collation flag and error handling stay consistent in one place.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 49d0c520-27a3-4c2f-af23-41e161b4fd24

📥 Commits

Reviewing files that changed from the base of the PR and between 8b1d326 and b7fd7d0.

📒 Files selected for processing (45)
  • lightning/pkg/errormanager/errormanager.go
  • pkg/ddl/backfilling_dist_executor.go
  • pkg/ddl/backfilling_dist_scheduler.go
  • pkg/ddl/backfilling_operators.go
  • pkg/ddl/backfilling_txn_executor.go
  • pkg/ddl/copr/copr_ctx.go
  • pkg/ddl/copr/copr_ctx_test.go
  • pkg/ddl/executor.go
  • pkg/ddl/export_test.go
  • pkg/ddl/index.go
  • pkg/ddl/index_cop.go
  • pkg/ddl/job_scheduler.go
  • pkg/ddl/reorg.go
  • pkg/dxf/importinto/BUILD.bazel
  • pkg/dxf/importinto/conflictedkv/handler.go
  • pkg/dxf/importinto/planner.go
  • pkg/dxf/importinto/task_executor.go
  • pkg/executor/admin.go
  • pkg/executor/batch_checker.go
  • pkg/executor/importer/BUILD.bazel
  • pkg/executor/importer/chunk_process_testkit_test.go
  • pkg/executor/importer/import.go
  • pkg/executor/importer/import_test.go
  • pkg/executor/importer/sampler.go
  • pkg/executor/importer/table_import.go
  • pkg/expression/expression.go
  • pkg/infoschema/BUILD.bazel
  • pkg/infoschema/tables.go
  • pkg/lightning/backend/kv/base.go
  • pkg/lightning/backend/kv/kv2sql.go
  • pkg/lightning/backend/kv/sql2kv.go
  • pkg/meta/model/job_test.go
  • pkg/meta/model/reorg.go
  • pkg/table/table.go
  • pkg/table/tables/BUILD.bazel
  • pkg/table/tables/mutation_checker_test.go
  • pkg/table/tables/partition.go
  • pkg/table/tables/tables.go
  • pkg/table/tables/tables_test.go
  • tests/realtikvtest/addindextest1/BUILD.bazel
  • tests/realtikvtest/addindextest1/cross_ks_test.go
  • tests/realtikvtest/configs/next-gen/pd.toml
  • tests/realtikvtest/importintotest3/BUILD.bazel
  • tests/realtikvtest/importintotest3/cross_ks_test.go
  • tests/realtikvtest/testkit.go
💤 Files with no reviewable changes (1)
  • pkg/ddl/job_scheduler.go

Comment thread pkg/ddl/export_test.go
"github.com/pingcap/tidb/pkg/table"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/chunk"
"github.com/pingcap/tidb/pkg/util/collate"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use the cop context’s collation mode in this test helper.

ConvertRowToHandleAndIndexDatum receives copCtx, so deriving the handle encoder from collate.NewCollationEnabled() can make cross-keyspace tests use the process-global mode instead of the context/table snapshot being tested.

Proposed fix
-	"github.com/pingcap/tidb/pkg/util/collate"
@@
-	handle, err := ddl.BuildHandle(collate.NewCollationEnabled(), handleData, c.TableInfo, c.PrimaryKeyInfo, time.Local, errctx.StrictNoWarningContext)
+	handle, err := ddl.BuildHandle(c.UseNewCollate, handleData, c.TableInfo, c.PrimaryKeyInfo, time.Local, errctx.StrictNoWarningContext)

Also applies to: 84-84

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/ddl/export_test.go` at line 36, The test helper using
ConvertRowToHandleAndIndexDatum is deriving its handle encoder from the
process-global collation setting instead of the passed-in copCtx. Update the
helper to use the collation mode from copCtx (or the table snapshot context it
represents) when creating the encoder, and remove any reliance on
collate.NewCollationEnabled() so cross-keyspace tests reflect the context under
test. Also update the second related usage noted in the diff to keep both helper
paths consistent.

Comment thread pkg/executor/importer/BUILD.bazel Outdated
Comment on lines +120 to +124
<<<<<<< HEAD
shard_count = 40,
=======
shard_count = 42,
>>>>>>> 09d214004a2 (*: use user keyspace's collation mode for DXF tasks (#69677))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Unresolved merge-conflict markers break the BUILD file.

Lines 120-124 contain literal <<<<<<< HEAD / ======= / >>>>>>> conflict markers left in the file, which is invalid Bazel syntax and will fail parsing/build. This matches the PR comment noting the cherry-pick has merge conflicts and is on hold.

🔧 Proposed fix
-<<<<<<< HEAD
-    shard_count = 40,
-=======
-    shard_count = 42,
->>>>>>> 09d214004a2 (*: use user keyspace's collation mode for DXF tasks (`#69677`))
+    shard_count = 42,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<<<<<<< HEAD
shard_count = 40,
=======
shard_count = 42,
>>>>>>> 09d214004a2 (*: use user keyspace's collation mode for DXF tasks (#69677))
shard_count = 42,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/executor/importer/BUILD.bazel` around lines 120 - 124, Remove the
unresolved merge-conflict markers from the BUILD.bazel entry and keep only the
intended shard_count value in the importer target. Clean up the conflict block
around the shard_count setting so pkg/executor/importer/BUILD.bazel contains
valid Bazel syntax with no literal <<<<<<<, =======, or >>>>>>> markers.

Comment thread pkg/infoschema/BUILD.bazel Outdated
Comment on lines +52 to +56
<<<<<<< HEAD
=======
"//pkg/util/chunk",
"//pkg/util/collate",
>>>>>>> 09d214004a2 (*: use user keyspace's collation mode for DXF tasks (#69677))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Unresolved merge-conflict markers break the BUILD file.

Lines 52-56 contain literal <<<<<<< HEAD / ======= / >>>>>>> conflict markers, making this an invalid Bazel deps list. Same root cause as in pkg/executor/importer/BUILD.bazel — the cherry-pick conflicts noted in the PR thread need to be resolved before this can build.

🔧 Proposed fix
-<<<<<<< HEAD
-=======
-        "//pkg/util/chunk",
-        "//pkg/util/collate",
->>>>>>> 09d214004a2 (*: use user keyspace's collation mode for DXF tasks (`#69677`))
+        "//pkg/util/chunk",
+        "//pkg/util/collate",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<<<<<<< HEAD
=======
"//pkg/util/chunk",
"//pkg/util/collate",
>>>>>>> 09d214004a2 (*: use user keyspace's collation mode for DXF tasks (#69677))
"//pkg/util/chunk",
"//pkg/util/collate",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/infoschema/BUILD.bazel` around lines 52 - 56, Resolve the merge conflict
in the BUILD.bazel deps list by removing the literal conflict markers and
keeping the intended dependency entries. Update the infoschema BUILD target so
the deps section is valid Bazel syntax again, using the surrounding target
definition and the package dependency names in this block to locate and clean up
the conflict.

@ti-chi-bot

Copy link
Copy Markdown
Member Author

Cherry-pick conflicts appear resolved; removing the do-not-merge/hold label.

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 7, 2026
@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 7, 2026
@joechenrh

Copy link
Copy Markdown
Contributor

/hold Let'me test again with this branch.

@ti-chi-bot ti-chi-bot Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 7, 2026
@joechenrh

Copy link
Copy Markdown
Contributor

/test unit-test

@ti-chi-bot

ti-chi-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

@joechenrh: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

/test pull-build-next-gen
/test pull-integration-realcluster-test-next-gen
/test pull-mysql-client-test-next-gen
/test pull-unit-test-next-gen

The following commands are available to trigger optional jobs:

/test pull-br-integration-test-next-gen
/test pull-integration-ddl-test-next-gen
/test pull-integration-e2e-test-next-gen
/test pull-mysql-test-next-gen

Use /test all to run the following jobs that were automatically triggered:

pingcap/tidb/pull_build_next_gen
pingcap/tidb/pull_integration_realcluster_test_next_gen
pingcap/tidb/pull_mysql_client_test_next_gen
pingcap/tidb/pull_unit_test_next_gen
Details

In response to this:

/test unit-test

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.

@joechenrh

Copy link
Copy Markdown
Contributor

/retest

@windtalker windtalker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 7, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-07 04:49:05.572276579 +0000 UTC m=+84331.608371635: ☑️ agreed by joechenrh.
  • 2026-07-07 05:07:15.354709057 +0000 UTC m=+85421.390804113: ☑️ agreed by windtalker.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.37500% with 30 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release-nextgen-202603@5d7735a). Learn more about missing BASE report.

Additional details and impacted files
@@                     Coverage Diff                     @@
##             release-nextgen-202603     #69702   +/-   ##
===========================================================
  Coverage                          ?   76.1669%           
===========================================================
  Files                             ?       1936           
  Lines                             ?     540677           
  Branches                          ?          0           
===========================================================
  Hits                              ?     411817           
  Misses                            ?     128860           
  Partials                          ?          0           
Flag Coverage Δ
unit 76.1669% <84.3750%> (?)

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

Components Coverage Δ
dumpling 61.5065% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 48.7236% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joechenrh

Copy link
Copy Markdown
Contributor

/unhold
Local nextgen test passed.

@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 7, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, GMHDBJD, joechenrh, windtalker

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

The pull request process is described here

Details 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

@ti-chi-bot ti-chi-bot Bot added the approved label Jul 7, 2026
@ti-chi-bot ti-chi-bot Bot merged commit f55c185 into pingcap:release-nextgen-202603 Jul 7, 2026
18 checks passed
@ti-chi-bot ti-chi-bot Bot deleted the cherry-pick-69677-to-release-nextgen-202603 branch July 7, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved component/import lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/cherry-pick-for-release-nextgen-202603

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants