Skip to content

Commit

Permalink
sql: de-experimentalize user defined schemas
Browse files Browse the repository at this point in the history
Release justification: low-risk update to new functionality
Release note (sql change): De-experimentalize user defined schemas.
  • Loading branch information
rohany committed Aug 31, 2020
1 parent ce1ef2a commit 3f99874
Show file tree
Hide file tree
Showing 21 changed files with 3 additions and 100 deletions.
13 changes: 1 addition & 12 deletions pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ func TestRestoreFailCleanup(t *testing.T) {
// failed restore.
sqlDB.Exec(t, `CREATE TYPE data.myenum AS ENUM ('hello')`)
// Do the same with a user defined schema.
sqlDB.Exec(t, `SET experimental_enable_user_defined_schemas = true; USE data; CREATE SCHEMA myschema`)
sqlDB.Exec(t, `USE data; CREATE SCHEMA myschema`)

sqlDB.Exec(t, `BACKUP DATABASE data TO $1`, LocalFoo)
// Bugger the backup by removing the SST files.
Expand Down Expand Up @@ -1823,7 +1823,6 @@ func TestBackupRestoreUserDefinedSchemas(t *testing.T) {

var ts1, ts2, ts3, ts4, ts5, ts6 string
sqlDB.Exec(t, `
SET experimental_enable_user_defined_schemas = true;
CREATE DATABASE d;
USE d;
Expand Down Expand Up @@ -1911,8 +1910,6 @@ CREATE TABLE sc.t1 (a FLOAT);
_, _, sqlDB, dataDir, cleanupFn := BackupRestoreTestSetup(t, singleNode, 0, InitNone)
defer cleanupFn()
sqlDB.Exec(t, `
SET experimental_enable_user_defined_schemas = true;
CREATE DATABASE d;
USE d;
CREATE SCHEMA unused;
Expand Down Expand Up @@ -1948,8 +1945,6 @@ INSERT INTO sc.tb2 VALUES ('hello');
defer cleanupFn()

sqlDB.Exec(t, `
SET experimental_enable_user_defined_schemas = true;
CREATE DATABASE d;
USE d;
CREATE SCHEMA sc;
Expand Down Expand Up @@ -1984,8 +1979,6 @@ INSERT INTO sc.tb2 VALUES ('hello');
defer cleanupFn()

sqlDB.Exec(t, `
SET experimental_enable_user_defined_schemas = true;
CREATE DATABASE d;
USE d;
CREATE SCHEMA sc;
Expand Down Expand Up @@ -2044,8 +2037,6 @@ INSERT INTO sc.tb2 VALUES (1);
kvDB := tc.Server(0).DB()

sqlDB.Exec(t, `
SET experimental_enable_user_defined_schemas = true;
CREATE DATABASE d1;
USE d1;
CREATE SCHEMA sc1;
Expand Down Expand Up @@ -2104,8 +2095,6 @@ INSERT INTO sc4.tb VALUES (4);
defer cleanupFn()

sqlDB.Exec(t, `
SET experimental_enable_user_defined_schemas = true;
CREATE DATABASE d;
USE d;
CREATE SCHEMA sc;
Expand Down
2 changes: 0 additions & 2 deletions pkg/ccl/backupccl/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func TestShowBackup(t *testing.T) {
defer cleanupFn()
defer cleanupEmptyCluster()
sqlDB.Exec(t, `
SET experimental_enable_user_defined_schemas = true;
CREATE TYPE data.welcome AS ENUM ('hello', 'hi');
USE data; CREATE SCHEMA sc;
CREATE TABLE data.sc.t1 (a INT);
Expand Down
2 changes: 0 additions & 2 deletions pkg/ccl/importccl/import_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,6 @@ b STRING) CSV DATA (%s)`, testFiles.files[0])); err != nil {

t.Run("user-defined-schemas", func(t *testing.T) {
sqlDB.Exec(t, `CREATE DATABASE uds`)
sqlDB.Exec(t, `SET experimental_enable_user_defined_schemas = true`)
sqlDB.Exec(t, `USE uds`)
sqlDB.Exec(t, `CREATE SCHEMA sc`)
// Now import into a table under sc.
Expand Down Expand Up @@ -5475,7 +5474,6 @@ func TestImportAvro(t *testing.T) {
}

t.Run("user-defined-schemas", func(t *testing.T) {
sqlDB.Exec(t, `SET experimental_enable_user_defined_schemas = true`)
sqlDB.Exec(t, `CREATE SCHEMA myschema`)
sqlDB.Exec(t, `CREATE TABLE myschema.simple (i INT8 PRIMARY KEY, s text, b bytea)`)
sqlDB.Exec(t, `IMPORT INTO myschema.simple (i, s, b) AVRO DATA ($1)`, simpleOcf)
Expand Down
9 changes: 2 additions & 7 deletions pkg/cli/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,10 @@ func runDump(cmd *cobra.Command, args []string) error {
// Dump schema create statements, if any. If connecting to a cockroach version
// before 20.2 the list of schemas will be empty, so nothing will be emitted.
if shouldDumpSchemas && dumpCtx.dumpMode != dumpDataOnly {
if len(schemas) > 0 {
if _, err := fmt.Fprintf(w, "SET experimental_enable_user_defined_schemas = true;\n"); err != nil {
for _, schema := range schemas {
if _, err := fmt.Fprintf(w, "CREATE SCHEMA %s;\n\n", tree.Name(schema)); err != nil {
return err
}
for _, schema := range schemas {
if _, err := fmt.Fprintf(w, "CREATE SCHEMA %s;\n\n", tree.Name(schema)); err != nil {
return err
}
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/cli/testdata/dump/schemas
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sql
SET experimental_enable_user_defined_schemas = true;
CREATE DATABASE d;
USE d;

Expand All @@ -17,7 +16,6 @@ INSERT 1
dump d
----
----
SET experimental_enable_user_defined_schemas = true;
CREATE SCHEMA sc1;

CREATE SCHEMA sc2;
Expand Down
6 changes: 0 additions & 6 deletions pkg/sql/create_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ func (p *planner) createUserDefinedSchema(params runParams, n *tree.CreateSchema
clusterversion.VersionByKey(clusterversion.VersionUserDefinedSchemas))
}

// Check that creation of schemas is enabled.
if !p.EvalContext().SessionData.UserDefinedSchemasEnabled {
return pgerror.Newf(pgcode.FeatureNotSupported,
"session variable experimental_enable_user_defined_schemas is set to false, cannot create a schema")
}

// Create the ID.
id, err := catalogkv.GenerateUniqueDescID(params.ctx, p.ExecCfg().DB, p.ExecCfg().Codec)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func TestDatabaseHasChildSchemas(t *testing.T) {

// Create a database and schema.
if _, err := sqlDB.Exec(`
SET experimental_enable_user_defined_schemas = true;
CREATE DATABASE d;
USE d;
CREATE SCHEMA sc;
Expand Down
10 changes: 0 additions & 10 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,6 @@ var hashShardedIndexesEnabledClusterMode = settings.RegisterBoolSetting(
false,
)

var userDefinedSchemasClusterMode = settings.RegisterBoolSetting(
"sql.defaults.experimental_user_defined_schemas.enabled",
"default value for experimental_enable_user_defined_schemas; allows for creation of user defined schemas",
false,
)

var zigzagJoinClusterMode = settings.RegisterBoolSetting(
"sql.defaults.zigzag_join.enabled",
"default value for enable_zigzag_join session setting; allows use of zig-zag join by default",
Expand Down Expand Up @@ -2056,10 +2050,6 @@ func (m *sessionDataMutator) SetZigzagJoinEnabled(val bool) {
m.data.ZigzagJoinEnabled = val
}

func (m *sessionDataMutator) SetUserDefinedSchemasEnabled(val bool) {
m.data.UserDefinedSchemasEnabled = val
}

func (m *sessionDataMutator) SetExperimentalDistSQLPlanning(
val sessiondata.ExperimentalDistSQLPlanningMode,
) {
Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/alter_schema_owner
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
statement ok
SET experimental_enable_user_defined_schemas = true

statement ok
CREATE SCHEMA s

Expand Down
6 changes: 0 additions & 6 deletions pkg/sql/logictest/testdata/logic_test/alter_table_owner
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ ALTER TABLE t OWNER TO testuser

user testuser

statement ok
SET experimental_enable_user_defined_schemas = true

statement ok
CREATE SCHEMA s

Expand Down Expand Up @@ -124,9 +121,6 @@ REVOKE testuser FROM root

user testuser

statement ok
SET experimental_enable_user_defined_schemas = true

statement ok
CREATE SCHEMA s2

Expand Down
6 changes: 0 additions & 6 deletions pkg/sql/logictest/testdata/logic_test/alter_type_owner
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ ALTER TYPE typ OWNER TO testuser

user testuser

statement ok
SET experimental_enable_user_defined_schemas = true

statement ok
CREATE SCHEMA s

Expand Down Expand Up @@ -102,9 +99,6 @@ REVOKE testuser FROM root

user testuser

statement ok
SET experimental_enable_user_defined_schemas = true

statement ok
CREATE SCHEMA s2

Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/drop_table
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ SELECT * FROM a

user testuser

statement ok
SET experimental_enable_user_defined_schemas = true

statement ok
CREATE SCHEMA s

Expand Down
1 change: 0 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/enums
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,6 @@ public int Z|S of int
public notbad dup|DUP

statement ok
SET experimental_enable_user_defined_schemas = true;
CREATE SCHEMA uds;
CREATE TYPE uds.typ AS ENUM ('schema')

Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,6 @@ enable_zigzag_join on NULL NUL
experimental_distsql_planning off NULL NULL NULL string
experimental_enable_hash_sharded_indexes off NULL NULL NULL string
experimental_enable_temp_tables off NULL NULL NULL string
experimental_enable_user_defined_schemas off NULL NULL NULL string
extra_float_digits 0 NULL NULL NULL string
force_savepoint_restart off NULL NULL NULL string
foreign_key_cascades_limit 10000 NULL NULL NULL string
Expand Down Expand Up @@ -1900,7 +1899,6 @@ enable_zigzag_join on NULL user
experimental_distsql_planning off NULL user NULL off off
experimental_enable_hash_sharded_indexes off NULL user NULL off off
experimental_enable_temp_tables off NULL user NULL off off
experimental_enable_user_defined_schemas off NULL user NULL off off
extra_float_digits 0 NULL user NULL 0 2
force_savepoint_restart off NULL user NULL off off
foreign_key_cascades_limit 10000 NULL user NULL 10000 10000
Expand Down Expand Up @@ -1967,7 +1965,6 @@ enable_zigzag_join NULL NULL NULL NULL
experimental_distsql_planning NULL NULL NULL NULL NULL
experimental_enable_hash_sharded_indexes NULL NULL NULL NULL NULL
experimental_enable_temp_tables NULL NULL NULL NULL NULL
experimental_enable_user_defined_schemas NULL NULL NULL NULL NULL
extra_float_digits NULL NULL NULL NULL NULL
force_savepoint_restart NULL NULL NULL NULL NULL
foreign_key_cascades_limit NULL NULL NULL NULL NULL
Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/reparent_database
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
statement ok
SET experimental_enable_user_defined_schemas = true;

statement ok
CREATE DATABASE pgdatabase;
CREATE TABLE pgdatabase.t1 (x INT PRIMARY KEY);
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/schema
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
statement ok
SET experimental_enable_user_defined_schemas = true;
SET experimental_enable_temp_tables = true;

statement ok
Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/set_schema
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
statement ok
SET experimental_enable_user_defined_schemas = true

statement ok
CREATE SCHEMA s1

Expand Down
1 change: 0 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ enable_zigzag_join on
experimental_distsql_planning off
experimental_enable_hash_sharded_indexes off
experimental_enable_temp_tables off
experimental_enable_user_defined_schemas off
extra_float_digits 0
force_savepoint_restart off
foreign_key_cascades_limit 10000
Expand Down
6 changes: 0 additions & 6 deletions pkg/sql/reparent_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ func (p *planner) ReparentDatabase(
clusterversion.VersionByKey(clusterversion.VersionUserDefinedSchemas))
}

// Check that creation of schemas is enabled.
if !p.EvalContext().SessionData.UserDefinedSchemasEnabled {
return nil, pgerror.Newf(pgcode.FeatureNotSupported,
"session variable experimental_enable_user_defined_schemas is set to false, cannot create a schema")
}

db, err := p.ResolveMutableDatabaseDescriptor(ctx, string(n.Name), true /* required */)
if err != nil {
return nil, err
Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/sessiondata/session_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ type SessionData struct {
// DistSQLMode indicates whether to run queries using the distributed
// execution engine.
DistSQLMode DistSQLExecMode
// UserDefinedSchemasEnabled indicates whether use of user defined schemas
// are allowed.
UserDefinedSchemasEnabled bool
// ExperimentalDistSQLPlanningMode indicates whether the experimental
// DistSQL planning driven by the optimizer is enabled.
ExperimentalDistSQLPlanningMode ExperimentalDistSQLPlanningMode
Expand Down
19 changes: 0 additions & 19 deletions pkg/sql/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,25 +448,6 @@ var varGen = map[string]sessionVar{
},
},

// CockroachDB extension.
`experimental_enable_user_defined_schemas`: {
GetStringVal: makePostgresBoolGetStringValFn(`experimental_enable_user_defined_schemas`),
Set: func(_ context.Context, m *sessionDataMutator, s string) error {
b, err := parseBoolVar(`experimental_enable_user_defined_schemas`, s)
if err != nil {
return err
}
m.SetUserDefinedSchemasEnabled(b)
return nil
},
Get: func(evalCtx *extendedEvalContext) string {
return formatBoolAsPostgresSetting(evalCtx.SessionData.UserDefinedSchemasEnabled)
},
GlobalDefault: func(sv *settings.Values) string {
return formatBoolAsPostgresSetting(userDefinedSchemasClusterMode.Get(sv))
},
},

// CockroachDB extension.
`enable_zigzag_join`: {
GetStringVal: makePostgresBoolGetStringValFn(`enable_zigzag_join`),
Expand Down

0 comments on commit 3f99874

Please sign in to comment.