Skip to content

ddl, importer: use captured collation mode for background encoding#69592

Draft
joechenrh wants to merge 17 commits into
fix-dxf-collation-snapshot-basefrom
fix-dxf-collation-snapshot-on-refactor
Draft

ddl, importer: use captured collation mode for background encoding#69592
joechenrh wants to merge 17 commits into
fix-dxf-collation-snapshot-basefrom
fix-dxf-collation-snapshot-on-refactor

Conversation

@joechenrh

@joechenrh joechenrh commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Background ADD INDEX and IMPORT INTO encoding can run outside the submitting keyspace. In next-gen deployments, the worker current new-collation default can differ from the table or task setting, so common handle, index key, restored data, and generated expression encoding need a task-level snapshot instead of reading the worker-global value.

What changed?

  • Persist a use_new_collate snapshot in DDL reorg metadata and IMPORT INTO task plans.
  • Build ADD INDEX txn and ingest indexes, handles, restored data, and decode column maps with the captured value.
  • Build IMPORT INTO tables, KV encoders, sampled KV encoders, generated column expressions, and column assignment expressions with the captured value.
  • Keep old task metadata compatible by falling back to the current process default when the snapshot field is missing.

Tests

  • go test -p=1 ./pkg/ddl/copr

  • go test -p=1 ./pkg/table/tables ./pkg/lightning/backend/kv ./pkg/executor/importer ./pkg/planner/core -run '^$'

  • Local next-gen mismatch validation where the submitting user keyspace and the worker/system keyspace use different new-collation defaults.

  • ADD INDEX coverage:

    • Distributed ADD INDEX backfill with task-captured collation mode.
    • Index key encoding and common handle encoding/decoding.
    • Prefix/restored-data index path.
    • Generated column expression path.
    • Multiple indexes added by one ALTER statement.
    • Max-handle scan and handle rebuild from coprocessor chunks.
    • ADMIN CHECK TABLE after backfill, with DDL job verification that the work ran through DXF.
  • IMPORT INTO coverage:

    • File import with task-captured collation mode.
    • Table construction in planner/executor/importer paths.
    • SQL-to-KV encoding, sampled KV encoding, and raw row decoding.
    • Primary handle and secondary index consistency after import.
    • Generated column and column assignment expression paths.
    • Restored-data/extra-payload consistency checks.
    • ADMIN CHECK TABLE and query assertions after import.
  • Baseline comparison: the same local validations fail before this change with index/table inconsistency and pass on this branch.

@ti-chi-bot

ti-chi-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

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 the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 2, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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 kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/planner SIG: Planner labels Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e18b94c5-4a42-4e81-ae9d-1f4855ec432f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-dxf-collation-snapshot-on-refactor

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.

@joechenrh joechenrh force-pushed the fix-dxf-collation-snapshot-on-refactor branch from 2805216 to 39075e2 Compare July 2, 2026 09:40
@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 Jul 2, 2026
@joechenrh joechenrh force-pushed the fix-dxf-collation-snapshot-on-refactor branch from 39075e2 to 94e51a8 Compare July 2, 2026 09:51
Comment thread pkg/executor/importer/import.go Outdated
User: userSctx.GetSessionVars().User.String(),
Keyspace: userSctx.GetStore().GetKeyspace(),
}
p.SetUseNewCollate(tbl.UseNewCollate())

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.

NewCollate Is actually an cluster(keyspace) attribute, not a table attribute, i think we should get it from current source of truth, i.e. the global variable, not from tbl

@ti-chi-bot

ti-chi-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

[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 ailinkid, gmhdbjd, zanmato1984 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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. 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/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.

2 participants