Skip to content

Commit

Permalink
sql: add feature flag checking for UDF statements
Browse files Browse the repository at this point in the history
Release note: None
Release justification: low risk feature flags for DDL statements.
  • Loading branch information
chengxiong-ruan committed Aug 17, 2022
1 parent 79ef820 commit 4e01fb1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/sql/alter_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ type alterFunctionDepExtensionNode struct {
func (p *planner) AlterFunctionOptions(
ctx context.Context, n *tree.AlterFunctionOptions,
) (planNode, error) {
if err := checkSchemaChangeEnabled(
ctx,
p.ExecCfg(),
"ALTER FUNCTION",
); err != nil {
return nil, err
}

return &alterFunctionOptionsNode{n: n}, nil
}

Expand Down Expand Up @@ -90,6 +98,14 @@ func (n *alterFunctionOptionsNode) Close(ctx context.Context) {}
func (p *planner) AlterFunctionRename(
ctx context.Context, n *tree.AlterFunctionRename,
) (planNode, error) {
if err := checkSchemaChangeEnabled(
ctx,
p.ExecCfg(),
"ALTER FUNCTION",
); err != nil {
return nil, err
}

return &alterFunctionRenameNode{n: n}, nil
}

Expand Down Expand Up @@ -141,6 +157,14 @@ func (n *alterFunctionRenameNode) Close(ctx context.Context) {}
func (p *planner) AlterFunctionSetOwner(
ctx context.Context, n *tree.AlterFunctionSetOwner,
) (planNode, error) {
if err := checkSchemaChangeEnabled(
ctx,
p.ExecCfg(),
"ALTER FUNCTION",
); err != nil {
return nil, err
}

return &alterFunctionSetOwnerNode{n: n}, nil
}

Expand Down Expand Up @@ -181,6 +205,14 @@ func (n *alterFunctionSetOwnerNode) Close(ctx context.Context) {}
func (p *planner) AlterFunctionSetSchema(
ctx context.Context, n *tree.AlterFunctionSetSchema,
) (planNode, error) {
if err := checkSchemaChangeEnabled(
ctx,
p.ExecCfg(),
"ALTER FUNCTION",
); err != nil {
return nil, err
}

return &alterFunctionSetSchemaNode{n: n}, nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/drop_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ type dropFunctionNode struct {
func (p *planner) DropFunction(
ctx context.Context, n *tree.DropFunction,
) (ret planNode, err error) {
if err := checkSchemaChangeEnabled(
ctx,
p.ExecCfg(),
"DROP FUNCTION",
); err != nil {
return nil, err
}

if n.DropBehavior == tree.DropCascade {
// TODO(chengxiong): remove this check when drop function cascade is supported.
return nil, unimplemented.Newf("DROP FUNCTION...CASCADE", "drop function cascade not supported")
Expand Down
27 changes: 27 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/schema_change_feature_flags
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,30 @@ COMMENT ON TABLE t IS 'comment'
# Reset feature flag to true so that test objects can be dropped.
statement ok
SET CLUSTER SETTING feature.schema_change.enabled = TRUE

statement ok
SET CLUSTER SETTING feature.schema_change.enabled = FALSE

statement error pq: feature CREATE FUNCTION is part of the schema change category, which was disabled by the database administrator
CREATE FUNCTION f() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$;

statement error pq: feature CREATE FUNCTION is part of the schema change category, which was disabled by the database administrator
CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$;

statement error pq: feature DROP FUNCTION is part of the schema change category, which was disabled by the database administrator
DROP FUNCTION f()

statement error pq: feature ALTER FUNCTION is part of the schema change category, which was disabled by the database administrator
ALTER FUNCTION f() IMMUTABLE;

statement error pq: feature ALTER FUNCTION is part of the schema change category, which was disabled by the database administrator
ALTER FUNCTION f() RENAME TO g;

statement error pq: feature ALTER FUNCTION is part of the schema change category, which was disabled by the database administrator
ALTER FUNCTION f() OWNER TO new_owner;

statement error pq: feature ALTER FUNCTION is part of the schema change category, which was disabled by the database administrator
ALTER FUNCTION f() SET SCHEMA new_schema;

statement ok
SET CLUSTER SETTING feature.schema_change.enabled = TRUE

0 comments on commit 4e01fb1

Please sign in to comment.