Skip to content

Commit fc190f4

Browse files
committed
schemachanger: add builder and planner tests for DEFAULT / ON UPDATE
Release note: None
1 parent b1c79a5 commit fc190f4

File tree

5 files changed

+299
-1
lines changed

5 files changed

+299
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
setup
2+
CREATE TABLE t (i INT PRIMARY KEY, j INT)
3+
----
4+
5+
build
6+
ALTER TABLE t ALTER COLUMN j SET DEFAULT 42
7+
----
8+
- [[IndexData:{DescID: 104, IndexID: 1}, PUBLIC], PUBLIC]
9+
{indexId: 1, tableId: 104}
10+
- [[TableData:{DescID: 104, ReferencedDescID: 100}, PUBLIC], PUBLIC]
11+
{databaseId: 100, tableId: 104}
12+
- [[ColumnDefaultExpression:{DescID: 104, ColumnID: 2, Expr: 42:::INT8}, PUBLIC], ABSENT]
13+
{columnId: 2, expr: '42:::INT8', tableId: 104}
14+
15+
build
16+
ALTER TABLE t ALTER COLUMN j DROP DEFAULT
17+
----
18+
19+
setup
20+
CREATE TABLE t2 (i INT PRIMARY KEY, j INT DEFAULT 100)
21+
----
22+
23+
build
24+
ALTER TABLE t2 ALTER COLUMN j SET DEFAULT 200
25+
----
26+
- [[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC]
27+
{columnId: 2, expr: '100:::INT8', tableId: 105}
28+
- [[IndexData:{DescID: 105, IndexID: 1}, PUBLIC], PUBLIC]
29+
{indexId: 1, tableId: 105}
30+
- [[TableData:{DescID: 105, ReferencedDescID: 100}, PUBLIC], PUBLIC]
31+
{databaseId: 100, tableId: 105}
32+
- [[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 200:::INT8}, PUBLIC], ABSENT]
33+
{columnId: 2, expr: '200:::INT8', tableId: 105}
34+
35+
build
36+
ALTER TABLE t2 ALTER COLUMN j DROP DEFAULT
37+
----
38+
- [[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC]
39+
{columnId: 2, expr: '100:::INT8', tableId: 105}
40+
- [[IndexData:{DescID: 105, IndexID: 1}, PUBLIC], PUBLIC]
41+
{indexId: 1, tableId: 105}
42+
- [[TableData:{DescID: 105, ReferencedDescID: 100}, PUBLIC], PUBLIC]
43+
{databaseId: 100, tableId: 105}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
setup
2+
CREATE TABLE t (i INT PRIMARY KEY, j INT)
3+
----
4+
5+
build
6+
ALTER TABLE t ALTER COLUMN j SET ON UPDATE 42
7+
----
8+
- [[IndexData:{DescID: 104, IndexID: 1}, PUBLIC], PUBLIC]
9+
{indexId: 1, tableId: 104}
10+
- [[TableData:{DescID: 104, ReferencedDescID: 100}, PUBLIC], PUBLIC]
11+
{databaseId: 100, tableId: 104}
12+
- [[ColumnOnUpdateExpression:{DescID: 104, ColumnID: 2, Expr: 42:::INT8}, PUBLIC], ABSENT]
13+
{columnId: 2, expr: '42:::INT8', tableId: 104}
14+
15+
build
16+
ALTER TABLE t ALTER COLUMN j DROP ON UPDATE
17+
----
18+
19+
setup
20+
CREATE TABLE t2 (i INT PRIMARY KEY, j INT ON UPDATE 100)
21+
----
22+
23+
build
24+
ALTER TABLE t2 ALTER COLUMN j SET ON UPDATE 200
25+
----
26+
- [[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC]
27+
{columnId: 2, expr: '100:::INT8', tableId: 105}
28+
- [[IndexData:{DescID: 105, IndexID: 1}, PUBLIC], PUBLIC]
29+
{indexId: 1, tableId: 105}
30+
- [[TableData:{DescID: 105, ReferencedDescID: 100}, PUBLIC], PUBLIC]
31+
{databaseId: 100, tableId: 105}
32+
- [[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 200:::INT8}, PUBLIC], ABSENT]
33+
{columnId: 2, expr: '200:::INT8', tableId: 105}
34+
35+
build
36+
ALTER TABLE t2 ALTER COLUMN j DROP ON UPDATE
37+
----
38+
- [[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC]
39+
{columnId: 2, expr: '100:::INT8', tableId: 105}
40+
- [[IndexData:{DescID: 105, IndexID: 1}, PUBLIC], PUBLIC]
41+
{indexId: 1, tableId: 105}
42+
- [[TableData:{DescID: 105, ReferencedDescID: 100}, PUBLIC], PUBLIC]
43+
{databaseId: 100, tableId: 105}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
setup
2+
CREATE TABLE defaultdb.t (
3+
i INT PRIMARY KEY,
4+
j INT
5+
);
6+
----
7+
8+
ops
9+
ALTER TABLE defaultdb.t ALTER COLUMN j SET DEFAULT 42;
10+
----
11+
StatementPhase stage 1 of 1 with 1 MutationType op
12+
transitions:
13+
[[ColumnDefaultExpression:{DescID: 104, ColumnID: 2, Expr: 42:::INT8}, PUBLIC], ABSENT] -> PUBLIC
14+
ops:
15+
*scop.AddColumnDefaultExpression
16+
Default:
17+
ColumnID: 2
18+
Expression:
19+
Expr: 42:::INT8
20+
TableID: 104
21+
PreCommitPhase stage 1 of 2 with 1 MutationType op
22+
transitions:
23+
[[ColumnDefaultExpression:{DescID: 104, ColumnID: 2, Expr: 42:::INT8}, PUBLIC], PUBLIC] -> ABSENT
24+
ops:
25+
*scop.UndoAllInTxnImmediateMutationOpSideEffects
26+
{}
27+
PreCommitPhase stage 2 of 2 with 1 MutationType op
28+
transitions:
29+
[[ColumnDefaultExpression:{DescID: 104, ColumnID: 2, Expr: 42:::INT8}, PUBLIC], ABSENT] -> PUBLIC
30+
ops:
31+
*scop.AddColumnDefaultExpression
32+
Default:
33+
ColumnID: 2
34+
Expression:
35+
Expr: 42:::INT8
36+
TableID: 104
37+
38+
setup
39+
CREATE TABLE defaultdb.t2 (
40+
i INT PRIMARY KEY,
41+
j INT DEFAULT 100
42+
);
43+
----
44+
45+
ops
46+
ALTER TABLE defaultdb.t2 ALTER COLUMN j DROP DEFAULT;
47+
----
48+
StatementPhase stage 1 of 1 with 1 MutationType op
49+
transitions:
50+
[[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC] -> ABSENT
51+
ops:
52+
*scop.RemoveColumnDefaultExpression
53+
ColumnID: 2
54+
TableID: 105
55+
PreCommitPhase stage 1 of 2 with 1 MutationType op
56+
transitions:
57+
[[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], ABSENT] -> PUBLIC
58+
ops:
59+
*scop.UndoAllInTxnImmediateMutationOpSideEffects
60+
{}
61+
PreCommitPhase stage 2 of 2 with 1 MutationType op
62+
transitions:
63+
[[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC] -> ABSENT
64+
ops:
65+
*scop.RemoveColumnDefaultExpression
66+
ColumnID: 2
67+
TableID: 105
68+
69+
ops
70+
ALTER TABLE defaultdb.t2 ALTER COLUMN j SET DEFAULT 200;
71+
----
72+
StatementPhase stage 1 of 1 with 2 MutationType ops
73+
transitions:
74+
[[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC] -> ABSENT
75+
[[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 200:::INT8}, PUBLIC], ABSENT] -> PUBLIC
76+
ops:
77+
*scop.RemoveColumnDefaultExpression
78+
ColumnID: 2
79+
TableID: 105
80+
*scop.AddColumnDefaultExpression
81+
Default:
82+
ColumnID: 2
83+
Expression:
84+
Expr: 200:::INT8
85+
TableID: 105
86+
PreCommitPhase stage 1 of 2 with 1 MutationType op
87+
transitions:
88+
[[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], ABSENT] -> PUBLIC
89+
[[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 200:::INT8}, PUBLIC], PUBLIC] -> ABSENT
90+
ops:
91+
*scop.UndoAllInTxnImmediateMutationOpSideEffects
92+
{}
93+
PreCommitPhase stage 2 of 2 with 2 MutationType ops
94+
transitions:
95+
[[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC] -> ABSENT
96+
[[ColumnDefaultExpression:{DescID: 105, ColumnID: 2, Expr: 200:::INT8}, PUBLIC], ABSENT] -> PUBLIC
97+
ops:
98+
*scop.RemoveColumnDefaultExpression
99+
ColumnID: 2
100+
TableID: 105
101+
*scop.AddColumnDefaultExpression
102+
Default:
103+
ColumnID: 2
104+
Expression:
105+
Expr: 200:::INT8
106+
TableID: 105
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
setup
2+
CREATE TABLE defaultdb.t (
3+
i INT PRIMARY KEY,
4+
j INT
5+
);
6+
----
7+
8+
ops
9+
ALTER TABLE defaultdb.t ALTER COLUMN j SET ON UPDATE 42;
10+
----
11+
StatementPhase stage 1 of 1 with 1 MutationType op
12+
transitions:
13+
[[ColumnOnUpdateExpression:{DescID: 104, ColumnID: 2, Expr: 42:::INT8}, PUBLIC], ABSENT] -> PUBLIC
14+
ops:
15+
*scop.AddColumnOnUpdateExpression
16+
OnUpdate:
17+
ColumnID: 2
18+
Expression:
19+
Expr: 42:::INT8
20+
TableID: 104
21+
PreCommitPhase stage 1 of 2 with 1 MutationType op
22+
transitions:
23+
[[ColumnOnUpdateExpression:{DescID: 104, ColumnID: 2, Expr: 42:::INT8}, PUBLIC], PUBLIC] -> ABSENT
24+
ops:
25+
*scop.UndoAllInTxnImmediateMutationOpSideEffects
26+
{}
27+
PreCommitPhase stage 2 of 2 with 1 MutationType op
28+
transitions:
29+
[[ColumnOnUpdateExpression:{DescID: 104, ColumnID: 2, Expr: 42:::INT8}, PUBLIC], ABSENT] -> PUBLIC
30+
ops:
31+
*scop.AddColumnOnUpdateExpression
32+
OnUpdate:
33+
ColumnID: 2
34+
Expression:
35+
Expr: 42:::INT8
36+
TableID: 104
37+
38+
setup
39+
CREATE TABLE defaultdb.t2 (
40+
i INT PRIMARY KEY,
41+
j INT ON UPDATE 100
42+
);
43+
----
44+
45+
ops
46+
ALTER TABLE defaultdb.t2 ALTER COLUMN j DROP ON UPDATE;
47+
----
48+
StatementPhase stage 1 of 1 with 1 MutationType op
49+
transitions:
50+
[[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC] -> ABSENT
51+
ops:
52+
*scop.RemoveColumnOnUpdateExpression
53+
ColumnID: 2
54+
TableID: 105
55+
PreCommitPhase stage 1 of 2 with 1 MutationType op
56+
transitions:
57+
[[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], ABSENT] -> PUBLIC
58+
ops:
59+
*scop.UndoAllInTxnImmediateMutationOpSideEffects
60+
{}
61+
PreCommitPhase stage 2 of 2 with 1 MutationType op
62+
transitions:
63+
[[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC] -> ABSENT
64+
ops:
65+
*scop.RemoveColumnOnUpdateExpression
66+
ColumnID: 2
67+
TableID: 105
68+
69+
ops
70+
ALTER TABLE defaultdb.t2 ALTER COLUMN j SET ON UPDATE 200;
71+
----
72+
StatementPhase stage 1 of 1 with 2 MutationType ops
73+
transitions:
74+
[[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC] -> ABSENT
75+
[[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 200:::INT8}, PUBLIC], ABSENT] -> PUBLIC
76+
ops:
77+
*scop.RemoveColumnOnUpdateExpression
78+
ColumnID: 2
79+
TableID: 105
80+
*scop.AddColumnOnUpdateExpression
81+
OnUpdate:
82+
ColumnID: 2
83+
Expression:
84+
Expr: 200:::INT8
85+
TableID: 105
86+
PreCommitPhase stage 1 of 2 with 1 MutationType op
87+
transitions:
88+
[[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], ABSENT] -> PUBLIC
89+
[[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 200:::INT8}, PUBLIC], PUBLIC] -> ABSENT
90+
ops:
91+
*scop.UndoAllInTxnImmediateMutationOpSideEffects
92+
{}
93+
PreCommitPhase stage 2 of 2 with 2 MutationType ops
94+
transitions:
95+
[[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 100:::INT8}, ABSENT], PUBLIC] -> ABSENT
96+
[[ColumnOnUpdateExpression:{DescID: 105, ColumnID: 2, Expr: 200:::INT8}, PUBLIC], ABSENT] -> PUBLIC
97+
ops:
98+
*scop.RemoveColumnOnUpdateExpression
99+
ColumnID: 2
100+
TableID: 105
101+
*scop.AddColumnOnUpdateExpression
102+
OnUpdate:
103+
ColumnID: 2
104+
Expression:
105+
Expr: 200:::INT8
106+
TableID: 105

pkg/sql/schemachanger/scplan/testdata/drop_index

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ PostCommitNonRevertiblePhase stage 1 of 2 with 8 MutationType ops
19041904
PostCommitNonRevertiblePhase stage 2 of 2 with 10 MutationType ops
19051905
transitions:
19061906
[[Column:{DescID: 105, ColumnID: 6}, ABSENT], DELETE_ONLY] -> ABSENT
1907-
[[ColumnComputeExpression:{DescID: 105, ColumnID: 6, Usage: REGULAR}, ABSENT], PUBLIC] -> ABSENT
1907+
[[ColumnComputeExpression:{DescID: 105, ColumnID: 6, ReferencedFunctionIDs: [104], Usage: REGULAR}, ABSENT], PUBLIC] -> ABSENT
19081908
[[ColumnType:{DescID: 105, ColumnFamilyID: 0, ColumnID: 6, TypeName: INT8}, ABSENT], PUBLIC] -> ABSENT
19091909
[[SecondaryIndex:{DescID: 105, IndexID: 10, ConstraintID: 0, RecreateSourceIndexID: 0}, ABSENT], DELETE_ONLY] -> ABSENT
19101910
[[IndexData:{DescID: 105, IndexID: 10}, ABSENT], PUBLIC] -> ABSENT

0 commit comments

Comments
 (0)