Skip to content

ddl: support storage class table attributes#69605

Open
Connor1996 wants to merge 6 commits into
pingcap:masterfrom
Connor1996:codex/tidb-storage-class-ddl
Open

ddl: support storage class table attributes#69605
Connor1996 wants to merge 6 commits into
pingcap:masterfrom
Connor1996:codex/tidb-storage-class-ddl

Conversation

@Connor1996

@Connor1996 Connor1996 commented Jul 2, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: ref #69625

Problem Summary:
TiDB currently lacks upstream SQL and metadata support for table and partition storage class attributes, so storage class intent cannot be expressed in DDL or surfaced through schema introspection.

What changed and how does it work?

  • add STORAGE_CLASS syntax and ENGINE_ATTRIBUTE storage-class metadata
  • support create, alter, add partition, and reorganize partition handling
  • render storage-class metadata through SHOW CREATE TABLE
  • expose storage-class metadata through INFORMATION_SCHEMA.TABLES and INFORMATION_SCHEMA.PARTITIONS
  • add storage-class focused unit and integration coverage

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.
  • Parser coverage and focused DDL coverage pass locally.
  • Storage-class integration coverage passes locally with 94 cases.

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

Add `STORAGE_CLASS` table and partition attributes, including `SHOW CREATE TABLE` and `INFORMATION_SCHEMA` exposure for storage class metadata.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jul 2, 2026
@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/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds STORAGE_CLASS and ENGINE_ATTRIBUTE support across parser, metadata, DDL execution, information_schema exposure, and SHOW CREATE TABLE output, with unit and integration coverage.

Changes

Storage Class Feature

Layer / File(s) Summary
Parser and AST support for STORAGE_CLASS
pkg/parser/..., pkg/meta/model/.../BUILD.bazel
Adds STORAGE_CLASS keyword/token support, table-option grammar, restore support, and Bazel wiring for the parser and model packages.
Storage class parsing and application logic
pkg/ddl/storage_class.go, pkg/ddl/partition.go, pkg/ddl/storage_class_*_test.go
Implements storage class JSON parsing, conflict checks, tier validation, table/partition assignment, and partition value matching helpers.
Engine attribute DDL job handling
pkg/ddl/engine_attribute.go, pkg/ddl/job_worker.go, pkg/ddl/multi_schema_change.go
Adds CREATE TABLE engine attribute handling, ALTER TABLE job submission and execution, job worker dispatch, and multi-schema-change support for the new DDL action.
CREATE and ALTER TABLE wiring
pkg/ddl/create_table.go, pkg/ddl/executor.go, pkg/ddl/partition.go, pkg/ddl/schematracker/dm_tracker.go, pkg/ddl/schematracker/BUILD.bazel, pkg/ddl/schematracker/dm_tracker_test.go
Wires storage class handling into CREATE TABLE, ALTER TABLE, add/reorganize partition flows, and schema-tracker persistence.
Information schema and SHOW CREATE TABLE
pkg/infoschema/tables.go, pkg/executor/infoschema_reader.go, pkg/executor/show.go
Adds TIDB_STORAGE_CLASS columns, populates them in information schema output, and emits STORAGE_CLASS or ENGINE_ATTRIBUTE in SHOW CREATE TABLE.
Tests
pkg/ddl/storage_class_test.go, pkg/ddl/storage_class_partition_test.go, tests/integrationtest/t/ddl/storage_class.test, tests/integrationtest/r/ddl/storage_class.result
Adds DDL unit tests, schema-tracker tests, and integration coverage for storage class parsing, partition behavior, and information schema output.

Estimated code review effort: 5 (Critical) | ~120 minutes

Suggested labels: sig/planner

Suggested reviewers: wjhuang2016, gengliqi, YangKeao

Poem

A rabbit hops through tiers of storage,
IA and STANDARD, snug in order.
Partitions dance, and CREATE TABLE sings,
STORAGE_CLASS glitters on tiny springs.
Hop, hop — the metadata’s in bloom 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding storage class table attribute support.
Description check ✅ Passed The description includes the required sections, issue reference, change summary, checklist, and release note, so it is mostly complete.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 2, 2026
@Connor1996 Connor1996 force-pushed the codex/tidb-storage-class-ddl branch from 0fe079f to 43d3878 Compare July 3, 2026 00:01
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
@Connor1996 Connor1996 force-pushed the codex/tidb-storage-class-ddl branch from 43d3878 to ffd893d Compare July 3, 2026 00:15
@Connor1996 Connor1996 marked this pull request as ready for review July 3, 2026 00:49
@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 Jul 3, 2026
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.19718% with 240 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.9642%. Comparing base (b212b93) to head (1b288ce).

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69605        +/-   ##
================================================
- Coverage   76.3234%   75.9642%   -0.3593%     
================================================
  Files          2041       2080        +39     
  Lines        560728     579424     +18696     
