Skip to content

Commit a9de873

Browse files
craig[bot]fqazi
craig[bot]
andcommittedFeb 14, 2025·
Merge #141426
141426: sql/schemachanger: add / fix tests for not null constraints r=fqazi a=fqazi Previously, tests for dropping columns with not null constraints did not work correctly because of a syntax error. To address this, this patch fixes those tests and adds an additional drop test for not null stored columns. Informs: #139864 Release note: None Co-authored-by: Faizan Qazi <[email protected]>
2 parents 9f7bab1 + 9cca22d commit a9de873

File tree

28 files changed

+1656
-203
lines changed

28 files changed

+1656
-203
lines changed
 

‎pkg/ccl/schemachangerccl/backup_base_generated_test.go

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/sql/schemachanger/sctest/end_to_end.go

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ func EndToEndSideEffects(t *testing.T, relTestCaseDir string, factory TestServer
170170
}
171171
return d.Expected
172172
})
173+
require.Equalf(t, 1, numTestStatementsObserved,
174+
"one test should exist")
173175
})
174176
}
175177

‎pkg/sql/schemachanger/sctest_generated_test.go

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_null_constraint/drop_column_with_null_constraint.definition

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ create table t (i int primary key, j int not null);
88
stage-exec phase=PostCommitPhase stage=:
99
INSERT INTO t (i) VALUES($stageKey);
1010
----
11-
pq: failed to satisfy CHECK constraint (j IS NOT NULL)
11+
pq: failed to satisfy CHECK constraint \(j IS NOT NULL\)
1212

1313
stage-exec phase=PostCommitNonRevertiblePhase stage=1
1414
INSERT INTO t (i) VALUES($stageKey);
1515
----
16-
pq: failed to satisfy CHECK constraint (j IS NOT NULL)
16+
pq: failed to satisfy CHECK constraint \(j IS NOT NULL\)
1717

1818

1919
stage-exec phase=PostCommitNonRevertiblePhase stage=2:
2020
INSERT INTO t (i) VALUES($stageKey);
2121
INSERT INTO t (i) VALUES($stageKey + 1);
22+
----
2223

2324
test
2425
alter table t drop column j;

‎pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_null_constraint/drop_column_with_null_constraint.explain

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP COL
147147
│ └── PUBLIC → TRANSIENT_ABSENT IndexData:{DescID: 104 (t), IndexID: 3}
148148
├── 4 elements transitioning toward ABSENT
149149
│ ├── DELETE_ONLY → ABSENT Column:{DescID: 104 (t), ColumnID: 2 (j-)}
150-
│ ├── PUBLIC → ABSENT ColumnType:{DescID: 104 (t), ColumnFamilyID: 0 (primary), ColumnID: 2 (j-)}
150+
│ ├── PUBLIC → ABSENT ColumnType:{DescID: 104 (t), ColumnFamilyID: 0 (primary), ColumnID: 2 (j-), TypeName: "INT8"}
151151
│ ├── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104 (t), IndexID: 1 (t_pkey-), ConstraintID: 1}
152152
│ └── PUBLIC → ABSENT IndexData:{DescID: 104 (t), IndexID: 1 (t_pkey-)}
153153
└── 6 Mutation operations

‎pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_null_constraint/drop_column_with_null_constraint.side_effects

