Skip to content

Commit

Permalink
scbuildstmt: fallback for ADD COLUMN NOT NULL UNIQUE
Browse files Browse the repository at this point in the history
An issue (#90174) was recently discovered when we have concurrent
`add column not null unique` and inserts. This PR fall backs to the old
schema changer for `ADD COLUMN NOT NULL UNIQUE`.

Release note: None
  • Loading branch information
Xiang-Gu committed Oct 18, 2022
1 parent a7f40e7 commit ed33a4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func alterTableAddColumn(
GeneratedAsIdentityType: desc.GeneratedAsIdentityType,
PgAttributeNum: desc.GetPGAttributeNum(),
},
unique: d.Unique.IsUnique,
}
if ptr := desc.GeneratedAsIdentitySequenceOption; ptr != nil {
spec.col.GeneratedAsIdentitySequenceOption = *ptr
Expand Down Expand Up @@ -277,6 +278,7 @@ type addColumnSpec struct {
def *scpb.ColumnDefaultExpression
onUpdate *scpb.ColumnOnUpdateExpression
comment *scpb.ColumnComment
unique bool
}

// addColumn is a helper function which adds column element targets and ensures
Expand Down Expand Up @@ -338,6 +340,11 @@ func addColumn(b BuildCtx, spec addColumnSpec, n tree.NodeFormatter) (backing *s
// follow-up change in order to get this in.
allTargets := b.QueryByID(spec.tbl.TableID)
if spec.def == nil && spec.colType.ComputeExpr == nil {
if !spec.colType.IsNullable && spec.unique {
panic(scerrors.NotImplementedErrorf(n,
"`ADD COLUMN NOT NULL UNIQUE` is problematic with "+
"concurrent insert. See issue #90174"))
}
b.Add(&scpb.IndexColumn{
TableID: spec.tbl.TableID,
IndexID: existing.IndexID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ unimplemented
ALTER TABLE defaultdb.foo ADD COLUMN p INT, DROP COLUMN o
----

unimplemented
ALTER TABLE defaultdb.foo ADD COLUMN p INT NOT NULL UNIQUE
----

unimplemented
ALTER TABLE defaultdb.foo DROP CONSTRAINT foobar
----
Expand Down

0 comments on commit ed33a4c

Please sign in to comment.