@@ -25,6 +25,8 @@ import (
2525type supportedStatement struct {
2626 // fn is a function to perform a schema change.
2727 fn interface {}
28+ // statementTag tag for this statement.
29+ statementTag string
2830 // checks contains a coarse-grained function to filter out most
2931 // unsupported statements.
3032 // It's possible for certain unsupported statements to pass it but will
@@ -44,28 +46,32 @@ var supportedStatements = map[reflect.Type]supportedStatement{
4446 // Alter table will have commands individually whitelisted via the
4547 // supportedAlterTableStatements list, so wwe will consider it fully supported
4648 // here.
47- reflect .TypeOf ((* tree .AlterTable )(nil )): {fn : AlterTable , on : true , checks : alterTableChecks },
48- reflect .TypeOf ((* tree .CreateIndex )(nil )): {fn : CreateIndex , on : true , checks : isV231Active },
49- reflect .TypeOf ((* tree .DropDatabase )(nil )): {fn : DropDatabase , on : true , checks : isV221Active },
50- reflect .TypeOf ((* tree .DropOwnedBy )(nil )): {fn : DropOwnedBy , on : true , checks : isV222Active },
51- reflect .TypeOf ((* tree .DropSchema )(nil )): {fn : DropSchema , on : true , checks : isV221Active },
52- reflect .TypeOf ((* tree .DropSequence )(nil )): {fn : DropSequence , on : true , checks : isV221Active },
53- reflect .TypeOf ((* tree .DropTable )(nil )): {fn : DropTable , on : true , checks : isV221Active },
54- reflect .TypeOf ((* tree .DropType )(nil )): {fn : DropType , on : true , checks : isV221Active },
55- reflect .TypeOf ((* tree .DropView )(nil )): {fn : DropView , on : true , checks : isV221Active },
56- reflect .TypeOf ((* tree .CommentOnDatabase )(nil )): {fn : CommentOnDatabase , on : true , checks : isV222Active },
57- reflect .TypeOf ((* tree .CommentOnSchema )(nil )): {fn : CommentOnSchema , on : true , checks : isV222Active },
58- reflect .TypeOf ((* tree .CommentOnTable )(nil )): {fn : CommentOnTable , on : true , checks : isV222Active },
59- reflect .TypeOf ((* tree .CommentOnColumn )(nil )): {fn : CommentOnColumn , on : true , checks : isV222Active },
60- reflect .TypeOf ((* tree .CommentOnIndex )(nil )): {fn : CommentOnIndex , on : true , checks : isV222Active },
61- reflect .TypeOf ((* tree .CommentOnConstraint )(nil )): {fn : CommentOnConstraint , on : true , checks : isV222Active },
62- reflect .TypeOf ((* tree .DropIndex )(nil )): {fn : DropIndex , on : true , checks : isV231Active },
63- reflect .TypeOf ((* tree .DropFunction )(nil )): {fn : DropFunction , on : true , checks : isV231Active },
64- reflect .TypeOf ((* tree .CreateRoutine )(nil )): {fn : CreateFunction , on : true , checks : isV231Active },
65- reflect .TypeOf ((* tree .CreateSchema )(nil )): {fn : CreateSchema , on : true , checks : isV232Active },
66- reflect .TypeOf ((* tree .CreateSequence )(nil )): {fn : CreateSequence , on : true , checks : isV232Active },
49+ reflect .TypeOf ((* tree .AlterTable )(nil )): {fn : AlterTable , statementTag : tree . AlterTableTag , on : true , checks : alterTableChecks },
50+ reflect .TypeOf ((* tree .CreateIndex )(nil )): {fn : CreateIndex , statementTag : tree . CreateIndexTag , on : true , checks : isV231Active },
51+ reflect .TypeOf ((* tree .DropDatabase )(nil )): {fn : DropDatabase , statementTag : tree . DropDatabaseTag , on : true , checks : isV221Active },
52+ reflect .TypeOf ((* tree .DropOwnedBy )(nil )): {fn : DropOwnedBy , statementTag : tree . DropOwnedByTag , on : true , checks : isV222Active },
53+ reflect .TypeOf ((* tree .DropSchema )(nil )): {fn : DropSchema , statementTag : tree . DropSchemaTag , on : true , checks : isV221Active },
54+ reflect .TypeOf ((* tree .DropSequence )(nil )): {fn : DropSequence , statementTag : tree . DropSequenceTag , on : true , checks : isV221Active },
55+ reflect .TypeOf ((* tree .DropTable )(nil )): {fn : DropTable , statementTag : tree . DropTableTag , on : true , checks : isV221Active },
56+ reflect .TypeOf ((* tree .DropType )(nil )): {fn : DropType , statementTag : tree . DropTypeTag , on : true , checks : isV221Active },
57+ reflect .TypeOf ((* tree .DropView )(nil )): {fn : DropView , statementTag : tree . DropViewTag , on : true , checks : isV221Active },
58+ reflect .TypeOf ((* tree .CommentOnConstraint )(nil )): {fn : CommentOnConstraint , statementTag : tree . CommentOnConstraintTag , on : true , checks : isV222Active },
59+ reflect .TypeOf ((* tree .CommentOnDatabase )(nil )): {fn : CommentOnDatabase , statementTag : tree . CommentOnDatabaseTag , on : true , checks : isV222Active },
60+ reflect .TypeOf ((* tree .CommentOnSchema )(nil )): {fn : CommentOnSchema , statementTag : tree . CommentOnSchemaTag , on : true , checks : isV222Active },
61+ reflect .TypeOf ((* tree .CommentOnTable )(nil )): {fn : CommentOnTable , statementTag : tree . CommentOnTableTag , on : true , checks : isV222Active },
62+ reflect .TypeOf ((* tree .CommentOnColumn )(nil )): {fn : CommentOnColumn , statementTag : tree . CommentOnColumnTag , on : true , checks : isV222Active },
63+ reflect .TypeOf ((* tree .CommentOnIndex )(nil )): {fn : CommentOnIndex , statementTag : tree . CommentOnIndexTag , on : true , checks : isV222Active },
64+ reflect .TypeOf ((* tree .DropIndex )(nil )): {fn : DropIndex , statementTag : tree . DropIndexTag , on : true , checks : isV231Active },
65+ reflect .TypeOf ((* tree .DropFunction )(nil )): {fn : DropFunction , statementTag : tree . DropFunctionTag , on : true , checks : isV231Active },
66+ reflect .TypeOf ((* tree .CreateRoutine )(nil )): {fn : CreateFunction , statementTag : tree . CreateRoutineTag , on : true , checks : isV231Active },
67+ reflect .TypeOf ((* tree .CreateSchema )(nil )): {fn : CreateSchema , statementTag : tree . CreateSchemaTag , on : false , checks : isV232Active },
68+ reflect .TypeOf ((* tree .CreateSequence )(nil )): {fn : CreateSequence , statementTag : tree . CreateSequenceTag , on : false , checks : isV232Active },
6769}
6870
71+ // supportedStatementTags tracks statement tags which are implemented
72+ // by the declarative schema changer.
73+ var supportedStatementTags = map [string ]struct {}{}
74+
6975func init () {
7076 boolType := reflect .TypeOf ((* bool )(nil )).Elem ()
7177 // Check function signatures inside the supportedStatements map.
@@ -99,6 +105,9 @@ func init() {
99105 statementType , checks ))
100106 }
101107 }
108+ // Fetch the statement tag using the statement tag method on the type,
109+ // we can use this as a blacklist of blocked schema changes.
110+ supportedStatementTags [statementEntry .statementTag ] = struct {}{}
102111 }
103112}
104113
@@ -157,9 +166,16 @@ func isFullySupportedWithFalsePositiveInternal(
157166// Process dispatches on the statement type to populate the BuilderState
158167// embedded in the BuildCtx. Any error will be panicked.
159168func Process (b BuildCtx , n tree.Statement ) {
169+ newSchemaChangerMode := b .EvalCtx ().SessionData ().NewSchemaChangerMode
170+ // Check if the feature is either forced disabled or enabled,
171+ // using a cluster setting.
172+ disabledStatements := getSchemaChangerStatementControl (& b .ClusterSettings ().SV )
173+ if forcedEnabled := disabledStatements .CheckStatementControl (n ); forcedEnabled {
174+ newSchemaChangerMode = sessiondatapb .UseNewSchemaChangerUnsafe
175+ }
160176 // Run a few "quick checks" to see if the statement is not supported.
161177 if ! IsFullySupportedWithFalsePositive (n , b .EvalCtx ().Settings .Version .ActiveVersion (b ),
162- b . EvalCtx (). SessionData (). NewSchemaChangerMode ) {
178+ newSchemaChangerMode ) {
163179 panic (scerrors .NotImplementedError (n ))
164180 }
165181
0 commit comments