+13-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ upsert descriptor #104
7878
+ sharded: {}
7979
+ storeColumnNames: []
8080
+ unique: true
81+
+ vecConfig: {}
8182
+ version: 4
8283
+ mutationId: 1
8384
+ state: BACKFILLING
@@ -102,6 +103,7 @@ upsert descriptor #104
102103
+ storeColumnNames: []
103104
+ unique: true
104105
+ useDeletePreservingEncoding: true
106+
+ vecConfig: {}
105107
+ version: 4
106108
+ mutationId: 1
107109
+ state: DELETE_ONLY
@@ -153,6 +155,8 @@ upsert descriptor #104
153155
+ nameMapping:
154156
+ columns:
155157
+ "1": i
158+
+ "4294967292": crdb_internal_origin_timestamp
159+
+ "4294967293": crdb_internal_origin_id
156160
+ "4294967294": tableoid
157161
+ "4294967295": crdb_internal_mvcc_timestamp
158162
+ families:
@@ -211,6 +215,7 @@ upsert descriptor #104
211215
+ sharded: {}
212216
+ storeColumnNames: []
213217
+ unique: true
218+
+ vecConfig: {}
214219
+ version: 4
215220
+ mutationId: 1
216221
+ state: BACKFILLING
@@ -235,6 +240,7 @@ upsert descriptor #104
235240
+ storeColumnNames: []
236241
+ unique: true
237242
+ useDeletePreservingEncoding: true
243+
+ vecConfig: {}
238244
+ version: 4
239245
+ mutationId: 1
240246
+ state: DELETE_ONLY
@@ -439,7 +445,8 @@ upsert descriptor #104
439445
+ storeColumnNames:
440446
+ - crdb_internal_column_2_name_placeholder
441447
unique: true
442-
version: 4
448+
vecConfig: {}
449+
...
443450
mutationId: 1
444451
state: WRITE_ONLY
445452
- - direction: DROP
@@ -463,6 +470,7 @@ upsert descriptor #104
463470
- storeColumnNames: []
464471
- unique: true
465472
- useDeletePreservingEncoding: true
473+
- vecConfig: {}
466474
- version: 4
467475
+ - column:
468476
+ id: 2
@@ -501,7 +509,7 @@ upsert descriptor #104
501509
- - j
502510
+ storeColumnNames: []
503511
unique: true
504-
version: 4
512+
vecConfig: {}
505513
...
506514
time: {}
507515
unexposedParentSchemaId: 101
@@ -550,6 +558,8 @@ upsert descriptor #104
550558
- nameMapping:
551559
- columns:
552560
- "1": i
561+
- "4294967292": crdb_internal_origin_timestamp
562+
- "4294967293": crdb_internal_origin_id
553563
- "4294967294": tableoid
554564
- "4294967295": crdb_internal_mvcc_timestamp
555565
- families:
@@ -601,6 +611,7 @@ upsert descriptor #104
601611
- storeColumnNames:
602612
- - crdb_internal_column_2_name_placeholder
603613
- unique: true
614+
- vecConfig: {}
604615
- version: 4
605616
- mutationId: 1
606617
- state: DELETE_ONLY
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* setup */
2+
create table t (i int primary key, j int not null);
3+
4+
/* test */
5+
alter table t drop column j;
6+
EXPLAIN (DDL) rollback at post-commit stage 1 of 7;
7+
----
8+
Schema change plan for rolling back ALTER TABLE defaultdb.public.t DROP COLUMN j;
9+
└── PostCommitNonRevertiblePhase
10+
└── Stage 1 of 1 in PostCommitNonRevertiblePhase
11+
├── 1 element transitioning toward PUBLIC
12+
│ └── VALIDATED → PUBLIC ColumnNotNull:{DescID: 104 (t), ColumnID: 2 (j+), IndexID: 0}
13+
├── 5 elements transitioning toward ABSENT
14+
│ ├── BACKFILL_ONLY → ABSENT PrimaryIndex:{DescID: 104 (t), IndexID: 2 (t_pkey-), ConstraintID: 2, TemporaryIndexID: 3, SourceIndexID: 1 (t_pkey+)}
15+
│ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104 (t), ColumnID: 1 (i), IndexID: 2 (t_pkey-)}
16+
│ ├── PUBLIC → ABSENT IndexData:{DescID: 104 (t), IndexID: 2 (t_pkey-)}
17+
│ ├── DELETE_ONLY → ABSENT TemporaryIndex:{DescID: 104 (t), IndexID: 3, ConstraintID: 3, SourceIndexID: 1 (t_pkey+)}
18+
│ └── PUBLIC → ABSENT IndexColumn:{DescID: 104 (t), ColumnID: 1 (i), IndexID: 3}
19+
└── 8 Mutation operations
20+
├── MakeValidatedColumnNotNullPublic {"ColumnID":2,"TableID":104}
21+
├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
22+
├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
23+
├── MakeIndexAbsent {"IndexID":2,"TableID":104}
24+
├── CreateGCJobForIndex {"IndexID":2,"TableID":104}
25+
├── MakeIndexAbsent {"IndexID":3,"TableID":104}
26+
├── RemoveJobStateFromDescriptor {"DescriptorID":104}
27+
└── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* setup */
2+
create table t (i int primary key, j int not null);
3+
4+
/* test */
5+
alter table t drop column j;
6+
EXPLAIN (DDL) rollback at post-commit stage 2 of 7;
7+
----
8+
Schema change plan for rolling back ALTER TABLE defaultdb.public.t DROP COLUMN j;
9+
└── PostCommitNonRevertiblePhase
10+
├── Stage 1 of 2 in PostCommitNonRevertiblePhase
11+
│ ├── 1 element transitioning toward PUBLIC
12+
│ │ └── VALIDATED → PUBLIC ColumnNotNull:{DescID: 104 (t), ColumnID: 2 (j+), IndexID: 0}
13+
│ ├── 4 elements transitioning toward ABSENT
14+
│ │ ├── BACKFILL_ONLY → ABSENT PrimaryIndex:{DescID: 104 (t), IndexID: 2 (t_pkey-), ConstraintID: 2, TemporaryIndexID: 3, SourceIndexID: 1 (t_pkey+)}
15+
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104 (t), ColumnID: 1 (i), IndexID: 2 (t_pkey-)}
16+
│ │ ├── WRITE_ONLY → DELETE_ONLY TemporaryIndex:{DescID: 104 (t), IndexID: 3, ConstraintID: 3, SourceIndexID: 1 (t_pkey+)}
17+
│ │ └── PUBLIC → ABSENT IndexColumn:{DescID: 104 (t), ColumnID: 1 (i), IndexID: 3}
18+
│ └── 7 Mutation operations
19+
│ ├── MakeValidatedColumnNotNullPublic {"ColumnID":2,"TableID":104}
20+
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
21+
│ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":3,"TableID":104}
22+
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
23+
│ ├── MakeIndexAbsent {"IndexID":2,"TableID":104}
24+
│ ├── SetJobStateOnDescriptor {"DescriptorID":104}
25+
│ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."}
26+
└── Stage 2 of 2 in PostCommitNonRevertiblePhase
27+
├── 3 elements transitioning toward ABSENT
28+
│ ├── PUBLIC → ABSENT IndexData:{DescID: 104 (t), IndexID: 2 (t_pkey-)}
29+
│ ├── DELETE_ONLY → ABSENT TemporaryIndex:{DescID: 104 (t), IndexID: 3, ConstraintID: 3, SourceIndexID: 1 (t_pkey+)}
30+
│ └── PUBLIC → ABSENT IndexData:{DescID: 104 (t), IndexID: 3}
31+
└── 5 Mutation operations
32+
├── CreateGCJobForIndex {"IndexID":2,"TableID":104}
33+
├── MakeIndexAbsent {"IndexID":3,"TableID":104}
34+
├── CreateGCJobForIndex {"IndexID":3,"TableID":104}
35+
├── RemoveJobStateFromDescriptor {"DescriptorID":104}
36+
└── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* setup */
2+
create table t (i int primary key, j int not null);
3+
4+
/* test */
5+
alter table t drop column j;
6+
EXPLAIN (DDL) rollback at post-commit stage 3 of 7;
7+
----
8+
Schema change plan for rolling back ALTER TABLE defaultdb.public.t DROP COLUMN j;
9+
└── PostCommitNonRevertiblePhase
10+
├── Stage 1 of 2 in PostCommitNonRevertiblePhase
11+
│ ├── 1 element transitioning toward PUBLIC
12+
│ │ └── VALIDATED → PUBLIC ColumnNotNull:{DescID: 104 (t), ColumnID: 2 (j+), IndexID: 0}
13+
│ ├── 4 elements transitioning toward ABSENT
14+
│ │ ├── BACKFILL_ONLY → ABSENT PrimaryIndex:{DescID: 104 (t), IndexID: 2 (t_pkey-), ConstraintID: 2, TemporaryIndexID: 3, SourceIndexID: 1 (t_pkey+)}
15+
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104 (t), ColumnID: 1 (i), IndexID: 2 (t_pkey-)}
16+
│ │ ├── WRITE_ONLY → DELETE_ONLY TemporaryIndex:{DescID: 104 (t), IndexID: 3, ConstraintID: 3, SourceIndexID: 1 (t_pkey+)}
17+
│ │ └── PUBLIC → ABSENT IndexColumn:{DescID: 104 (t), ColumnID: 1 (i), IndexID: 3}
18+
│ └── 7 Mutation operations
19+
│ ├── MakeValidatedColumnNotNullPublic {"ColumnID":2,"TableID":104}
20+
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
21+
│ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":3,"TableID":104}
22+
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
23+
│ ├── MakeIndexAbsent {"IndexID":2,"TableID":104}
24+
│ ├── SetJobStateOnDescriptor {"DescriptorID":104}
25+
│ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."}
26+
└── Stage 2 of 2 in PostCommitNonRevertiblePhase
27+
├── 3 elements transitioning toward ABSENT
28+
│ ├── PUBLIC → ABSENT IndexData:{DescID: 104 (t), IndexID: 2 (t_pkey-)}
29+
│ ├── DELETE_ONLY → ABSENT TemporaryIndex:{DescID: 104 (t), IndexID: 3, ConstraintID: 3, SourceIndexID: 1 (t_pkey+)}
30+
│ └── PUBLIC → ABSENT IndexData:{DescID: 104 (t), IndexID: 3}
31+
└── 5 Mutation operations
32+
├── CreateGCJobForIndex {"IndexID":2,"TableID":104}
33+
├── MakeIndexAbsent {"IndexID":3,"TableID":104}
34+
├── CreateGCJobForIndex {"IndexID":3,"TableID":104}
35+
├── RemoveJobStateFromDescriptor {"DescriptorID":104}
36+
└── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."}

0 commit comments

Comments
 (0)
Please sign in to comment.