================================================
+ Hits         427967     440155     +12188     
- Misses       131860     137210      +5350     
- Partials        901       2059      +1158     
Flag Coverage Δ
integration 45.8352% <66.1971%> (+6.1300%) ⬆️

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

Components Coverage Δ
dumpling 60.4471% <ø> (ø)
parser ∅ <ø> (∅)
br 64.0249% <ø> (+1.3036%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Connor1996 <zbk602423539@gmail.com>

@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: 1

🧹 Nitpick comments (3)
tests/integrationtest/t/ddl/storage_class.test (1)

36-44: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Missing integration coverage for the ENGINE_ATTRIBUTE fallback in SHOW CREATE TABLE.

This section only exercises SHOW CREATE TABLE for a simple no-scope, no-transition tier (STORAGE_CLASS='IA'). Per unit tests in pkg/ddl/storage_class_test.go (e.g. "with transitions falls back to engine attribute", "with scope falls back to engine attribute"), GetSimpleTableStorageClassForShowCreate declines and SHOW CREATE TABLE should render the raw ENGINE_ATTRIBUTE JSON instead of STORAGE_CLASS=... when transitions or scopes are present. There's no end-to-end integration test verifying that fallback rendering path.

🤖 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 `@tests/integrationtest/t/ddl/storage_class.test` around lines 36 - 44, The
current storage class integration test only covers the simple STORAGE_CLASS='IA'
path, so add an end-to-end case that exercises the SHOW CREATE TABLE fallback
when GetSimpleTableStorageClassForShowCreate declines. Extend
TestStorageClassSyntaxSugarForTable with a table definition that includes
transitions or scope so SHOW CREATE TABLE renders raw ENGINE_ATTRIBUTE JSON
instead of STORAGE_CLASS=..., and verify the output before and after an ALTER
TABLE path if needed.
pkg/ddl/multi_schema_change.go (1)

315-317: 📐 Maintainability & Code Quality | 🔵 Trivial

Minor: could merge into the adjacent no-op case group for consistency.

ActionModifyEngineAttribute is functionally a no-op here just like the case above it; consider merging into the same case list (case model.ActionRebaseAutoID, model.ActionModifyTableComment, model.ActionModifyTableCharsetAndCollate, model.ActionModifyEngineAttribute:) for consistency with the existing style.

🤖 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/multi_schema_change.go` around lines 315 - 317, The switch in
multiSchemaChange handling has a redundant no-op branch:
ActionModifyEngineAttribute behaves the same as the adjacent no-op cases. Merge
it into the existing case group in the relevant switch statement alongside
ActionRebaseAutoID, ActionModifyTableComment, and
ActionModifyTableCharsetAndCollate so the no-op actions are handled
consistently.
pkg/ddl/schematracker/dm_tracker_test.go (1)

132-164: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

LGTM! Solid coverage of the storage-class-rebuild-on-add-partition path for both range and list partitioning.

Consider optionally adding a negative case (new partition value falling outside the less_than/values_in scope) to confirm StorageClassTier is correctly left unset in that scenario.

🤖 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/schematracker/dm_tracker_test.go` around lines 132 - 164, Add a
negative test alongside TestSchemaTrackerAddPartitionRebuildsStorageClass to
cover AddPartition when the new partition expression falls outside the existing
storage_class scope; use schematracker.NewSchemaTracker, execCreate, execAlter,
and mustTableByName to verify the resulting Partition.Definitions entry leaves
StorageClassTier unset instead of matching model.StorageClassTierIA.
🤖 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/storage_class.go`:
- Around line 36-90: BuildStorageClassSettingsFromJSON treats nil as a default
STANDARD StorageClassSettings, not as “no settings”, so callers must not rely on
it to preserve an untouched storage_class. Update
onAlterTableStorageClassSettings to check for an absent/nil storage_class field
before calling BuildStorageClassSettingsFromJSON, mirroring the guard already
used by getStorageClassSettingsFromTableInfo. Keep the change localized to the
storage class handling path so the nil-input default behavior in
BuildStorageClassSettingsFromJSON remains intact.

---

Nitpick comments:
In `@pkg/ddl/multi_schema_change.go`:
- Around line 315-317: The switch in multiSchemaChange handling has a redundant
no-op branch: ActionModifyEngineAttribute behaves the same as the adjacent no-op
cases. Merge it into the existing case group in the relevant switch statement
alongside ActionRebaseAutoID, ActionModifyTableComment, and
ActionModifyTableCharsetAndCollate so the no-op actions are handled
consistently.

In `@pkg/ddl/schematracker/dm_tracker_test.go`:
- Around line 132-164: Add a negative test alongside
TestSchemaTrackerAddPartitionRebuildsStorageClass to cover AddPartition when the
new partition expression falls outside the existing storage_class scope; use
schematracker.NewSchemaTracker, execCreate, execAlter, and mustTableByName to
verify the resulting Partition.Definitions entry leaves StorageClassTier unset
instead of matching model.StorageClassTierIA.

In `@tests/integrationtest/t/ddl/storage_class.test`:
- Around line 36-44: The current storage class integration test only covers the
simple STORAGE_CLASS='IA' path, so add an end-to-end case that exercises the
SHOW CREATE TABLE fallback when GetSimpleTableStorageClassForShowCreate
declines. Extend TestStorageClassSyntaxSugarForTable with a table definition
that includes transitions or scope so SHOW CREATE TABLE renders raw
ENGINE_ATTRIBUTE JSON instead of STORAGE_CLASS=..., and verify the output before
and after an ALTER TABLE path if needed.
🪄 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: 3299c988-b78a-4d35-b390-d9dfe5d2846f

📥 Commits

Reviewing files that changed from the base of the PR and between b212b93 and ffd893d.

📒 Files selected for processing (27)
  • pkg/ddl/BUILD.bazel
  • pkg/ddl/create_table.go
  • pkg/ddl/engine_attribute.go
  • pkg/ddl/executor.go
  • pkg/ddl/job_worker.go
  • pkg/ddl/multi_schema_change.go
  • pkg/ddl/partition.go
  • pkg/ddl/schematracker/dm_tracker.go
  • pkg/ddl/schematracker/dm_tracker_test.go
  • pkg/ddl/storage_class.go
  • pkg/ddl/storage_class_partition_test.go
  • pkg/ddl/storage_class_test.go
  • pkg/executor/infoschema_reader.go
  • pkg/executor/show.go
  • pkg/infoschema/tables.go
  • pkg/meta/model/BUILD.bazel
  • pkg/meta/model/engine_attribute.go
  • pkg/meta/model/job_args.go
  • pkg/meta/model/table.go
  • pkg/parser/ast/ddl.go
  • pkg/parser/keywords.go
  • pkg/parser/keywords_test.go
  • pkg/parser/misc.go
  • pkg/parser/parser.go
  • pkg/parser/parser.y
  • tests/integrationtest/r/ddl/storage_class.result
  • tests/integrationtest/t/ddl/storage_class.test

Comment thread pkg/ddl/storage_class.go
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
@Connor1996

Copy link
Copy Markdown
Member Author

Addressed the remaining user-visible review gap in 5c44734 by adding integration coverage for the SHOW CREATE TABLE fallback path when storage class settings include transitions. The new case verifies raw ENGINE_ATTRIBUTE rendering on create and alter, then confirms SHOW CREATE switches back to STORAGE_CLASS syntax after altering back to a simple tier.

Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
@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 benjamin2037, terry1purcell 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

@Connor1996

Copy link
Copy Markdown
Member Author

Addressed the remaining low-risk review follow-ups in 1b288ce826:

  • merged ActionModifyEngineAttribute into the adjacent multi-schema no-op case list
  • extended TestSchemaTrackerAddPartitionRebuildsStorageClass with out-of-scope range/list cases

While adding the negative coverage, I verified the current storage-class contract is to fall back to STANDARD when a partition does not match the configured scope, so I kept that behavior and codified it in the test instead of changing semantics here.

@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed and removed do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/needs-triage-completed 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant