diff --git a/pkg/sql/pgwire/testdata/pgtest/notice b/pkg/sql/pgwire/testdata/pgtest/notice index e60704db2a91..b1bdffafbf42 100644 --- a/pkg/sql/pgwire/testdata/pgtest/notice +++ b/pkg/sql/pgwire/testdata/pgtest/notice @@ -55,7 +55,7 @@ Query {"String": "DROP INDEX t_x_idx"} until crdb_only CommandComplete ---- -{"Severity":"NOTICE","SeverityUnlocalized":"NOTICE","Code":"00000","Message":"the data for dropped indexes is reclaimed asynchronously","Detail":"","Hint":"The reclamation delay can be customized in the zone configuration for the table.","Position":0,"InternalPosition":0,"InternalQuery":"","Where":"","SchemaName":"","TableName":"","ColumnName":"","DataTypeName":"","ConstraintName":"","File":"drop_index.go","Line":66,"Routine":"DropIndex","UnknownFields":null} +{"Severity":"NOTICE","SeverityUnlocalized":"NOTICE","Code":"00000","Message":"the data for dropped indexes is reclaimed asynchronously","Detail":"","Hint":"The reclamation delay can be customized in the zone configuration for the table.","Position":0,"InternalPosition":0,"InternalQuery":"","Where":"","SchemaName":"","TableName":"","ColumnName":"","DataTypeName":"","ConstraintName":"","File":"drop_index.go","Line":68,"Routine":"DropIndex","UnknownFields":null} {"Type":"CommandComplete","CommandTag":"DROP INDEX"} until noncrdb_only diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go index 77931bc83b85..b5d3e9d63d49 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go @@ -13,6 +13,7 @@ package scbuildstmt import ( "sort" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" @@ -255,6 +256,12 @@ func dropColumn( } dropCascadeDescriptor(b, e.FunctionID) case *scpb.UniqueWithoutIndexConstraint: + // Until the appropriate version gate is hit, we still do not allow + // dropping unique without index constraints. + if !b.ClusterSettings().Version.IsActive(b, clusterversion.V23_1) { + panic(scerrors.NotImplementedErrorf(nil, "dropping without"+ + "index constraints is not allowed.")) + } constraintElems := b.QueryByID(e.TableID).Filter(hasConstraintIDAttrFilter(e.ConstraintID)) _, _, constraintName := scpb.FindConstraintWithoutIndexName(constraintElems.Filter(publicTargetFilter)) alterTableDropConstraint(b, tn, tbl, &tree.AlterTableDropConstraint{ @@ -263,6 +270,12 @@ func dropColumn( DropBehavior: behavior, }) case *scpb.UniqueWithoutIndexConstraintUnvalidated: + // Until the appropriate version gate is hit, we still do not allow + // dropping unique without index constraints. + if !b.ClusterSettings().Version.IsActive(b, clusterversion.V23_1) { + panic(scerrors.NotImplementedErrorf(nil, "dropping without"+ + "index constraints is not allowed.")) + } constraintElems := b.QueryByID(e.TableID).Filter(hasConstraintIDAttrFilter(e.ConstraintID)) _, _, constraintName := scpb.FindConstraintWithoutIndexName(constraintElems.Filter(publicTargetFilter)) alterTableDropConstraint(b, tn, tbl, &tree.AlterTableDropConstraint{ diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go index 05a6956b1dea..80f61e244f0f 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go @@ -13,11 +13,13 @@ package scbuildstmt import ( "fmt" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgnotice" "github.com/cockroachdb/cockroach/pkg/sql/privilege" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" "github.com/cockroachdb/cockroach/pkg/sql/sem/catid" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" @@ -235,6 +237,12 @@ func maybeDropDependentFKConstraints( // shouldDropFK returns true if it is a dependent FK and no uniqueness-providing // replacement can be found. shouldDropFK := func(fkReferencedColIDs []catid.ColumnID) bool { + // Until the appropriate version gate is hit, we still do not allow + // dropping foreign keys in any the context of secondary indexes. + if !b.ClusterSettings().Version.IsActive(b, clusterversion.V23_1) { + panic(scerrors.NotImplementedErrorf(nil, "dropping FK constraints"+ + " as a result of `DROP INDEX CASCADE` is not supported yet.")) + } return canToBeDroppedConstraintServeFK(fkReferencedColIDs) && !hasColsUniquenessConstraintOtherThan(b, tableID, fkReferencedColIDs, toBeDroppedConstraintID) }