Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql/schemachanger: copy ALTER TABLE .. SET TYPE validation checks from legacy to DSC #127533

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions pkg/sql/alter_column_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,12 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sem/cast"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sem/volatility"
"github.com/cockroachdb/cockroach/pkg/sql/sqlerrors"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
"github.com/cockroachdb/errors"
)

var colInIndexNotSupportedErr = unimplemented.NewWithIssuef(
47636, "ALTER COLUMN TYPE requiring rewrite of on-disk "+
"data is currently not supported for columns that are part of an index")

var colOwnsSequenceNotSupportedErr = unimplemented.NewWithIssuef(
48244, "ALTER COLUMN TYPE for a column that owns a sequence "+
"is currently not supported")

var colWithConstraintNotSupportedErr = unimplemented.NewWithIssuef(
48288, "ALTER COLUMN TYPE for a column that has a constraint "+
"is currently not supported")

// AlterColTypeInTxnNotSupportedErr is returned when an ALTER COLUMN TYPE
// is tried in an explicit transaction.
var AlterColTypeInTxnNotSupportedErr = unimplemented.NewWithIssuef(
Expand Down Expand Up @@ -177,34 +166,36 @@ func alterColumnTypeGeneral(

// Disallow ALTER COLUMN TYPE general for columns that own sequences.
if col.NumOwnsSequences() != 0 {
return colOwnsSequenceNotSupportedErr
return sqlerrors.NewAlterColumnTypeColOwnsSequenceNotSupportedErr()
}

// Disallow ALTER COLUMN TYPE general for columns that have a check
// constraint.
for _, ck := range tableDesc.EnforcedCheckConstraints() {
if ck.CollectReferencedColumnIDs().Contains(col.GetID()) {
return colWithConstraintNotSupportedErr
return sqlerrors.NewAlterColumnTypeColWithConstraintNotSupportedErr()
}
}

// Disallow ALTER COLUMN TYPE general for columns that have a
// UNIQUE WITHOUT INDEX constraint.
for _, uc := range tableDesc.UniqueConstraintsWithoutIndex() {
if uc.CollectKeyColumnIDs().Contains(col.GetID()) {
return colWithConstraintNotSupportedErr
return sqlerrors.NewAlterColumnTypeColWithConstraintNotSupportedErr()
}
}

// Disallow ALTER COLUMN TYPE general for columns that have a foreign key
// constraint.
for _, fk := range tableDesc.OutboundForeignKeys() {
if fk.CollectOriginColumnIDs().Contains(col.GetID()) {
return colWithConstraintNotSupportedErr
return sqlerrors.NewAlterColumnTypeColWithConstraintNotSupportedErr()
}
}
for _, fk := range tableDesc.InboundForeignKeys() {
if fk.GetReferencedTableID() == tableDesc.GetID() &&
fk.CollectReferencedColumnIDs().Contains(col.GetID()) {
return colWithConstraintNotSupportedErr
return sqlerrors.NewAlterColumnTypeColWithConstraintNotSupportedErr()
}
}

Expand All @@ -214,7 +205,7 @@ func alterColumnTypeGeneral(
if idx.CollectKeyColumnIDs().Contains(col.GetID()) ||
idx.CollectKeySuffixColumnIDs().Contains(col.GetID()) ||
idx.CollectSecondaryStoredColumnIDs().Contains(col.GetID()) {
return colInIndexNotSupportedErr
return sqlerrors.NewAlterColumnTypeColInIndexNotSupportedErr()
}
}

Expand Down
Loading
Loading