cockroachdb / cockroachdb/cockroach
schema: make CREATE TABLE use the new declarative schema changer
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
CREATE TABLE statements account for 60%+ of all executed DDL statements in Cockroach Cloud. We should work towards moving CREATE TABLE statements to use the new declarative schema changer to make our schema changes more robust.
Because CREATE TABLE depends on other schema changes, we would have to break this down into multiple phases.
## Phase 1 — Foundation
- [x] Wire CREATE TABLE through the DSC dispatcher behind a createTableChecks prefilter that initially rejects everything.
- [x] Add scop.CreateTableDescriptor op, executor visitor, and opgen wiring (Table.ABSENT → DESCRIPTOR_ADDED → PUBLIC) so a future builder body can materialize a descriptor.
- [x] Initialize desc.PrimaryIndex in CreateTableDescriptor with a valid version + encoding so the existing column-emission ops compose without hitting primary index has invalid version 0.
## Phase 2 — Trivial accepted surface
- [x] Tighten createTableChecks to accept the minimal shape: permanent persistence, no PARTITION BY / LOCALITY / STORAGE PARAMS / ON COMMIT / AS, only ColumnTableDef entries with scalar types and at most one inline single-column PRIMARY KEY. Defer IfNotExists, scalar-only types, etc.
- [x] Implement the builder body that emits Table / Namespace / SchemaChild / TableData / Column* / PrimaryIndex / IndexColumn / IndexName / ownership elements; include the implicit-rowid path for tables without an inline PK.
- [x] Add end-to-end testdata/end_to_end/create_table_simple/ with .definition + generated fixtures.
- [x] Regenerate existing fixtures whose setup blocks contain simple CREATE TABLE (now routed through the DSC), and verify diffs are benign (mutation IDs, TableSchemaLocked presence, ordering).
## Phase 3 — Widen column features
- [x] DEFAULT expressions
- [x] ON UPDATE expressions
- [x] NOT VISIBLE / HIDDEN
- [x] Computed (stored and virtual) columns
- [x] SERIAL columns
- [x] Generated identity columns
- [x] Non-scalar column types (arrays, collated strings, UDT/enum)
## Phase 4 — Widen table structure
- [x] Multi-column inline PRIMARY KEY
- [ ] Sharded primary keys (USING HASH)
- [ ] Inline UNIQUE constraints
- [x] Inline secondary INDEX definitions
- [x] Inline CHECK constraints
- [x] FAMILY definitions
- [ ] LIKE clause
- [x] Foreign keys (likely the largest single item; may need its own sub-issue)
## Phase 5 — Surfaces that need broader DSC work
- [x] STORAGE PARAMS
- [ ] PARTITION BY
- [x] LOCALITY / multi-region tables
- [x] TEMPORARY tables
- [x] UNLOGGED tables
- [ ] CTAS (CREATE TABLE … AS SELECT)
Jira issue: CRDB-25187
Epic CRDB-65937
Contributor guide
Assessment
This issue has not been assessed yet.