From cc7a9af6c4d84493ffc3a5c6523abf268d34ee31 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Thu, 12 Apr 2018 18:07:27 +0200 Subject: [PATCH] sql: sanitize the "no current db" story Prior to this patch, CockroachdB made it excessively simple for client connections to not have any current database set. Also by design CockroachDB allows a connection to be opened with a non-existent database set as current. This in turn causes various problems related to name resolution and the `pg_catalog` schema. To understand these problems we can consider separately two groups of users, which have separate use cases: - newcomers to CockroachDB that don't have prior experience with SQL or PostgreSQL. These will not know about "databases" in any sense, and will use CockroachDB with default options. This includes using `cockroach sql` with no current database selected. These users have to be taught upfront that they need to "create a database" and "set the current database", which they may or may not (more likely not) be interested in. When these users then transition into writing apps, they will copy-paste the conn URL printed by `cockroach start` (which sets no current db) into some ORM or framework, and then will regretfully observe that their app fail in mysterious ways because the current db is not set (also see the next point). - users of existing applications or SQL drivers that have been developed to target PostgreSQL. These apps commonly contain code that: - connect to a database named "`postgres`" by default, and make this default hard(er) to customize. For example Ecto (Elixir ORM) doesn't make this configurable. (From the PostgreSQL docs: "After initialization, a database cluster will contain a database named `postgres`, which is meant as a default database for use by utilities, users and third party applications. The database server itself does not require the postgres database to exist, but many external utility programs assume it exists.") - (regardless of which db is selected as current), will issue some introspection queries using `pg_catalog` before any additional initialization is made by the higher-level app code, in particular before the app can issue `CREATE DATABASE`. Currently `pg_catalog` queries (and several other things) fail if the current database is unset or set to a non-existing database. To address this relatively large class of problems, this patch modifies CockroachDB as follows: - all clusters (existing or new) now get two empty databases on startup (created by a migration) called `defaultdb` and `postgres`. - when a client doesn't specify a current db in their conn string (i.e. in the pgwire options), the `defaultdb` database is picked up instead. This resolves all the known problems around the situations identified above. The two new databases behave like any regular database and are provided for convenience to newcomers and compatibility. (Administrators are free to drop them afterwards to restore the previous situation, if that is actively desired.) In addition, to make it slightly harder for newcomers to shoot themselves in the foot, the `database` session variable cannot be set to the empty string any more if `sql_safe_updates` is otherwise set. Three alternatives to this approach were considered, discussed with @jordanlewis and @nvanbenschoten in their quality of pg compatibility experts, and with @bdarnell in his quality of carer for newcomers, and ultimately rejected: A) generate the current db upon connection if it does not exist, make connections using the empty string as curdb use `system` instead. Rejected because we don't like to auto-create upon connection. Too easy to flood the system with bogus database names by typos in the connection string. B) Pre-populate clusters with a special anonymous database (db name = empty string). Rejected because there are too many areas in CockroachDB with a risk to fail silently or with weird error messages as a result. Also does not solve the problem of clients that want a db called `postgres`. C) Auto-create a database named after the user upon user creation (with an optional flag to skip db creation). Rejected because it does not solve the problem of clients that want a db called `postgres`. @bdarnell: creating a database per user also implicitly encourages bad habits (like sharing certs for the user whose name corresponds to the database instead of creating multiple users). D) Implement some magic in the handling of `pg_catalog`, name resolution and all other pieces that currently don't like non-existent `database` values to create the appearance of something that works. Rejected because too complex to implement successfully (there are many moving parts that need to be touched to make this work) and the resulting magic would be hard to understand by CockroachDB contributors and hard to maintain over time. E) Auto-create only one database called `defaultdb`. Rejected because it does not solve the problem of clients that want a db called `postgres`. F) Auto-create only one database called `postgres` and use that as default when no current db is specified. Rejected because not good for branding. G) Name the `defaultdb` either `def`, `default` or `default_database`. The word "`default`" was rejected because it is a SQL keyword and would cause queries using it to fail in obscure ways. The word "`def`" (similar to what MySQL uses in `information_schema`) was rejected because it refers too strongly to other uses of this word in programming languages ("define"). "`default_database`" was rejected because too verbose. Release note (sql change): new and existing clusters will now contain two empty databases called `defaultdb` and `postgres` by default. The database `defaultdb` is automatically used for clients that connect without a current database set (e.g. without a database component in the connection URL). The database `postgres` is provided for compatibility with PostgreSQL client frameworks that require it to exist when the database server has ben freshly installed. Both new databases behave like any other regular database. Release note (general change): existing clusters upgraded to this version of CockroachDB will automatically see two new empty databases named `defaultdb` and `postgres`. These were added for compatibility with PostgreSQL and to ease adoption of CockroachDB. They can be manually deleted by an administrator if the client applications are determined not to require them. Co-authored-by: Nikhil Benesch --- pkg/ccl/backupccl/backup_test.go | 4 +- pkg/ccl/importccl/import_stmt.go | 2 +- .../testdata/logic_test/crdb_internal | 20 +- pkg/ccl/partitionccl/partition_test.go | 2 +- pkg/ccl/partitionccl/zone_test.go | 16 +- pkg/ccl/storageccl/bench_test.go | 6 +- pkg/cli/cli_test.go | 8 +- .../test_contextual_help.tcl | 6 - pkg/cli/interactive_tests/test_local_cmds.tcl | 2 +- pkg/cli/interactive_tests/test_txn_prompt.tcl | 7 +- pkg/cli/sql.go | 12 +- pkg/config/system_test.go | 6 +- pkg/keys/constants.go | 11 +- pkg/server/admin_test.go | 4 +- pkg/server/testserver.go | 26 +- pkg/sql/conn_executor.go | 6 +- pkg/sql/conn_executor_test.go | 2 +- pkg/sql/create_test.go | 2 +- pkg/sql/distsqlrun/cluster_test.go | 2 +- pkg/sql/drop_test.go | 4 +- .../testdata/logic_test/crdb_internal | 8 +- .../testdata/logic_test/dangerous_statements | 3 + .../logictest/testdata/logic_test/database | 6 + .../testdata/logic_test/deep_interleaving | 8 +- .../testdata/logic_test/dependencies | 136 ++-- .../testdata/logic_test/drop_database | 25 +- .../logictest/testdata/logic_test/event_log | 68 +- pkg/sql/logictest/testdata/logic_test/explain | 4 +- .../logictest/testdata/logic_test/grant_table | 728 ++++++------------ .../testdata/logic_test/information_schema | 2 + .../logictest/testdata/logic_test/interleaved | 2 +- .../testdata/logic_test/interleaved_join | 124 +-- pkg/sql/logictest/testdata/logic_test/join | 2 +- .../logictest/testdata/logic_test/pg_catalog | 288 +++---- .../logictest/testdata/logic_test/pgoidtype | 10 +- pkg/sql/logictest/testdata/logic_test/ranges | 70 +- .../testdata/logic_test/rename_database | 11 + .../testdata/logic_test/select_tighten_spans | 18 +- .../logictest/testdata/logic_test/sequences | 2 +- .../logictest/testdata/logic_test/show_source | 2 + .../logictest/testdata/logic_test/show_trace | 150 ++-- pkg/sql/logictest/testdata/logic_test/system | 16 +- pkg/sql/pgwire/pgwire_test.go | 4 +- pkg/sql/rename_test.go | 3 +- pkg/sql/schema_changer_test.go | 5 +- pkg/sql/sessiondata/search_path.go | 9 +- pkg/sql/sqlbase/metadata.go | 2 +- pkg/sql/sqlbase/privilege_test.go | 4 +- pkg/sql/sqlbase/structured.go | 2 +- pkg/sql/sqlbase/structured_test.go | 8 +- pkg/sql/tests/split_test.go | 2 +- pkg/sql/tests/system_table_test.go | 2 +- pkg/sql/txn_restart_test.go | 2 +- pkg/sql/vars.go | 6 +- pkg/sql/zone_config_test.go | 5 +- pkg/sql/zone_test.go | 7 +- pkg/sqlmigrations/migrations.go | 77 +- pkg/sqlmigrations/migrations_test.go | 4 + pkg/storage/client_split_test.go | 22 +- pkg/storage/engine/mvcc_test.go | 4 +- pkg/storage/replicate_queue_test.go | 2 +- pkg/storage/store_test.go | 2 +- 62 files changed, 957 insertions(+), 1046 deletions(-) diff --git a/pkg/ccl/backupccl/backup_test.go b/pkg/ccl/backupccl/backup_test.go index e837e79202bd..4ea5bbd60268 100644 --- a/pkg/ccl/backupccl/backup_test.go +++ b/pkg/ccl/backupccl/backup_test.go @@ -1970,7 +1970,7 @@ func TestRestoreAsOfSystemTimeGCBounds(t *testing.T) { gcr := roachpb.GCRequest{ // Bogus span to make it a valid request. Span: roachpb.Span{ - Key: keys.MakeTablePrefix(keys.MaxReservedDescID + 1), + Key: keys.MakeTablePrefix(keys.MinUserDescID), EndKey: keys.MaxKey, }, Threshold: tc.Server(0).Clock().Now(), @@ -2857,7 +2857,7 @@ func TestBackupRestoreSequence(t *testing.T) { if _, err := newDB.DB.Exec( `RESTORE TABLE t FROM $1`, localFoo, - ); !testutils.IsError(err, "pq: cannot restore table \"t\" without referenced sequence 52 \\(or \"skip_missing_sequences\" option\\)") { + ); !testutils.IsError(err, "pq: cannot restore table \"t\" without referenced sequence 54 \\(or \"skip_missing_sequences\" option\\)") { t.Fatal(err) } diff --git a/pkg/ccl/importccl/import_stmt.go b/pkg/ccl/importccl/import_stmt.go index fd7b5e5f7f3f..7f1577b803cc 100644 --- a/pkg/ccl/importccl/import_stmt.go +++ b/pkg/ccl/importccl/import_stmt.go @@ -70,7 +70,7 @@ const ( // We need to choose arbitrary database and table IDs. These aren't important, // but they do match what would happen when creating a new database and // table on an empty cluster. - defaultCSVParentID sqlbase.ID = keys.MaxReservedDescID + 1 + defaultCSVParentID sqlbase.ID = keys.MinNonPredefinedUserDescID defaultCSVTableID sqlbase.ID = defaultCSVParentID + 1 ) diff --git a/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal b/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal index f15cda324af9..9a78d5d36380 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal +++ b/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal @@ -36,13 +36,13 @@ CREATE table t2 (a STRING PRIMARY KEY) PARTITION BY LIST (a) ( query IITTI SELECT * FROM crdb_internal.partitions ORDER BY table_id, index_id, name ---- -51 1 NULL p12 1 -51 1 p12 p12p3 1 -51 1 p12p3 p12p3p8 1 -51 1 NULL p6 1 -51 1 p6 p6p7 1 -51 1 p6 p6p8 1 -51 1 p6 p6px 1 -51 1 p12 pd 1 -51 2 NULL p00 2 -52 1 NULL pfoo 1 +53 1 NULL p12 1 +53 1 p12 p12p3 1 +53 1 p12p3 p12p3p8 1 +53 1 NULL p6 1 +53 1 p6 p6p7 1 +53 1 p6 p6p8 1 +53 1 p6 p6px 1 +53 1 p12 pd 1 +53 2 NULL p00 2 +54 1 NULL pfoo 1 diff --git a/pkg/ccl/partitionccl/partition_test.go b/pkg/ccl/partitionccl/partition_test.go index 78af511b5788..955023454d93 100644 --- a/pkg/ccl/partitionccl/partition_test.go +++ b/pkg/ccl/partitionccl/partition_test.go @@ -123,7 +123,7 @@ func (t *partitioningTest) parse() error { return errors.Errorf("expected *tree.CreateTable got %T", stmt) } st := cluster.MakeTestingClusterSettings() - const parentID, tableID = keys.MaxReservedDescID + 1, keys.MaxReservedDescID + 2 + const parentID, tableID = keys.MinUserDescID, keys.MinUserDescID + 1 t.parsed.tableDesc, err = importccl.MakeSimpleTableDescriptor( ctx, st, createTable, parentID, tableID, hlc.UnixNano()) if err != nil { diff --git a/pkg/ccl/partitionccl/zone_test.go b/pkg/ccl/partitionccl/zone_test.go index 37e5fbb6cff8..3785557fea2a 100644 --- a/pkg/ccl/partitionccl/zone_test.go +++ b/pkg/ccl/partitionccl/zone_test.go @@ -48,6 +48,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) { zoneOverride := config.DefaultZoneConfig() zoneOverride.GC.TTLSeconds = 42 + dbDescID := uint32(keys.MinNonPredefinedUserDescID) + defaultRow := sqlutils.ZoneRow{ ID: keys.RootNamespaceID, CLISpecifier: ".default", @@ -59,27 +61,27 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) { Config: zoneOverride, } dbRow := sqlutils.ZoneRow{ - ID: keys.MaxReservedDescID + 1, + ID: dbDescID, CLISpecifier: "d", Config: zoneOverride, } tableRow := sqlutils.ZoneRow{ - ID: keys.MaxReservedDescID + 2, + ID: dbDescID + 1, CLISpecifier: "d.t", Config: zoneOverride, } primaryRow := sqlutils.ZoneRow{ - ID: keys.MaxReservedDescID + 2, + ID: dbDescID + 1, CLISpecifier: "d.t@primary", Config: zoneOverride, } p0Row := sqlutils.ZoneRow{ - ID: keys.MaxReservedDescID + 2, + ID: dbDescID + 1, CLISpecifier: "d.t.p0", Config: zoneOverride, } p1Row := sqlutils.ZoneRow{ - ID: keys.MaxReservedDescID + 2, + ID: dbDescID + 1, CLISpecifier: "d.t.p1", Config: zoneOverride, } @@ -220,11 +222,11 @@ func TestInvalidIndexPartitionSetShowZones(t *testing.T) { }{ { "ALTER INDEX foo EXPERIMENTAL CONFIGURE ZONE ''", - `no schema has been selected to search index: "foo"`, + `index "foo" does not exist`, }, { "EXPERIMENTAL SHOW ZONE CONFIGURATION FOR INDEX foo", - `no schema has been selected to search index: "foo"`, + `index "foo" does not exist`, }, { "USE system; ALTER INDEX foo EXPERIMENTAL CONFIGURE ZONE ''", diff --git a/pkg/ccl/storageccl/bench_test.go b/pkg/ccl/storageccl/bench_test.go index 4ebd96cb74b6..b7e4ce08bf2e 100644 --- a/pkg/ccl/storageccl/bench_test.go +++ b/pkg/ccl/storageccl/bench_test.go @@ -47,7 +47,7 @@ func BenchmarkAddSSTable(b *testing.B) { defer tc.Stopper().Stop(ctx) kvDB := tc.Server(0).DB() - id := sqlbase.ID(keys.MaxReservedDescID + 1) + id := sqlbase.ID(keys.MinUserDescID) var totalLen int64 b.StopTimer() @@ -105,7 +105,7 @@ func BenchmarkWriteBatch(b *testing.B) { defer tc.Stopper().Stop(ctx) kvDB := tc.Server(0).DB() - id := sqlbase.ID(keys.MaxReservedDescID + 1) + id := sqlbase.ID(keys.MinUserDescID) var batch engine.RocksDBBatchBuilder var totalLen int64 @@ -161,7 +161,7 @@ func BenchmarkImport(b *testing.B) { defer tc.Stopper().Stop(ctx) kvDB := tc.Server(0).DB() - id := sqlbase.ID(keys.MaxReservedDescID + 1) + id := sqlbase.ID(keys.MinUserDescID) var totalLen int64 b.StopTimer() diff --git a/pkg/cli/cli_test.go b/pkg/cli/cli_test.go index a5b600d76140..bdc4cb267e59 100644 --- a/pkg/cli/cli_test.go +++ b/pkg/cli/cli_test.go @@ -749,6 +749,8 @@ func Example_sql() { // 42 69 // sql --execute=show databases // Database + // defaultdb + // postgres // system // t // sql -e select 1; select 2 @@ -2001,7 +2003,7 @@ func checkNodeStatus(t *testing.T, c cliTest, output string, start time.Time) { testcases = append(testcases, testCase{"leader_ranges", baseIdx, 3}, testCase{"leaseholder_ranges", baseIdx + 1, 3}, - testCase{"ranges", baseIdx + 2, 20}, + testCase{"ranges", baseIdx + 2, 22}, testCase{"unavailable_ranges", baseIdx + 3, 1}, testCase{"underreplicated_ranges", baseIdx + 4, 1}, ) @@ -2239,6 +2241,10 @@ writing ` + os.DevNull + ` debug/nodes/1/ranges/18 debug/nodes/1/ranges/19 debug/nodes/1/ranges/20 + debug/nodes/1/ranges/21 + debug/nodes/1/ranges/22 + debug/schema/defaultdb@details + debug/schema/postgres@details debug/schema/system@details debug/schema/system/descriptor debug/schema/system/eventlog diff --git a/pkg/cli/interactive_tests/test_contextual_help.tcl b/pkg/cli/interactive_tests/test_contextual_help.tcl index 1d5b2e8d99e9..6edd100f5e63 100644 --- a/pkg/cli/interactive_tests/test_contextual_help.tcl +++ b/pkg/cli/interactive_tests/test_contextual_help.tcl @@ -6,12 +6,6 @@ start_server $argv spawn $argv sql -start_test "Check that a client without a current database suggests to use SET." -eexpect "warning: no current database set" -eexpect "SET database" -eexpect root@ -end_test - start_test "Check that a syntax error can make suggestions." send "select * from;\r" eexpect "syntax error" diff --git a/pkg/cli/interactive_tests/test_local_cmds.tcl b/pkg/cli/interactive_tests/test_local_cmds.tcl index 5374eed8dfaf..984a5ce75800 100644 --- a/pkg/cli/interactive_tests/test_local_cmds.tcl +++ b/pkg/cli/interactive_tests/test_local_cmds.tcl @@ -107,7 +107,7 @@ expect { } root@ {} } -eexpect "/> " +eexpect "/defaultdb> " # restore send "\\set show_times\r" end_test diff --git a/pkg/cli/interactive_tests/test_txn_prompt.tcl b/pkg/cli/interactive_tests/test_txn_prompt.tcl index 753913acbf42..2968b6a12440 100644 --- a/pkg/cli/interactive_tests/test_txn_prompt.tcl +++ b/pkg/cli/interactive_tests/test_txn_prompt.tcl @@ -47,10 +47,15 @@ send "SET DATABASE = testdb;\r" eexpect "\nSET\r\n" eexpect root@ eexpect "/testdb>" -send "SET DATABASE = '';\r" +send "SET sql_safe_updates = false;\r" +eexpect "\nSET\r\n" +send "SET database = '';\r" eexpect "\nSET\r\n" eexpect root@ eexpect "/>" +send "SET database = 'defaultdb';\r" +eexpect "\nSET\r\n" +eexpect root@ end_test start_test "Test that prompt becomes OPEN when txn is opened." diff --git a/pkg/cli/sql.go b/pkg/cli/sql.go index e721f4389229..b1b9d1201b29 100644 --- a/pkg/cli/sql.go +++ b/pkg/cli/sql.go @@ -549,6 +549,12 @@ func (c *cliState) refreshDatabaseName() (string, bool) { return "", false } + if dbVal == "" { + // Attempt to be helpful to new users. + fmt.Fprintln(stderr, "warning: no current database set."+ + " Use SET database = to change, CREATE DATABASE to make a new database.") + } + dbName := formatVal(dbVal.(string), false /* showPrintableUnicode */, false /* shownewLinesAndTabs */) @@ -570,12 +576,6 @@ func preparePrompts(dbURL string) (promptPrefix, fullPrompt, continuePrompt stri username = parsedURL.User.Username() } promptPrefix = fmt.Sprintf("%s@%s", username, parsedURL.Host) - - if parsedURL.Path == "" { - // Attempt to be helpful to new users. - fmt.Fprintln(stderr, "warning: no current database set."+ - " Use SET database = to change, CREATE DATABASE to make a new database.") - } } if len(promptPrefix) == 0 { diff --git a/pkg/config/system_test.go b/pkg/config/system_test.go index c2ee2245baf1..b817a1dbb022 100644 --- a/pkg/config/system_test.go +++ b/pkg/config/system_test.go @@ -274,7 +274,7 @@ func TestComputeSplitKeyTableIDs(t *testing.T) { defer leaktest.AfterTest(t)() const ( - start = keys.MaxReservedDescID + 1 + start = keys.MinUserDescID reservedStart = keys.MaxSystemConfigDescID + 1 ) @@ -401,8 +401,8 @@ func TestGetZoneConfigForKey(t *testing.T) { {tkey(keys.LeaseTableID), keys.SystemDatabaseID}, {tkey(keys.JobsTableID), keys.SystemDatabaseID}, {tkey(keys.LocationsTableID), keys.SystemDatabaseID}, - {tkey(keys.MaxReservedDescID + 1), keys.MaxReservedDescID + 1}, - {tkey(keys.MaxReservedDescID + 23), keys.MaxReservedDescID + 23}, + {tkey(keys.MinUserDescID), keys.MinUserDescID}, + {tkey(keys.MinUserDescID + 22), keys.MinUserDescID + 22}, {roachpb.RKeyMax, keys.RootNamespaceID}, } diff --git a/pkg/keys/constants.go b/pkg/keys/constants.go index c1ab2adce75c..b7955176657d 100644 --- a/pkg/keys/constants.go +++ b/pkg/keys/constants.go @@ -256,7 +256,7 @@ var ( SystemConfigTableDataMax = roachpb.Key(MakeTablePrefix(MaxSystemConfigDescID + 1)) // UserTableDataMin is the start key of user structured data. - UserTableDataMin = roachpb.Key(MakeTablePrefix(MaxReservedDescID + 1)) + UserTableDataMin = roachpb.Key(MakeTablePrefix(MinUserDescID)) // MaxKey is the infinity marker which is larger than any other key. MaxKey = roachpb.KeyMax @@ -277,6 +277,15 @@ const ( // cockroach. MaxReservedDescID = 49 + // MinUserDescID is the first descriptor ID available for user + // structured data. + MinUserDescID = MaxReservedDescID + 1 + + // MinNonPredefinedUserDescID is the first descriptor ID used by + // user-level objects that are not created automatically on empty + // clusters (default databases). + MinNonPredefinedUserDescID = MinUserDescID + 2 + // VirtualDescriptorID is the ID used by all virtual descriptors. VirtualDescriptorID = math.MaxUint32 diff --git a/pkg/server/admin_test.go b/pkg/server/admin_test.go index c72c208a1efa..50651ab46536 100644 --- a/pkg/server/admin_test.go +++ b/pkg/server/admin_test.go @@ -248,7 +248,7 @@ func TestAdminAPIDatabases(t *testing.T) { t.Fatal(err) } - expectedDBs := []string{"system", testdb} + expectedDBs := []string{"defaultdb", "postgres", "system", testdb} if a, e := len(resp.Databases), len(expectedDBs); a != e { t.Fatalf("length of result %d != expected %d", a, e) } @@ -689,7 +689,7 @@ func TestAdminAPIEvents(t *testing.T) { {sql.EventLogNodeJoin, false, 0, 1}, {sql.EventLogNodeRestart, false, 0, 0}, {sql.EventLogDropDatabase, false, 0, 0}, - {sql.EventLogCreateDatabase, false, 0, 1}, + {sql.EventLogCreateDatabase, false, 0, 3}, {sql.EventLogDropTable, false, 0, 2}, {sql.EventLogCreateTable, false, 0, 3}, {sql.EventLogSetClusterSetting, false, 0, 5}, diff --git a/pkg/server/testserver.go b/pkg/server/testserver.go index 4a8828145b6e..c0772f7536d4 100644 --- a/pkg/server/testserver.go +++ b/pkg/server/testserver.go @@ -373,16 +373,32 @@ func ExpectedInitialRangeCount(db *client.DB) (int, error) { if err != nil { return 0, err } - maxDescriptorID := descriptorIDs[len(descriptorIDs)-1] // System table splits occur at every possible table boundary between the end // of the system config ID space (keys.MaxSystemConfigDescID) and the system - // table with the maximum ID (maxDescriptorID), even when an ID within the - // span does not have an associated descriptor. - systemTableSplits := int(maxDescriptorID - keys.MaxSystemConfigDescID) + // table with the maximum ID (maxSystemDescriptorID), even when an ID within + // the span does not have an associated descriptor. + maxSystemDescriptorID := descriptorIDs[0] + for _, descID := range descriptorIDs { + if descID > maxSystemDescriptorID && descID <= keys.MaxReservedDescID { + maxSystemDescriptorID = descID + } + } + systemTableSplits := int(maxSystemDescriptorID - keys.MaxSystemConfigDescID) + + // User table splits are analogous to system table splits: they occur at every + // possible table boundary between the end of the system ID space + // (keys.MaxReservedDescID) and the user table with the maximum ID + // (maxUserDescriptorID), even when an ID within the span does not have an + // associated descriptor. + maxUserDescriptorID := descriptorIDs[len(descriptorIDs)-1] + userTableSplits := 0 + if maxUserDescriptorID >= keys.MaxReservedDescID { + userTableSplits = int(maxUserDescriptorID - keys.MaxReservedDescID) + } // `n` splits create `n+1` ranges. - return len(config.StaticSplits()) + systemTableSplits + 1, nil + return len(config.StaticSplits()) + systemTableSplits + userTableSplits + 1, nil } // WaitForInitialSplits waits for the server to complete its expected initial diff --git a/pkg/sql/conn_executor.go b/pkg/sql/conn_executor.go index d91f4ea3234f..b7e17d9da8e3 100644 --- a/pkg/sql/conn_executor.go +++ b/pkg/sql/conn_executor.go @@ -421,9 +421,13 @@ func (sp sessionParams) sessionData( if sp.data != nil { return *sp.data } + curDb := sp.args.Database + if curDb == "" { + curDb = sessiondata.DefaultDatabaseName + } sd := sessiondata.SessionData{ ApplicationName: sp.args.ApplicationName, - Database: sp.args.Database, + Database: curDb, DistSQLMode: sessiondata.DistSQLExecMode(DistSQLClusterExecMode.Get(&settings.SV)), SearchPath: sqlbase.DefaultSearchPath, Location: time.UTC, diff --git a/pkg/sql/conn_executor_test.go b/pkg/sql/conn_executor_test.go index f17aad81dcea..010bb5e88fd1 100644 --- a/pkg/sql/conn_executor_test.go +++ b/pkg/sql/conn_executor_test.go @@ -284,7 +284,7 @@ func TestNonRetriableErrorOnAutoCommit(t *testing.T) { func TestErrorOnRollback(t *testing.T) { defer leaktest.AfterTest(t)() - const targetKeyString string = "/Table/51/1/1/0" + const targetKeyString string = "/Table/53/1/1/0" var injectedErr int64 // We're going to inject an error into our EndTransaction. diff --git a/pkg/sql/create_test.go b/pkg/sql/create_test.go index 33286076590b..3f92811d448b 100644 --- a/pkg/sql/create_test.go +++ b/pkg/sql/create_test.go @@ -43,7 +43,7 @@ func TestDatabaseDescriptor(t *testing.T) { defer s.Stopper().Stop(context.TODO()) ctx := context.TODO() - expectedCounter := int64(keys.MaxReservedDescID + 1) + expectedCounter := int64(keys.MinNonPredefinedUserDescID) // Test values before creating the database. // descriptor ID counter. diff --git a/pkg/sql/distsqlrun/cluster_test.go b/pkg/sql/distsqlrun/cluster_test.go index 31f07a853fd1..40ec8b2cd597 100644 --- a/pkg/sql/distsqlrun/cluster_test.go +++ b/pkg/sql/distsqlrun/cluster_test.go @@ -536,7 +536,7 @@ func TestDistSQLReadsFillGatewayID(t *testing.T) { if !ok { return nil } - if !strings.HasPrefix(scanReq.Span.Key.String(), "/Table/51/1") { + if !strings.HasPrefix(scanReq.Span.Key.String(), "/Table/53/1") { return nil } diff --git a/pkg/sql/drop_test.go b/pkg/sql/drop_test.go index 4f077a67b587..1a2dbd1f4c21 100644 --- a/pkg/sql/drop_test.go +++ b/pkg/sql/drop_test.go @@ -501,7 +501,7 @@ func TestDropTable(t *testing.T) { } tableDesc := sqlbase.GetTableDescriptor(kvDB, "t", "kv") - nameKey := sqlbase.MakeNameMetadataKey(keys.MaxReservedDescID+1, "kv") + nameKey := sqlbase.MakeNameMetadataKey(keys.MinNonPredefinedUserDescID, "kv") gr, err := kvDB.Get(ctx, nameKey) if err != nil { @@ -590,7 +590,7 @@ func TestDropTableDeleteData(t *testing.T) { descs = append(descs, sqlbase.GetTableDescriptor(kvDB, "t", tableName)) - nameKey := sqlbase.MakeNameMetadataKey(keys.MaxReservedDescID+1, tableName) + nameKey := sqlbase.MakeNameMetadataKey(keys.MinNonPredefinedUserDescID, tableName) gr, err := kvDB.Get(ctx, nameKey) if err != nil { t.Fatal(err) diff --git a/pkg/sql/logictest/testdata/logic_test/crdb_internal b/pkg/sql/logictest/testdata/logic_test/crdb_internal index 4e8ecb6b501c..60666691c4c3 100644 --- a/pkg/sql/logictest/testdata/logic_test/crdb_internal +++ b/pkg/sql/logictest/testdata/logic_test/crdb_internal @@ -202,8 +202,8 @@ statement ok INSERT INTO system.zones (id, config) VALUES (17, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)), (18, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)), - (51, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)), - (52, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)) + (53, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)), + (54, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)) query IT SELECT id, cli_specifier FROM crdb_internal.zones ORDER BY id @@ -214,8 +214,8 @@ SELECT id, cli_specifier FROM crdb_internal.zones ORDER BY id 17 .system 18 .timeseries 22 .liveness -51 testdb -52 testdb.foo +53 testdb +54 testdb.foo query error pq: foo SELECT crdb_internal.force_error('', 'foo') diff --git a/pkg/sql/logictest/testdata/logic_test/dangerous_statements b/pkg/sql/logictest/testdata/logic_test/dangerous_statements index 2c7506a289a4..cd997de02d5b 100644 --- a/pkg/sql/logictest/testdata/logic_test/dangerous_statements +++ b/pkg/sql/logictest/testdata/logic_test/dangerous_statements @@ -14,3 +14,6 @@ DELETE FROM foo statement error rejected: ALTER TABLE DROP COLUMN ALTER TABLE foo DROP COLUMN x + +statement error rejected: SET database to empty string +SET database = '' diff --git a/pkg/sql/logictest/testdata/logic_test/database b/pkg/sql/logictest/testdata/logic_test/database index 56c4c2d1ae41..6443464c6fb9 100644 --- a/pkg/sql/logictest/testdata/logic_test/database +++ b/pkg/sql/logictest/testdata/logic_test/database @@ -17,6 +17,8 @@ SHOW DATABASES ---- Database a +defaultdb +postgres system test @@ -85,6 +87,8 @@ b4 b5 b6 c +defaultdb +postgres system test @@ -132,6 +136,8 @@ SHOW DATABASES Database a c +defaultdb +postgres system test diff --git a/pkg/sql/logictest/testdata/logic_test/deep_interleaving b/pkg/sql/logictest/testdata/logic_test/deep_interleaving index f9bb073b59c0..f13fd2966b09 100644 --- a/pkg/sql/logictest/testdata/logic_test/deep_interleaving +++ b/pkg/sql/logictest/testdata/logic_test/deep_interleaving @@ -111,7 +111,7 @@ EXPLAIN SELECT * FROM level4 WHERE k1 > 1 AND k1 < 3 ---- scan · · · table level4@primary -· spans /2/#/52/1/#/53/1-/2/#/52/1/#/53/2 +· spans /2/#/54/1/#/55/1-/2/#/54/1/#/55/2 query III rowsort SELECT * FROM level4 WHERE k1 > 1 AND k1 < 3 @@ -131,7 +131,7 @@ EXPLAIN SELECT * FROM level4 WHERE k1 = 2 AND k2 > 10 AND k2 < 30 ---- scan · · · table level4@primary -· spans /2/#/52/1/#/53/1/11-/2/#/52/1/#/53/1/30 +· spans /2/#/54/1/#/55/1/11-/2/#/54/1/#/55/1/30 query III rowsort SELECT * FROM level4 WHERE k1 = 2 AND k2 > 10 AND k2 < 30 @@ -145,7 +145,7 @@ EXPLAIN SELECT * FROM level4 WHERE k1 = 2 AND k2 = 20 AND k3 > 100 AND k3 < 300 ---- scan · · · table level4@primary -· spans /2/#/52/1/#/53/1/20/101/#/54/1-/2/#/52/1/#/53/1/20/299/#/54/1/# +· spans /2/#/54/1/#/55/1/20/101/#/56/1-/2/#/54/1/#/55/1/20/299/#/56/1/# query III SELECT * FROM level4 WHERE k1 = 2 AND k2 = 20 AND k3 > 100 AND k3 < 300 @@ -157,7 +157,7 @@ EXPLAIN SELECT * FROM level4 WHERE k1 = 2 AND k2 = 20 AND k3 = 200 ---- scan · · · table level4@primary -· spans /2/#/52/1/#/53/1/20/200/#/54/1-/2/#/52/1/#/53/1/20/200/#/54/1/# +· spans /2/#/54/1/#/55/1/20/200/#/56/1-/2/#/54/1/#/55/1/20/200/#/56/1/# query III SELECT * FROM level4 WHERE k1 = 2 AND k2 = 20 AND k3 = 200 diff --git a/pkg/sql/logictest/testdata/logic_test/dependencies b/pkg/sql/logictest/testdata/logic_test/dependencies index e428898a4c6f..5a912bd02da3 100644 --- a/pkg/sql/logictest/testdata/logic_test/dependencies +++ b/pkg/sql/logictest/testdata/logic_test/dependencies @@ -18,89 +18,89 @@ query ITITTBTB colnames SELECT * FROM crdb_internal.table_columns WHERE descriptor_name LIKE 'test_%' ORDER BY descriptor_id, column_id ---- descriptor_id descriptor_name column_id column_name column_type nullable default_expr hidden -51 test_kv 1 k semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false -51 test_kv 2 v semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false -51 test_kv 3 w semantic_type:DECIMAL width:0 precision:0 visible_type:NONE true NULL false -52 test_kvr1 1 k semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false -53 test_kvr2 1 k semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false -53 test_kvr2 2 v semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false -53 test_kvr2 3 rowid semantic_type:INT width:0 precision:0 visible_type:NONE false unique_rowid() true -54 test_kvr3 1 k semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false -54 test_kvr3 2 v semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false -54 test_kvr3 3 rowid semantic_type:INT width:0 precision:0 visible_type:NONE false unique_rowid() true -55 test_kvi1 1 k semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false -56 test_kvi2 1 k semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false -56 test_kvi2 2 v semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false -57 test_v1 1 v semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false -59 test_v2 1 v semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false +53 test_kv 1 k semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false +53 test_kv 2 v semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false +53 test_kv 3 w semantic_type:DECIMAL width:0 precision:0 visible_type:NONE true NULL false +54 test_kvr1 1 k semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false +55 test_kvr2 1 k semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false +55 test_kvr2 2 v semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false +55 test_kvr2 3 rowid semantic_type:INT width:0 precision:0 visible_type:NONE false unique_rowid() true +56 test_kvr3 1 k semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false +56 test_kvr3 2 v semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false +56 test_kvr3 3 rowid semantic_type:INT width:0 precision:0 visible_type:NONE false unique_rowid() true +57 test_kvi1 1 k semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false +58 test_kvi2 1 k semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false +58 test_kvi2 2 v semantic_type:INT width:0 precision:0 visible_type:NONE true NULL false +59 test_v1 1 v semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false +61 test_v2 1 v semantic_type:INT width:0 precision:0 visible_type:NONE false NULL false query ITITTB colnames SELECT * FROM crdb_internal.table_indexes WHERE descriptor_name LIKE 'test_%' ORDER BY descriptor_id, index_id ---- descriptor_id descriptor_name index_id index_name index_type is_unique -51 test_kv 1 primary primary true -51 test_kv 2 test_v_idx secondary true -51 test_kv 3 test_v_idx2 secondary false -51 test_kv 4 test_v_idx3 secondary false -52 test_kvr1 1 primary primary true -53 test_kvr2 1 primary primary true -53 test_kvr2 2 test_kvr2_v_key secondary true -54 test_kvr3 1 primary primary true -54 test_kvr3 2 test_kvr3_v_key secondary true -55 test_kvi1 1 primary primary true -56 test_kvi2 1 primary primary true -56 test_kvi2 2 test_kvi2_idx secondary true -57 test_v1 0 · primary false -59 test_v2 0 · primary false +53 test_kv 1 primary primary true +53 test_kv 2 test_v_idx secondary true +53 test_kv 3 test_v_idx2 secondary false +53 test_kv 4 test_v_idx3 secondary false +54 test_kvr1 1 primary primary true +55 test_kvr2 1 primary primary true +55 test_kvr2 2 test_kvr2_v_key secondary true +56 test_kvr3 1 primary primary true +56 test_kvr3 2 test_kvr3_v_key secondary true +57 test_kvi1 1 primary primary true +58 test_kvi2 1 primary primary true +58 test_kvi2 2 test_kvi2_idx secondary true +59 test_v1 0 · primary false +61 test_v2 0 · primary false query ITITTITT colnames SELECT * FROM crdb_internal.index_columns WHERE descriptor_name LIKE 'test_%' ORDER BY descriptor_id, index_id, column_type, column_id ---- descriptor_id descriptor_name index_id index_name column_type column_id column_name column_direction -51 test_kv 1 primary key 1 k ASC -51 test_kv 2 test_v_idx extra 1 NULL NULL -51 test_kv 2 test_v_idx key 2 v ASC -51 test_kv 3 test_v_idx2 extra 1 NULL NULL -51 test_kv 3 test_v_idx2 key 2 v DESC -51 test_kv 4 test_v_idx3 composite 3 NULL NULL -51 test_kv 4 test_v_idx3 extra 1 NULL NULL -51 test_kv 4 test_v_idx3 key 3 w ASC -51 test_kv 4 test_v_idx3 storing 2 NULL NULL -52 test_kvr1 1 primary key 1 k ASC -53 test_kvr2 1 primary key 3 rowid ASC -53 test_kvr2 2 test_kvr2_v_key extra 3 NULL NULL -53 test_kvr2 2 test_kvr2_v_key key 2 v ASC -54 test_kvr3 1 primary key 3 rowid ASC -54 test_kvr3 2 test_kvr3_v_key extra 3 NULL NULL -54 test_kvr3 2 test_kvr3_v_key key 2 v ASC -55 test_kvi1 1 primary key 1 k ASC -56 test_kvi2 1 primary key 1 k ASC -56 test_kvi2 2 test_kvi2_idx extra 1 NULL NULL -56 test_kvi2 2 test_kvi2_idx key 2 v ASC +53 test_kv 1 primary key 1 k ASC +53 test_kv 2 test_v_idx extra 1 NULL NULL +53 test_kv 2 test_v_idx key 2 v ASC +53 test_kv 3 test_v_idx2 extra 1 NULL NULL +53 test_kv 3 test_v_idx2 key 2 v DESC +53 test_kv 4 test_v_idx3 composite 3 NULL NULL +53 test_kv 4 test_v_idx3 extra 1 NULL NULL +53 test_kv 4 test_v_idx3 key 3 w ASC +53 test_kv 4 test_v_idx3 storing 2 NULL NULL +54 test_kvr1 1 primary key 1 k ASC +55 test_kvr2 1 primary key 3 rowid ASC +55 test_kvr2 2 test_kvr2_v_key extra 3 NULL NULL +55 test_kvr2 2 test_kvr2_v_key key 2 v ASC +56 test_kvr3 1 primary key 3 rowid ASC +56 test_kvr3 2 test_kvr3_v_key extra 3 NULL NULL +56 test_kvr3 2 test_kvr3_v_key key 2 v ASC +57 test_kvi1 1 primary key 1 k ASC +58 test_kvi2 1 primary key 1 k ASC +58 test_kvi2 2 test_kvi2_idx extra 1 NULL NULL +58 test_kvi2 2 test_kvi2_idx key 2 v ASC query ITIIITITT colnames SELECT * FROM crdb_internal.backward_dependencies WHERE descriptor_name LIKE 'test_%' ORDER BY descriptor_id, index_id, dependson_type, dependson_id, dependson_index_id ---- descriptor_id descriptor_name index_id column_id dependson_id dependson_type dependson_index_id dependson_name dependson_details -52 test_kvr1 1 NULL 51 fk 1 fk_k_ref_test_kv SharedPrefixLen: 1 -53 test_kvr2 2 NULL 51 fk 1 fk_v_ref_test_kv SharedPrefixLen: 1 -54 test_kvr3 2 NULL 51 fk 2 fk_v_ref_test_kv SharedPrefixLen: 1 -55 test_kvi1 1 NULL 51 interleave 1 NULL SharedPrefixLen: 1 -56 test_kvi2 2 NULL 51 interleave 1 NULL SharedPrefixLen: 1 -57 test_v1 NULL NULL 51 view NULL NULL NULL -59 test_v2 NULL NULL 57 view NULL NULL NULL +54 test_kvr1 1 NULL 53 fk 1 fk_k_ref_test_kv SharedPrefixLen: 1 +55 test_kvr2 2 NULL 53 fk 1 fk_v_ref_test_kv SharedPrefixLen: 1 +56 test_kvr3 2 NULL 53 fk 2 fk_v_ref_test_kv SharedPrefixLen: 1 +57 test_kvi1 1 NULL 53 interleave 1 NULL SharedPrefixLen: 1 +58 test_kvi2 2 NULL 53 interleave 1 NULL SharedPrefixLen: 1 +59 test_v1 NULL NULL 53 view NULL NULL NULL +61 test_v2 NULL NULL 59 view NULL NULL NULL query ITIITITT colnames SELECT * FROM crdb_internal.forward_dependencies WHERE descriptor_name LIKE 'test_%' ORDER BY descriptor_id, index_id, dependedonby_type, dependedonby_id, dependedonby_index_id ---- descriptor_id descriptor_name index_id dependedonby_id dependedonby_type dependedonby_index_id dependedonby_name dependedonby_details -51 test_kv NULL 57 view 0 NULL Columns: [1 2 3] -51 test_kv 1 52 fk 1 · SharedPrefixLen: 0 -51 test_kv 1 53 fk 2 · SharedPrefixLen: 0 -51 test_kv 1 55 interleave 1 NULL SharedPrefixLen: 0 -51 test_kv 1 56 interleave 2 NULL SharedPrefixLen: 0 -51 test_kv 2 54 fk 2 · SharedPrefixLen: 0 -57 test_v1 NULL 59 view 0 NULL Columns: [1] +53 test_kv NULL 59 view 0 NULL Columns: [1 2 3] +53 test_kv 1 54 fk 1 · SharedPrefixLen: 0 +53 test_kv 1 55 fk 2 · SharedPrefixLen: 0 +53 test_kv 1 57 interleave 1 NULL SharedPrefixLen: 0 +53 test_kv 1 58 interleave 2 NULL SharedPrefixLen: 0 +53 test_kv 2 56 fk 2 · SharedPrefixLen: 0 +59 test_v1 NULL 61 view 0 NULL Columns: [1] # Checks view dependencies (#17306) statement ok @@ -111,13 +111,13 @@ query ITIIITITT colnames SELECT * FROM crdb_internal.backward_dependencies WHERE descriptor_name LIKE 'moretest_%' ORDER BY descriptor_id, index_id, dependson_type, dependson_id, dependson_index_id ---- descriptor_id descriptor_name index_id column_id dependson_id dependson_type dependson_index_id dependson_name dependson_details -62 moretest_v NULL NULL 60 view NULL NULL NULL +64 moretest_v NULL NULL 62 view NULL NULL NULL query ITIITITT colnames SELECT * FROM crdb_internal.forward_dependencies WHERE descriptor_name LIKE 'moretest_%' ORDER BY descriptor_id, index_id, dependedonby_type, dependedonby_id, dependedonby_index_id ---- descriptor_id descriptor_name index_id dependedonby_id dependedonby_type dependedonby_index_id dependedonby_name dependedonby_details -60 moretest_t NULL 62 view 0 NULL Columns: [1 2 3] +62 moretest_t NULL 64 view 0 NULL Columns: [1 2 3] # Check sequence dependencies. @@ -131,13 +131,13 @@ query ITIIITITT colnames SELECT * FROM crdb_internal.backward_dependencies WHERE descriptor_name LIKE 'blog_posts' ---- descriptor_id descriptor_name index_id column_id dependson_id dependson_type dependson_index_id dependson_name dependson_details -64 blog_posts NULL 1 63 sequence NULL NULL NULL +66 blog_posts NULL 1 65 sequence NULL NULL NULL query ITIITITT colnames SELECT * FROM crdb_internal.forward_dependencies WHERE descriptor_name LIKE 'blog_posts%' ---- descriptor_id descriptor_name index_id dependedonby_id dependedonby_type dependedonby_index_id dependedonby_name dependedonby_details -63 blog_posts_id_seq NULL 64 sequence 0 NULL Columns: [0] +65 blog_posts_id_seq NULL 66 sequence 0 NULL Columns: [0] # Verify that we report a dependency on a column that is being mutated. #CREATE VIEW v AS WITH a AS (UPDATE kv SET v = 444 RETURNING k) SELECT k FROM a; @@ -172,4 +172,4 @@ query ITIITITT colnames SELECT * FROM crdb_internal.forward_dependencies WHERE descriptor_name = 'kv' ---- descriptor_id descriptor_name index_id dependedonby_id dependedonby_type dependedonby_index_id dependedonby_name dependedonby_details -65 kv NULL 66 view 0 NULL Columns: [1 2 3] +67 kv NULL 68 view 0 NULL Columns: [1 2 3] diff --git a/pkg/sql/logictest/testdata/logic_test/drop_database b/pkg/sql/logictest/testdata/logic_test/drop_database index 4af00c7bd968..fd2943cc27c2 100644 --- a/pkg/sql/logictest/testdata/logic_test/drop_database +++ b/pkg/sql/logictest/testdata/logic_test/drop_database @@ -6,7 +6,9 @@ CREATE DATABASE "foo-bar" query T SHOW DATABASES ---- +defaultdb foo-bar +postgres system test @@ -22,11 +24,13 @@ DROP DATABASE "foo-bar" CASCADE query TTT SELECT name, database_name, state FROM crdb_internal.tables WHERE name = 't' ---- -t [51] DROP +t [53] DROP query T SHOW DATABASES ---- +defaultdb +postgres system test @@ -36,7 +40,9 @@ CREATE DATABASE "foo bar" query T SHOW DATABASES ---- +defaultdb foo bar +postgres system test @@ -46,6 +52,8 @@ DROP DATABASE "foo bar" CASCADE query T SHOW DATABASES ---- +defaultdb +postgres system test @@ -130,6 +138,8 @@ SHOW DATABASES ---- d1 d2 +defaultdb +postgres system test @@ -140,6 +150,8 @@ query T SHOW DATABASES ---- d2 +defaultdb +postgres system test @@ -165,6 +177,8 @@ DROP DATABASE d2 CASCADE query T SHOW DATABASES ---- +defaultdb +postgres system test @@ -196,6 +210,8 @@ DROP DATABASE constraint_db CASCADE query T SHOW DATABASES ---- +defaultdb +postgres system test @@ -218,3 +234,10 @@ DROP DATABASE foo statement ok SET sql_safe_updates = FALSE; DROP DATABASE foo + +# Check that the default databases can be dropped and re-created like any other. +statement OK +DROP DATABASE defaultdb; DROP DATABASE postgres + +statement ok +CREATE DATABASE defaultdb; CREATE DATABASE postgres diff --git a/pkg/sql/logictest/testdata/logic_test/event_log b/pkg/sql/logictest/testdata/logic_test/event_log index 1cb6c5ff9c27..26cfbdc0b1fe 100644 --- a/pkg/sql/logictest/testdata/logic_test/event_log +++ b/pkg/sql/logictest/testdata/logic_test/event_log @@ -25,8 +25,8 @@ query II rowsort SELECT "targetID", "reportingID" FROM system.eventlog WHERE "eventType" = 'create_table' ---- -51 1 -52 1 +53 1 +54 1 # Verify the contents of the 'Info' field of each log message using a LIKE # statement. @@ -38,7 +38,7 @@ FROM system.eventlog WHERE "eventType" = 'create_table' AND info::JSONB->>'Statement' LIKE 'CREATE TABLE a%' ---- -51 1 test.public.a +53 1 test.public.a query IIT SELECT "targetID", "reportingID", info::JSONB->>'TableName' @@ -46,7 +46,7 @@ FROM system.eventlog WHERE "eventType" = 'create_table' AND info::JSONB->>'Statement' LIKE 'CREATE TABLE IF NOT EXISTS b%' ---- -52 1 test.public.b +54 1 test.public.b # Sanity check - check for a non-matching info value. ################## @@ -74,13 +74,13 @@ query IIT rowsort SELECT "targetID", "reportingID", info::JSONB->>'TableName' FROM system.eventlog WHERE "eventType" = 'alter_table' ---- -51 1 test.public.a +53 1 test.public.a query II rowsort SELECT "targetID", "reportingID" FROM system.eventlog WHERE "eventType" = 'finish_schema_change' ---- -51 1 +53 1 query II SELECT "targetID", "reportingID" FROM system.eventlog @@ -95,7 +95,7 @@ SELECT "targetID", "reportingID", info::JSONB->>'TableName' FROM system.eventlog WHERE "eventType" = 'alter_table' AND info::JSONB->>'Statement' LIKE 'ALTER TABLE a%' ---- -51 1 test.public.a +53 1 test.public.a # Add a UNIQUE constraint to the table in a way that will ensure the schema # change is reversed. @@ -111,27 +111,27 @@ query IIT rowsort SELECT "targetID", "reportingID", info::JSONB->>'TableName' FROM system.eventlog WHERE "eventType" = 'alter_table' ---- -51 1 test.public.a -51 1 test.public.a +53 1 test.public.a +53 1 test.public.a query II rowsort SELECT "targetID", "reportingID" FROM system.eventlog WHERE "eventType" = 'finish_schema_change' ---- -51 1 +53 1 query II rowsort SELECT "targetID", "reportingID" FROM system.eventlog WHERE "eventType" = 'reverse_schema_change' ---- -51 1 +53 1 query II rowsort SELECT "targetID", "reportingID" FROM system.eventlog WHERE "eventType" = 'finish_schema_change_rollback' ---- -51 1 +53 1 # Create an Index on the table ################# @@ -144,14 +144,14 @@ SELECT "targetID", "reportingID", info::JSONB->>'TableName' FROM system.eventlog WHERE "eventType" = 'create_index' AND info::JSONB->>'Statement' LIKE 'CREATE INDEX a_foo%' ---- -51 1 test.public.a +53 1 test.public.a query II rowsort SELECT "targetID", "reportingID" FROM system.eventlog WHERE "eventType" = 'finish_schema_change' ---- -51 1 -51 1 +53 1 +53 1 # Drop the index ################# @@ -164,15 +164,15 @@ SELECT "targetID", "reportingID", info::JSONB->>'TableName' FROM system.eventlog WHERE "eventType" = 'drop_index' AND info::JSONB->>'Statement' LIKE 'DROP INDEX%a_foo' ---- -51 1 test.public.a +53 1 test.public.a query II rowsort SELECT "targetID", "reportingID" FROM system.eventlog WHERE "eventType" = 'finish_schema_change' ---- -51 1 -51 1 -51 1 +53 1 +53 1 +53 1 # Drop both tables + superfluous "IF EXISTS" ################## @@ -196,8 +196,8 @@ SELECT "targetID", "reportingID", info::JSONB->>'TableName' FROM system.eventlog WHERE "eventType" = 'drop_table' ---- -51 1 test.public.a -52 1 test.public.b +53 1 test.public.a +54 1 test.public.b # Verify the contents of the 'info' field of each event. ################## @@ -208,7 +208,7 @@ FROM system.eventlog WHERE "eventType" = 'drop_table' AND info::JSONB->>'Statement' LIKE 'DROP TABLE a%' ---- -51 1 test.public.a +53 1 test.public.a query IIT SELECT "targetID", "reportingID", info::JSONB->>'TableName' @@ -216,7 +216,7 @@ FROM system.eventlog WHERE "eventType" = 'drop_table' AND info::JSONB->>'Statement' LIKE 'DROP TABLE IF EXISTS b%' ---- -52 1 test.public.b +54 1 test.public.b ################## @@ -245,7 +245,7 @@ FROM system.eventlog WHERE "eventType" = 'create_database' AND info::JSONB->>'Statement' LIKE 'CREATE DATABASE eventlogtest%' ---- -53 1 +55 1 query II SELECT "targetID", "reportingID" @@ -253,7 +253,7 @@ FROM system.eventlog WHERE "eventType" = 'create_database' AND info::JSONB->>'Statement' LIKE 'CREATE DATABASE IF NOT EXISTS othereventlogtest%' ---- -54 1 +56 1 # Add some tables to eventlogtest. ################## @@ -290,7 +290,7 @@ FROM system.eventlog WHERE "eventType" = 'drop_database' AND info::JSONB->>'Statement' LIKE 'DROP DATABASE eventlogtest%' ---- -53 1 ["eventlogtest.public.anothertesttable", "eventlogtest.public.testtable"] +55 1 ["eventlogtest.public.anothertesttable", "eventlogtest.public.testtable"] query IIT SELECT "targetID", "reportingID", info::JSONB->>'DroppedSchemaObjects' @@ -298,7 +298,7 @@ FROM system.eventlog WHERE "eventType" = 'drop_database' AND info::JSONB->>'Statement' LIKE 'DROP DATABASE IF EXISTS othereventlogtest%' ---- -54 1 [] +56 1 [] statement ok SET DATABASE = test @@ -356,7 +356,7 @@ FROM system.eventlog WHERE "eventType" = 'set_zone_config' ORDER BY "timestamp" ---- -57 1 {"Target":"test.a","Config":"range_max_bytes: 67108865","User":"root"} +59 1 {"Target":"test.a","Config":"range_max_bytes: 67108865","User":"root"} 22 1 {"Target":".liveness","Config":"range_min_bytes: 1048577","User":"root"} query IIT @@ -365,7 +365,7 @@ FROM system.eventlog WHERE "eventType" = 'remove_zone_config' ORDER BY "timestamp" ---- -57 1 {"Target":"test.a","User":"root"} +59 1 {"Target":"test.a","User":"root"} 22 1 {"Target":".liveness","User":"root"} statement ok @@ -387,9 +387,9 @@ SELECT "eventType", "targetID", "reportingID", info::JSONB->>'SequenceName' FROM system.eventlog WHERE "eventType" in ('create_sequence', 'alter_sequence', 'drop_sequence') ---- -create_sequence 58 1 test.public.s -alter_sequence 58 1 test.public.s -drop_sequence 58 1 test.public.s +create_sequence 60 1 test.public.s +alter_sequence 60 1 test.public.s +drop_sequence 60 1 test.public.s # Views @@ -404,5 +404,5 @@ SELECT "eventType", "targetID", "reportingID", info::JSONB->>'ViewName' FROM system.eventlog WHERE "eventType" in ('create_view', 'drop_view') ---- -drop_view 59 1 test.public.v -create_view 59 1 test.public.v +create_view 61 1 test.public.v +drop_view 61 1 test.public.v diff --git a/pkg/sql/logictest/testdata/logic_test/explain b/pkg/sql/logictest/testdata/logic_test/explain index ac50b61beb67..a678c70b0c0e 100644 --- a/pkg/sql/logictest/testdata/logic_test/explain +++ b/pkg/sql/logictest/testdata/logic_test/explain @@ -178,7 +178,7 @@ distinct · · │ order +"Database" └── render · · └── values · · -· size 4 columns, 12 rows +· size 4 columns, 20 rows query TTT EXPLAIN SHOW TABLES @@ -265,7 +265,7 @@ sort · · └── render · · └── filter · · └── values · · -· size 8 columns, 376 rows +· size 8 columns, 540 rows query TTT diff --git a/pkg/sql/logictest/testdata/logic_test/grant_table b/pkg/sql/logictest/testdata/logic_test/grant_table index bb6a98a1f9e2..b932def3facc 100644 --- a/pkg/sql/logictest/testdata/logic_test/grant_table +++ b/pkg/sql/logictest/testdata/logic_test/grant_table @@ -136,504 +136,244 @@ statement ok SET DATABASE = '' query TTTTT colnames -SHOW GRANTS ----- -Database Schema Table User Privileges -a crdb_internal NULL admin ALL -a crdb_internal NULL readwrite ALL -a crdb_internal NULL root ALL -a crdb_internal backward_dependencies public SELECT -a crdb_internal builtin_functions public SELECT -a crdb_internal cluster_queries public SELECT -a crdb_internal cluster_sessions public SELECT -a crdb_internal cluster_settings public SELECT -a crdb_internal create_statements public SELECT -a crdb_internal forward_dependencies public SELECT -a crdb_internal gossip_alerts public SELECT -a crdb_internal gossip_liveness public SELECT -a crdb_internal gossip_nodes public SELECT -a crdb_internal index_columns public SELECT -a crdb_internal jobs public SELECT -a crdb_internal kv_node_status public SELECT -a crdb_internal kv_store_status public SELECT -a crdb_internal leases public SELECT -a crdb_internal node_build_info public SELECT -a crdb_internal node_metrics public SELECT -a crdb_internal node_queries public SELECT -a crdb_internal node_runtime_info public SELECT -a crdb_internal node_sessions public SELECT -a crdb_internal node_statement_statistics public SELECT -a crdb_internal partitions public SELECT -a crdb_internal ranges public SELECT -a crdb_internal schema_changes public SELECT -a crdb_internal session_trace public SELECT -a crdb_internal session_variables public SELECT -a crdb_internal table_columns public SELECT -a crdb_internal table_indexes public SELECT -a crdb_internal tables public SELECT -a crdb_internal zones public SELECT -a information_schema NULL admin ALL -a information_schema NULL readwrite ALL -a information_schema NULL root ALL -a information_schema administrable_role_authorizations public SELECT -a information_schema applicable_roles public SELECT -a information_schema column_privileges public SELECT -a information_schema columns public SELECT -a information_schema constraint_column_usage public SELECT -a information_schema enabled_roles public SELECT -a information_schema key_column_usage public SELECT -a information_schema referential_constraints public SELECT -a information_schema role_table_grants public SELECT -a information_schema schema_privileges public SELECT -a information_schema schemata public SELECT -a information_schema sequences public SELECT -a information_schema statistics public SELECT -a information_schema table_constraints public SELECT -a information_schema table_privileges public SELECT -a information_schema tables public SELECT -a information_schema user_privileges public SELECT -a information_schema views public SELECT -a pg_catalog NULL admin ALL -a pg_catalog NULL readwrite ALL -a pg_catalog NULL root ALL -a pg_catalog pg_am public SELECT -a pg_catalog pg_attrdef public SELECT -a pg_catalog pg_attribute public SELECT -a pg_catalog pg_auth_members public SELECT -a pg_catalog pg_class public SELECT -a pg_catalog pg_collation public SELECT -a pg_catalog pg_constraint public SELECT -a pg_catalog pg_database public SELECT -a pg_catalog pg_depend public SELECT -a pg_catalog pg_description public SELECT -a pg_catalog pg_enum public SELECT -a pg_catalog pg_extension public SELECT -a pg_catalog pg_foreign_data_wrapper public SELECT -a pg_catalog pg_foreign_server public SELECT -a pg_catalog pg_foreign_table public SELECT -a pg_catalog pg_index public SELECT -a pg_catalog pg_indexes public SELECT -a pg_catalog pg_inherits public SELECT -a pg_catalog pg_language public SELECT -a pg_catalog pg_namespace public SELECT -a pg_catalog pg_operator public SELECT -a pg_catalog pg_proc public SELECT -a pg_catalog pg_range public SELECT -a pg_catalog pg_rewrite public SELECT -a pg_catalog pg_roles public SELECT -a pg_catalog pg_sequence public SELECT -a pg_catalog pg_settings public SELECT -a pg_catalog pg_tables public SELECT -a pg_catalog pg_tablespace public SELECT -a pg_catalog pg_trigger public SELECT -a pg_catalog pg_type public SELECT -a pg_catalog pg_user public SELECT -a pg_catalog pg_user_mapping public SELECT -a pg_catalog pg_views public SELECT -a public NULL admin ALL -a public NULL readwrite ALL -a public NULL root ALL -system crdb_internal NULL admin GRANT -system crdb_internal NULL admin SELECT -system crdb_internal NULL root GRANT -system crdb_internal NULL root SELECT -system crdb_internal backward_dependencies public SELECT -system crdb_internal builtin_functions public SELECT -system crdb_internal cluster_queries public SELECT -system crdb_internal cluster_sessions public SELECT -system crdb_internal cluster_settings public SELECT -system crdb_internal create_statements public SELECT -system crdb_internal forward_dependencies public SELECT -system crdb_internal gossip_alerts public SELECT -system crdb_internal gossip_liveness public SELECT -system crdb_internal gossip_nodes public SELECT -system crdb_internal index_columns public SELECT -system crdb_internal jobs public SELECT -system crdb_internal kv_node_status public SELECT -system crdb_internal kv_store_status public SELECT -system crdb_internal leases public SELECT -system crdb_internal node_build_info public SELECT -system crdb_internal node_metrics public SELECT -system crdb_internal node_queries public SELECT -system crdb_internal node_runtime_info public SELECT -system crdb_internal node_sessions public SELECT -system crdb_internal node_statement_statistics public SELECT -system crdb_internal partitions public SELECT -system crdb_internal ranges public SELECT -system crdb_internal schema_changes public SELECT -system crdb_internal session_trace public SELECT -system crdb_internal session_variables public SELECT -system crdb_internal table_columns public SELECT -system crdb_internal table_indexes public SELECT -system crdb_internal tables public SELECT -system crdb_internal zones public SELECT -system information_schema NULL admin GRANT -system information_schema NULL admin SELECT -system information_schema NULL root GRANT -system information_schema NULL root SELECT -system information_schema administrable_role_authorizations public SELECT -system information_schema applicable_roles public SELECT -system information_schema column_privileges public SELECT -system information_schema columns public SELECT -system information_schema constraint_column_usage public SELECT -system information_schema enabled_roles public SELECT -system information_schema key_column_usage public SELECT -system information_schema referential_constraints public SELECT -system information_schema role_table_grants public SELECT -system information_schema schema_privileges public SELECT -system information_schema schemata public SELECT -system information_schema sequences public SELECT -system information_schema statistics public SELECT -system information_schema table_constraints public SELECT -system information_schema table_privileges public SELECT -system information_schema tables public SELECT -system information_schema user_privileges public SELECT -system information_schema views public SELECT -system pg_catalog NULL admin SELECT -system pg_catalog NULL admin GRANT -system pg_catalog NULL root GRANT -system pg_catalog NULL root SELECT -system pg_catalog pg_am public SELECT -system pg_catalog pg_attrdef public SELECT -system pg_catalog pg_attribute public SELECT -system pg_catalog pg_auth_members public SELECT -system pg_catalog pg_class public SELECT -system pg_catalog pg_collation public SELECT -system pg_catalog pg_constraint public SELECT -system pg_catalog pg_database public SELECT -system pg_catalog pg_depend public SELECT -system pg_catalog pg_description public SELECT -system pg_catalog pg_enum public SELECT -system pg_catalog pg_extension public SELECT -system pg_catalog pg_foreign_data_wrapper public SELECT -system pg_catalog pg_foreign_server public SELECT -system pg_catalog pg_foreign_table public SELECT -system pg_catalog pg_index public SELECT -system pg_catalog pg_indexes public SELECT -system pg_catalog pg_inherits public SELECT -system pg_catalog pg_language public SELECT -system pg_catalog pg_namespace public SELECT -system pg_catalog pg_operator public SELECT -system pg_catalog pg_proc public SELECT -system pg_catalog pg_range public SELECT -system pg_catalog pg_rewrite public SELECT -system pg_catalog pg_roles public SELECT -system pg_catalog pg_sequence public SELECT -system pg_catalog pg_settings public SELECT -system pg_catalog pg_tables public SELECT -system pg_catalog pg_tablespace public SELECT -system pg_catalog pg_trigger public SELECT -system pg_catalog pg_type public SELECT -system pg_catalog pg_user public SELECT -system pg_catalog pg_user_mapping public SELECT -system pg_catalog pg_views public SELECT -system public NULL admin SELECT -system public NULL admin GRANT -system public NULL root GRANT -system public NULL root SELECT -system public descriptor admin SELECT -system public descriptor admin GRANT -system public descriptor root SELECT -system public descriptor root GRANT -system public eventlog admin SELECT -system public eventlog admin GRANT -system public eventlog admin DELETE -system public eventlog admin UPDATE -system public eventlog admin INSERT -system public eventlog root DELETE -system public eventlog root UPDATE -system public eventlog root SELECT -system public eventlog root GRANT -system public eventlog root INSERT -system public jobs admin SELECT -system public jobs admin UPDATE -system public jobs admin DELETE -system public jobs admin GRANT -system public jobs admin INSERT -system public jobs root DELETE -system public jobs root SELECT -system public jobs root GRANT -system public jobs root UPDATE -system public jobs root INSERT -system public lease admin GRANT -system public lease admin SELECT -system public lease admin UPDATE -system public lease admin DELETE -system public lease admin INSERT -system public lease root INSERT -system public lease root SELECT -system public lease root GRANT -system public lease root DELETE -system public lease root UPDATE -system public locations admin GRANT -system public locations admin INSERT -system public locations admin SELECT -system public locations admin DELETE -system public locations admin UPDATE -system public locations root DELETE -system public locations root GRANT -system public locations root INSERT -system public locations root SELECT -system public locations root UPDATE -system public namespace admin GRANT -system public namespace admin SELECT -system public namespace root SELECT -system public namespace root GRANT -system public rangelog admin SELECT -system public rangelog admin INSERT -system public rangelog admin UPDATE -system public rangelog admin GRANT -system public rangelog admin DELETE -system public rangelog root GRANT -system public rangelog root INSERT -system public rangelog root DELETE -system public rangelog root UPDATE -system public rangelog root SELECT -system public role_members admin INSERT -system public role_members admin SELECT -system public role_members admin UPDATE -system public role_members admin DELETE -system public role_members admin GRANT -system public role_members root INSERT -system public role_members root SELECT -system public role_members root UPDATE -system public role_members root DELETE -system public role_members root GRANT -system public settings admin UPDATE -system public settings admin DELETE -system public settings admin INSERT -system public settings admin SELECT -system public settings admin GRANT -system public settings root SELECT -system public settings root GRANT -system public settings root INSERT -system public settings root UPDATE -system public settings root DELETE -system public table_statistics admin GRANT -system public table_statistics admin UPDATE -system public table_statistics admin INSERT -system public table_statistics admin SELECT -system public table_statistics admin DELETE -system public table_statistics root GRANT -system public table_statistics root UPDATE -system public table_statistics root SELECT -system public table_statistics root DELETE -system public table_statistics root INSERT -system public ui admin DELETE -system public ui admin SELECT -system public ui admin GRANT -system public ui admin INSERT -system public ui admin UPDATE -system public ui root DELETE -system public ui root GRANT -system public ui root SELECT -system public ui root INSERT -system public ui root UPDATE -system public users admin SELECT -system public users admin GRANT -system public users admin DELETE -system public users admin UPDATE -system public users admin INSERT -system public users root DELETE -system public users root INSERT -system public users root UPDATE -system public users root SELECT -system public users root GRANT -system public web_sessions admin DELETE -system public web_sessions admin UPDATE -system public web_sessions admin SELECT -system public web_sessions admin INSERT -system public web_sessions admin GRANT -system public web_sessions root UPDATE -system public web_sessions root INSERT -system public web_sessions root GRANT -system public web_sessions root DELETE -system public web_sessions root SELECT -system public zones admin INSERT -system public zones admin DELETE -system public zones admin GRANT -system public zones admin UPDATE -system public zones admin SELECT -system public zones root DELETE -system public zones root GRANT -system public zones root UPDATE -system public zones root SELECT -system public zones root INSERT -test crdb_internal NULL admin ALL -test crdb_internal NULL root ALL -test crdb_internal backward_dependencies public SELECT -test crdb_internal builtin_functions public SELECT -test crdb_internal cluster_queries public SELECT -test crdb_internal cluster_sessions public SELECT -test crdb_internal cluster_settings public SELECT -test crdb_internal create_statements public SELECT -test crdb_internal forward_dependencies public SELECT -test crdb_internal gossip_alerts public SELECT -test crdb_internal gossip_liveness public SELECT -test crdb_internal gossip_nodes public SELECT -test crdb_internal index_columns public SELECT -test crdb_internal jobs public SELECT -test crdb_internal kv_node_status public SELECT -test crdb_internal kv_store_status public SELECT -test crdb_internal leases public SELECT -test crdb_internal node_build_info public SELECT -test crdb_internal node_metrics public SELECT -test crdb_internal node_queries public SELECT -test crdb_internal node_runtime_info public SELECT -test crdb_internal node_sessions public SELECT -test crdb_internal node_statement_statistics public SELECT -test crdb_internal partitions public SELECT -test crdb_internal ranges public SELECT -test crdb_internal schema_changes public SELECT -test crdb_internal session_trace public SELECT -test crdb_internal session_variables public SELECT -test crdb_internal table_columns public SELECT -test crdb_internal table_indexes public SELECT -test crdb_internal tables public SELECT -test crdb_internal zones public SELECT -test information_schema NULL admin ALL -test information_schema NULL root ALL -test information_schema administrable_role_authorizations public SELECT -test information_schema applicable_roles public SELECT -test information_schema column_privileges public SELECT -test information_schema columns public SELECT -test information_schema constraint_column_usage public SELECT -test information_schema enabled_roles public SELECT -test information_schema key_column_usage public SELECT -test information_schema referential_constraints public SELECT -test information_schema role_table_grants public SELECT -test information_schema schema_privileges public SELECT -test information_schema schemata public SELECT -test information_schema sequences public SELECT -test information_schema statistics public SELECT -test information_schema table_constraints public SELECT -test information_schema table_privileges public SELECT -test information_schema tables public SELECT -test information_schema user_privileges public SELECT -test information_schema views public SELECT -test pg_catalog NULL admin ALL -test pg_catalog NULL root ALL -test pg_catalog pg_am public SELECT -test pg_catalog pg_attrdef public SELECT -test pg_catalog pg_attribute public SELECT -test pg_catalog pg_auth_members public SELECT -test pg_catalog pg_class public SELECT -test pg_catalog pg_collation public SELECT -test pg_catalog pg_constraint public SELECT -test pg_catalog pg_database public SELECT -test pg_catalog pg_depend public SELECT -test pg_catalog pg_description public SELECT -test pg_catalog pg_enum public SELECT -test pg_catalog pg_extension public SELECT -test pg_catalog pg_foreign_data_wrapper public SELECT -test pg_catalog pg_foreign_server public SELECT -test pg_catalog pg_foreign_table public SELECT -test pg_catalog pg_index public SELECT -test pg_catalog pg_indexes public SELECT -test pg_catalog pg_inherits public SELECT -test pg_catalog pg_language public SELECT -test pg_catalog pg_namespace public SELECT -test pg_catalog pg_operator public SELECT -test pg_catalog pg_proc public SELECT -test pg_catalog pg_range public SELECT -test pg_catalog pg_rewrite public SELECT -test pg_catalog pg_roles public SELECT -test pg_catalog pg_sequence public SELECT -test pg_catalog pg_settings public SELECT -test pg_catalog pg_tables public SELECT -test pg_catalog pg_tablespace public SELECT -test pg_catalog pg_trigger public SELECT -test pg_catalog pg_type public SELECT -test pg_catalog pg_user public SELECT -test pg_catalog pg_user_mapping public SELECT -test pg_catalog pg_views public SELECT -test public NULL admin ALL -test public NULL root ALL +SELECT * FROM [SHOW GRANTS] + WHERE "Schema" NOT IN ('crdb_internal', 'pg_catalog', 'information_schema') +---- +Database Schema Table User Privileges +a public NULL admin ALL +a public NULL readwrite ALL +a public NULL root ALL +defaultdb public NULL admin ALL +defaultdb public NULL root ALL +postgres public NULL admin ALL +postgres public NULL root ALL +system public NULL admin SELECT +system public NULL admin GRANT +system public NULL root GRANT +system public NULL root SELECT +system public descriptor admin SELECT +system public descriptor admin GRANT +system public descriptor root GRANT +system public descriptor root SELECT +system public eventlog admin SELECT +system public eventlog admin UPDATE +system public eventlog admin GRANT +system public eventlog admin INSERT +system public eventlog admin DELETE +system public eventlog root SELECT +system public eventlog root INSERT +system public eventlog root GRANT +system public eventlog root DELETE +system public eventlog root UPDATE +system public jobs admin GRANT +system public jobs admin DELETE +system public jobs admin UPDATE +system public jobs admin SELECT +system public jobs admin INSERT +system public jobs root GRANT +system public jobs root SELECT +system public jobs root UPDATE +system public jobs root INSERT +system public jobs root DELETE +system public lease admin UPDATE +system public lease admin SELECT +system public lease admin INSERT +system public lease admin DELETE +system public lease admin GRANT +system public lease root SELECT +system public lease root UPDATE +system public lease root DELETE +system public lease root GRANT +system public lease root INSERT +system public locations admin SELECT +system public locations admin UPDATE +system public locations admin INSERT +system public locations admin GRANT +system public locations admin DELETE +system public locations root DELETE +system public locations root GRANT +system public locations root INSERT +system public locations root UPDATE +system public locations root SELECT +system public namespace admin SELECT +system public namespace admin GRANT +system public namespace root SELECT +system public namespace root GRANT +system public rangelog admin DELETE +system public rangelog admin INSERT +system public rangelog admin SELECT +system public rangelog admin UPDATE +system public rangelog admin GRANT +system public rangelog root DELETE +system public rangelog root INSERT +system public rangelog root SELECT +system public rangelog root UPDATE +system public rangelog root GRANT +system public role_members admin GRANT +system public role_members admin DELETE +system public role_members admin UPDATE +system public role_members admin SELECT +system public role_members admin INSERT +system public role_members root UPDATE +system public role_members root GRANT +system public role_members root INSERT +system public role_members root SELECT +system public role_members root DELETE +system public settings admin SELECT +system public settings admin INSERT +system public settings admin DELETE +system public settings admin GRANT +system public settings admin UPDATE +system public settings root DELETE +system public settings root GRANT +system public settings root SELECT +system public settings root INSERT +system public settings root UPDATE +system public table_statistics admin GRANT +system public table_statistics admin INSERT +system public table_statistics admin SELECT +system public table_statistics admin UPDATE +system public table_statistics admin DELETE +system public table_statistics root DELETE +system public table_statistics root GRANT +system public table_statistics root INSERT +system public table_statistics root SELECT +system public table_statistics root UPDATE +system public ui admin INSERT +system public ui admin GRANT +system public ui admin SELECT +system public ui admin UPDATE +system public ui admin DELETE +system public ui root DELETE +system public ui root GRANT +system public ui root INSERT +system public ui root SELECT +system public ui root UPDATE +system public users admin INSERT +system public users admin GRANT +system public users admin UPDATE +system public users admin SELECT +system public users admin DELETE +system public users root UPDATE +system public users root DELETE +system public users root SELECT +system public users root GRANT +system public users root INSERT +system public web_sessions admin INSERT +system public web_sessions admin SELECT +system public web_sessions admin UPDATE +system public web_sessions admin DELETE +system public web_sessions admin GRANT +system public web_sessions root DELETE +system public web_sessions root GRANT +system public web_sessions root INSERT +system public web_sessions root SELECT +system public web_sessions root UPDATE +system public zones admin DELETE +system public zones admin GRANT +system public zones admin INSERT +system public zones admin UPDATE +system public zones admin SELECT +system public zones root DELETE +system public zones root INSERT +system public zones root SELECT +system public zones root UPDATE +system public zones root GRANT +test public NULL admin ALL +test public NULL root ALL query TTTTT colnames SHOW GRANTS FOR root ---- -Database Schema Table User Privileges -a crdb_internal NULL root ALL -a information_schema NULL root ALL -a pg_catalog NULL root ALL -a public NULL root ALL -system crdb_internal NULL root GRANT -system crdb_internal NULL root SELECT -system information_schema NULL root GRANT -system information_schema NULL root SELECT -system pg_catalog NULL root GRANT -system pg_catalog NULL root SELECT -system public NULL root SELECT -system public NULL root GRANT -system public descriptor root SELECT -system public descriptor root GRANT -system public eventlog root SELECT -system public eventlog root INSERT -system public eventlog root UPDATE -system public eventlog root DELETE -system public eventlog root GRANT -system public jobs root GRANT -system public jobs root UPDATE -system public jobs root SELECT -system public jobs root INSERT -system public jobs root DELETE -system public lease root UPDATE -system public lease root SELECT -system public lease root INSERT -system public lease root DELETE -system public lease root GRANT -system public locations root GRANT -system public locations root DELETE -system public locations root INSERT -system public locations root UPDATE -system public locations root SELECT -system public namespace root SELECT -system public namespace root GRANT -system public rangelog root GRANT -system public rangelog root INSERT -system public rangelog root DELETE -system public rangelog root UPDATE -system public rangelog root SELECT -system public role_members root UPDATE -system public role_members root SELECT -system public role_members root INSERT -system public role_members root GRANT -system public role_members root DELETE -system public settings root GRANT -system public settings root INSERT -system public settings root SELECT -system public settings root UPDATE -system public settings root DELETE -system public table_statistics root INSERT -system public table_statistics root GRANT -system public table_statistics root SELECT -system public table_statistics root DELETE -system public table_statistics root UPDATE -system public ui root UPDATE -system public ui root SELECT -system public ui root DELETE -system public ui root GRANT -system public ui root INSERT -system public users root GRANT -system public users root UPDATE -system public users root DELETE -system public users root SELECT -system public users root INSERT -system public web_sessions root DELETE -system public web_sessions root GRANT -system public web_sessions root INSERT -system public web_sessions root SELECT -system public web_sessions root UPDATE -system public zones root INSERT -system public zones root UPDATE -system public zones root SELECT -system public zones root GRANT -system public zones root DELETE -test crdb_internal NULL root ALL -test information_schema NULL root ALL -test pg_catalog NULL root ALL -test public NULL root ALL +Database Schema Table User Privileges +a crdb_internal NULL root ALL +a information_schema NULL root ALL +a pg_catalog NULL root ALL +a public NULL root ALL +defaultdb crdb_internal NULL root ALL +defaultdb information_schema NULL root ALL +defaultdb pg_catalog NULL root ALL +defaultdb public NULL root ALL +postgres crdb_internal NULL root ALL +postgres information_schema NULL root ALL +postgres pg_catalog NULL root ALL +postgres public NULL root ALL +system crdb_internal NULL root GRANT +system crdb_internal NULL root SELECT +system information_schema NULL root SELECT +system information_schema NULL root GRANT +system pg_catalog NULL root GRANT +system pg_catalog NULL root SELECT +system public NULL root SELECT +system public NULL root GRANT +system public descriptor root SELECT +system public descriptor root GRANT +system public eventlog root SELECT +system public eventlog root UPDATE +system public eventlog root DELETE +system public eventlog root GRANT +system public eventlog root INSERT +system public jobs root UPDATE +system public jobs root DELETE +system public jobs root SELECT +system public jobs root INSERT +system public jobs root GRANT +system public lease root DELETE +system public lease root SELECT +system public lease root UPDATE +system public lease root GRANT +system public lease root INSERT +system public locations root INSERT +system public locations root UPDATE +system public locations root GRANT +system public locations root DELETE +system public locations root SELECT +system public namespace root SELECT +system public namespace root GRANT +system public rangelog root INSERT +system public rangelog root UPDATE +system public rangelog root DELETE +system public rangelog root GRANT +system public rangelog root SELECT +system public role_members root SELECT +system public role_members root INSERT +system public role_members root UPDATE +system public role_members root DELETE +system public role_members root GRANT +system public settings root INSERT +system public settings root GRANT +system public settings root SELECT +system public settings root DELETE +system public settings root UPDATE +system public table_statistics root GRANT +system public table_statistics root DELETE +system public table_statistics root UPDATE +system public table_statistics root SELECT +system public table_statistics root INSERT +system public ui root SELECT +system public ui root DELETE +system public ui root GRANT +system public ui root INSERT +system public ui root UPDATE +system public users root GRANT +system public users root UPDATE +system public users root DELETE +system public users root SELECT +system public users root INSERT +system public web_sessions root GRANT +system public web_sessions root INSERT +system public web_sessions root SELECT +system public web_sessions root UPDATE +system public web_sessions root DELETE +system public zones root GRANT +system public zones root UPDATE +system public zones root SELECT +system public zones root INSERT +system public zones root DELETE +test crdb_internal NULL root ALL +test information_schema NULL root ALL +test pg_catalog NULL root ALL +test public NULL root ALL statement error pgcode 42P01 relation "a.t" does not exist SHOW GRANTS ON a.t diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index a2ccb22c4433..914f90bf3703 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -110,6 +110,8 @@ TRUNCATE TABLE information_schema.tables query T SHOW DATABASES ---- +defaultdb +postgres system test diff --git a/pkg/sql/logictest/testdata/logic_test/interleaved b/pkg/sql/logictest/testdata/logic_test/interleaved index 21d457fadcfd..42780368777d 100644 --- a/pkg/sql/logictest/testdata/logic_test/interleaved +++ b/pkg/sql/logictest/testdata/logic_test/interleaved @@ -315,7 +315,7 @@ EXPLAIN SELECT * FROM orders WHERE customer = 1 AND id = 1000 ---- scan · · · table orders@primary -· spans /1/#/68/1/1000-/1/#/68/1/1000/# +· spans /1/#/70/1/1000-/1/#/70/1/1000/# # Check that interleaving can occur across databases statement ok diff --git a/pkg/sql/logictest/testdata/logic_test/interleaved_join b/pkg/sql/logictest/testdata/logic_test/interleaved_join index 0225dbb53552..b52b6e533258 100644 --- a/pkg/sql/logictest/testdata/logic_test/interleaved_join +++ b/pkg/sql/logictest/testdata/logic_test/interleaved_join @@ -192,76 +192,76 @@ query TTITI colnames SHOW TESTING_RANGES FROM TABLE parent1 ---- Start Key End Key Range ID Replicas Lease Holder -NULL /2/#/54/1/42/2/#/56/1/2 1 {1} 1 -/2/#/54/1/42/2/#/56/1/2 /4/#/53/1/44 11 {2} 2 -/4/#/53/1/44 /6/#/54/1/46/6/#/56/1/6 6 {3} 3 -/6/#/54/1/46/6/#/56/1/6 /8 12 {4} 4 -/8 /10/#/54/1/50/10/#/56/1/10 2 {5} 5 -/10/#/54/1/50/10/#/56/1/10 /12/#/53/1/52 13 {1} 1 -/12/#/53/1/52 /14/#/54/1/54/14/#/56/1/14 7 {2} 2 -/14/#/54/1/54/14/#/56/1/14 /16 14 {3} 3 -/16 /18/#/54/1/58/18/#/56/1/18 3 {4} 4 -/18/#/54/1/58/18/#/56/1/18 /20/#/53/1/60 15 {5} 5 -/20/#/53/1/60 /22/#/54/1/62/22/#/56/1/22 8 {1} 1 -/22/#/54/1/62/22/#/56/1/22 /24 16 {2} 2 -/24 /26/#/54/1/66/26/#/56/1/26 4 {3} 3 -/26/#/54/1/66/26/#/56/1/26 /28/#/53/1/68 17 {4} 4 -/28/#/53/1/68 /30/#/54/1/70/30/#/56/1/30 9 {5} 5 -/30/#/54/1/70/30/#/56/1/30 /32 18 {1} 1 -/32 /34/#/54/1/74/34/#/56/1/34 5 {2} 2 -/34/#/54/1/74/34/#/56/1/34 /36/#/53/1/76 19 {3} 3 -/36/#/53/1/76 /38/#/54/1/78/38/#/56/1/38 10 {4} 4 -/38/#/54/1/78/38/#/56/1/38 NULL 20 {5} 5 +NULL /2/#/56/1/42/2/#/58/1/2 1 {1} 1 +/2/#/56/1/42/2/#/58/1/2 /4/#/55/1/44 11 {2} 2 +/4/#/55/1/44 /6/#/56/1/46/6/#/58/1/6 6 {3} 3 +/6/#/56/1/46/6/#/58/1/6 /8 12 {4} 4 +/8 /10/#/56/1/50/10/#/58/1/10 2 {5} 5 +/10/#/56/1/50/10/#/58/1/10 /12/#/55/1/52 13 {1} 1 +/12/#/55/1/52 /14/#/56/1/54/14/#/58/1/14 7 {2} 2 +/14/#/56/1/54/14/#/58/1/14 /16 14 {3} 3 +/16 /18/#/56/1/58/18/#/58/1/18 3 {4} 4 +/18/#/56/1/58/18/#/58/1/18 /20/#/55/1/60 15 {5} 5 +/20/#/55/1/60 /22/#/56/1/62/22/#/58/1/22 8 {1} 1 +/22/#/56/1/62/22/#/58/1/22 /24 16 {2} 2 +/24 /26/#/56/1/66/26/#/58/1/26 4 {3} 3 +/26/#/56/1/66/26/#/58/1/26 /28/#/55/1/68 17 {4} 4 +/28/#/55/1/68 /30/#/56/1/70/30/#/58/1/30 9 {5} 5 +/30/#/56/1/70/30/#/58/1/30 /32 18 {1} 1 +/32 /34/#/56/1/74/34/#/58/1/34 5 {2} 2 +/34/#/56/1/74/34/#/58/1/34 /36/#/55/1/76 19 {3} 3 +/36/#/55/1/76 /38/#/56/1/78/38/#/58/1/38 10 {4} 4 +/38/#/56/1/78/38/#/58/1/38 NULL 20 {5} 5 query TTITI colnames SHOW TESTING_RANGES FROM TABLE child1 ---- Start Key End Key Range ID Replicas Lease Holder -NULL /2/#/54/1/42/2/#/56/1/2 1 {1} 1 -/2/#/54/1/42/2/#/56/1/2 /4/#/53/1/44 11 {2} 2 -/4/#/53/1/44 /6/#/54/1/46/6/#/56/1/6 6 {3} 3 -/6/#/54/1/46/6/#/56/1/6 /8 12 {4} 4 -/8 /10/#/54/1/50/10/#/56/1/10 2 {5} 5 -/10/#/54/1/50/10/#/56/1/10 /12/#/53/1/52 13 {1} 1 -/12/#/53/1/52 /14/#/54/1/54/14/#/56/1/14 7 {2} 2 -/14/#/54/1/54/14/#/56/1/14 /16 14 {3} 3 -/16 /18/#/54/1/58/18/#/56/1/18 3 {4} 4 -/18/#/54/1/58/18/#/56/1/18 /20/#/53/1/60 15 {5} 5 -/20/#/53/1/60 /22/#/54/1/62/22/#/56/1/22 8 {1} 1 -/22/#/54/1/62/22/#/56/1/22 /24 16 {2} 2 -/24 /26/#/54/1/66/26/#/56/1/26 4 {3} 3 -/26/#/54/1/66/26/#/56/1/26 /28/#/53/1/68 17 {4} 4 -/28/#/53/1/68 /30/#/54/1/70/30/#/56/1/30 9 {5} 5 -/30/#/54/1/70/30/#/56/1/30 /32 18 {1} 1 -/32 /34/#/54/1/74/34/#/56/1/34 5 {2} 2 -/34/#/54/1/74/34/#/56/1/34 /36/#/53/1/76 19 {3} 3 -/36/#/53/1/76 /38/#/54/1/78/38/#/56/1/38 10 {4} 4 -/38/#/54/1/78/38/#/56/1/38 NULL 20 {5} 5 +NULL /2/#/56/1/42/2/#/58/1/2 1 {1} 1 +/2/#/56/1/42/2/#/58/1/2 /4/#/55/1/44 11 {2} 2 +/4/#/55/1/44 /6/#/56/1/46/6/#/58/1/6 6 {3} 3 +/6/#/56/1/46/6/#/58/1/6 /8 12 {4} 4 +/8 /10/#/56/1/50/10/#/58/1/10 2 {5} 5 +/10/#/56/1/50/10/#/58/1/10 /12/#/55/1/52 13 {1} 1 +/12/#/55/1/52 /14/#/56/1/54/14/#/58/1/14 7 {2} 2 +/14/#/56/1/54/14/#/58/1/14 /16 14 {3} 3 +/16 /18/#/56/1/58/18/#/58/1/18 3 {4} 4 +/18/#/56/1/58/18/#/58/1/18 /20/#/55/1/60 15 {5} 5 +/20/#/55/1/60 /22/#/56/1/62/22/#/58/1/22 8 {1} 1 +/22/#/56/1/62/22/#/58/1/22 /24 16 {2} 2 +/24 /26/#/56/1/66/26/#/58/1/26 4 {3} 3 +/26/#/56/1/66/26/#/58/1/26 /28/#/55/1/68 17 {4} 4 +/28/#/55/1/68 /30/#/56/1/70/30/#/58/1/30 9 {5} 5 +/30/#/56/1/70/30/#/58/1/30 /32 18 {1} 1 +/32 /34/#/56/1/74/34/#/58/1/34 5 {2} 2 +/34/#/56/1/74/34/#/58/1/34 /36/#/55/1/76 19 {3} 3 +/36/#/55/1/76 /38/#/56/1/78/38/#/58/1/38 10 {4} 4 +/38/#/56/1/78/38/#/58/1/38 NULL 20 {5} 5 query TTITI colnames SHOW TESTING_RANGES FROM TABLE grandchild1 ---- Start Key End Key Range ID Replicas Lease Holder -NULL /2/#/54/1/42/2/#/56/1/2 1 {1} 1 -/2/#/54/1/42/2/#/56/1/2 /4/#/53/1/44 11 {2} 2 -/4/#/53/1/44 /6/#/54/1/46/6/#/56/1/6 6 {3} 3 -/6/#/54/1/46/6/#/56/1/6 /8 12 {4} 4 -/8 /10/#/54/1/50/10/#/56/1/10 2 {5} 5 -/10/#/54/1/50/10/#/56/1/10 /12/#/53/1/52 13 {1} 1 -/12/#/53/1/52 /14/#/54/1/54/14/#/56/1/14 7 {2} 2 -/14/#/54/1/54/14/#/56/1/14 /16 14 {3} 3 -/16 /18/#/54/1/58/18/#/56/1/18 3 {4} 4 -/18/#/54/1/58/18/#/56/1/18 /20/#/53/1/60 15 {5} 5 -/20/#/53/1/60 /22/#/54/1/62/22/#/56/1/22 8 {1} 1 -/22/#/54/1/62/22/#/56/1/22 /24 16 {2} 2 -/24 /26/#/54/1/66/26/#/56/1/26 4 {3} 3 -/26/#/54/1/66/26/#/56/1/26 /28/#/53/1/68 17 {4} 4 -/28/#/53/1/68 /30/#/54/1/70/30/#/56/1/30 9 {5} 5 -/30/#/54/1/70/30/#/56/1/30 /32 18 {1} 1 -/32 /34/#/54/1/74/34/#/56/1/34 5 {2} 2 -/34/#/54/1/74/34/#/56/1/34 /36/#/53/1/76 19 {3} 3 -/36/#/53/1/76 /38/#/54/1/78/38/#/56/1/38 10 {4} 4 -/38/#/54/1/78/38/#/56/1/38 NULL 20 {5} 5 +NULL /2/#/56/1/42/2/#/58/1/2 1 {1} 1 +/2/#/56/1/42/2/#/58/1/2 /4/#/55/1/44 11 {2} 2 +/4/#/55/1/44 /6/#/56/1/46/6/#/58/1/6 6 {3} 3 +/6/#/56/1/46/6/#/58/1/6 /8 12 {4} 4 +/8 /10/#/56/1/50/10/#/58/1/10 2 {5} 5 +/10/#/56/1/50/10/#/58/1/10 /12/#/55/1/52 13 {1} 1 +/12/#/55/1/52 /14/#/56/1/54/14/#/58/1/14 7 {2} 2 +/14/#/56/1/54/14/#/58/1/14 /16 14 {3} 3 +/16 /18/#/56/1/58/18/#/58/1/18 3 {4} 4 +/18/#/56/1/58/18/#/58/1/18 /20/#/55/1/60 15 {5} 5 +/20/#/55/1/60 /22/#/56/1/62/22/#/58/1/22 8 {1} 1 +/22/#/56/1/62/22/#/58/1/22 /24 16 {2} 2 +/24 /26/#/56/1/66/26/#/58/1/26 4 {3} 3 +/26/#/56/1/66/26/#/58/1/26 /28/#/55/1/68 17 {4} 4 +/28/#/55/1/68 /30/#/56/1/70/30/#/58/1/30 9 {5} 5 +/30/#/56/1/70/30/#/58/1/30 /32 18 {1} 1 +/32 /34/#/56/1/74/34/#/58/1/34 5 {2} 2 +/34/#/56/1/74/34/#/58/1/34 /36/#/55/1/76 19 {3} 3 +/36/#/55/1/76 /38/#/56/1/78/38/#/58/1/38 10 {4} 4 +/38/#/56/1/78/38/#/58/1/38 NULL 20 {5} 5 statement ok SET CLUSTER SETTING sql.distsql.interleaved_joins.enabled = true; @@ -443,7 +443,7 @@ render · · │ spans /11-/13/# /19-/21/# /31-/33/# └── scan · · · table grandchild2@primary -· spans /11/#/54/1-/13/#/54/2 /19/#/54/1-/21/#/54/2 /31/#/54/1-/33/#/54/2 +· spans /11/#/56/1-/13/#/56/2 /19/#/56/1-/21/#/56/2 /31/#/56/1-/33/#/56/2 # Swap parent1 and grandchild2 positions. query IIIIII rowsort,colnames @@ -487,7 +487,7 @@ render · · │ mergeJoinOrder +"(pid1=pid1)" ├── scan · · │ table grandchild2@primary - │ spans /11/#/54/1-/13/#/54/2 /19/#/54/1-/21/#/54/2 /31/#/54/1-/33/#/54/2 + │ spans /11/#/56/1-/13/#/56/2 /19/#/56/1-/21/#/56/2 /31/#/56/1-/33/#/56/2 └── scan · · · table parent1@primary · spans /11-/13/# /19-/21/# /31-/33/# diff --git a/pkg/sql/logictest/testdata/logic_test/join b/pkg/sql/logictest/testdata/logic_test/join index 90253d2b3703..254e24a883ca 100644 --- a/pkg/sql/logictest/testdata/logic_test/join +++ b/pkg/sql/logictest/testdata/logic_test/join @@ -839,7 +839,7 @@ SELECT "Level", "Type", "Field", "Description" FROM [EXPLAIN (VERBOSE) SELECT 10 · type inner 10 · equality (refobjid) = (oid) 11 filter · · -11 · filter (dep.classid = 4061301040) AND (dep.refclassid = 2431470471) +11 · filter (dep.classid = 139623798) AND (dep.refclassid = 1411792157) 11 filter · · 11 · filter pkic.relkind = 'i' diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index d5cb3906f827..7cadd8ffd73e 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -185,10 +185,10 @@ query OTOT colnames SELECT * FROM pg_catalog.pg_namespace ---- oid nspname nspowner nspacl -2770537123 crdb_internal NULL NULL -711679804 information_schema NULL NULL -1809486327 pg_catalog NULL NULL -1692868363 public NULL NULL +2810313165 crdb_internal NULL NULL +2902531810 information_schema NULL NULL +1462631877 pg_catalog NULL NULL +2397796629 public NULL NULL ## pg_catalog.pg_database @@ -199,8 +199,10 @@ ORDER BY oid ---- oid datname datdba encoding datcollate datctype datistemplate datallowconn 381876367 system NULL 6 en_US.utf8 en_US.utf8 false true -437457361 constraint_db NULL 6 en_US.utf8 en_US.utf8 false true -1965331359 test NULL 6 en_US.utf8 en_US.utf8 false true +2069902775 constraint_db NULL 6 en_US.utf8 en_US.utf8 false true +2326011399 postgres NULL 6 en_US.utf8 en_US.utf8 false true +2754439556 defaultdb NULL 6 en_US.utf8 en_US.utf8 false true +3819194709 test NULL 6 en_US.utf8 en_US.utf8 false true query OTIOIIOT colnames SELECT oid, datname, datconnlimit, datlastsysoid, datfrozenxid, datminmxid, dattablespace, datacl @@ -209,8 +211,10 @@ ORDER BY oid ---- oid datname datconnlimit datlastsysoid datfrozenxid datminmxid dattablespace datacl 381876367 system -1 NULL NULL NULL 0 NULL -437457361 constraint_db -1 NULL NULL NULL 0 NULL -1965331359 test -1 NULL NULL NULL 0 NULL +2069902775 constraint_db -1 NULL NULL NULL 0 NULL +2326011399 postgres -1 NULL NULL NULL 0 NULL +2754439556 defaultdb -1 NULL NULL NULL 0 NULL +3819194709 test -1 NULL NULL NULL 0 NULL ## pg_catalog.pg_tables @@ -259,17 +263,17 @@ JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = 'public' ---- oid relname relnamespace reltype relowner relam relfilenode reltablespace -1509766457 t1 3969441927 0 NULL NULL 0 0 -3075386613 primary 3969441927 0 NULL NULL 0 0 -3075386614 t1_a_key 3969441927 0 NULL NULL 0 0 -3075386615 index_key 3969441927 0 NULL NULL 0 0 -1275321073 t2 3969441927 0 NULL NULL 0 0 -4026878981 primary 3969441927 0 NULL NULL 0 0 -4026878982 t2_t1_id_idx 3969441927 0 NULL NULL 0 0 -1308729185 t3 3969441927 0 NULL NULL 0 0 -126881509 primary 3969441927 0 NULL NULL 0 0 -126881510 t3_a_b_idx 3969441927 0 NULL NULL 0 0 -1543910075 v1 3969441927 0 NULL NULL 0 0 +4183203597 t1 393119649 0 NULL NULL 0 0 +586319997 primary 393119649 0 NULL NULL 0 0 +586319998 t1_a_key 393119649 0 NULL NULL 0 0 +586319999 index_key 393119649 0 NULL NULL 0 0 +192646233 t2 393119649 0 NULL NULL 0 0 +2761941313 primary 393119649 0 NULL NULL 0 0 +2761941314 t2_t1_id_idx 393119649 0 NULL NULL 0 0 +226054345 t3 393119649 0 NULL NULL 0 0 +4084598993 primary 393119649 0 NULL NULL 0 0 +4084598994 t3_a_b_idx 393119649 0 NULL NULL 0 0 +4218730311 v1 393119649 0 NULL NULL 0 0 query TIRIOBBT colnames SELECT relname, relpages, reltuples, relallvisible, reltoastrelid, relhasindex, relisshared, relpersistence @@ -338,25 +342,25 @@ JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = 'public' ---- attrelid relname attname atttypid attstattarget attlen attnum attndims attcacheoff -1509766457 t1 p 701 0 8 1 0 -1 -1509766457 t1 a 20 0 8 2 0 -1 -1509766457 t1 b 20 0 8 3 0 -1 -1509766457 t1 c 20 0 8 4 0 -1 -3075386613 primary p 701 0 8 1 0 -1 -3075386614 t1_a_key a 20 0 8 1 0 -1 -3075386615 index_key b 20 0 8 1 0 -1 -3075386615 index_key c 20 0 8 2 0 -1 -1275321073 t2 t1_id 20 0 8 1 0 -1 -4026878982 t2_t1_id_idx t1_id 20 0 8 1 0 -1 -1308729185 t3 a 20 0 8 1 0 -1 -1308729185 t3 b 20 0 8 2 0 -1 -1308729185 t3 c 25 0 -1 3 0 -1 -126881510 t3_a_b_idx a 20 0 8 1 0 -1 -126881510 t3_a_b_idx b 20 0 8 2 0 -1 -1543910075 v1 p 701 0 8 1 0 -1 -1543910075 v1 a 20 0 8 2 0 -1 -1543910075 v1 b 20 0 8 3 0 -1 -1543910075 v1 c 20 0 8 4 0 -1 +4183203597 t1 p 701 0 8 1 0 -1 +4183203597 t1 a 20 0 8 2 0 -1 +4183203597 t1 b 20 0 8 3 0 -1 +4183203597 t1 c 20 0 8 4 0 -1 +586319997 primary p 701 0 8 1 0 -1 +586319998 t1_a_key a 20 0 8 1 0 -1 +586319999 index_key b 20 0 8 1 0 -1 +586319999 index_key c 20 0 8 2 0 -1 +192646233 t2 t1_id 20 0 8 1 0 -1 +2761941314 t2_t1_id_idx t1_id 20 0 8 1 0 -1 +226054345 t3 a 20 0 8 1 0 -1 +226054345 t3 b 20 0 8 2 0 -1 +226054345 t3 c 25 0 -1 3 0 -1 +4084598994 t3_a_b_idx a 20 0 8 1 0 -1 +4084598994 t3_a_b_idx b 20 0 8 2 0 -1 +4218730311 v1 p 701 0 8 1 0 -1 +4218730311 v1 a 20 0 8 2 0 -1 +4218730311 v1 b 20 0 8 3 0 -1 +4218730311 v1 c 20 0 8 4 0 -1 query TTIBTTBB colnames SELECT c.relname, attname, atttypmod, attbyval, attstorage, attalign, attnotnull, atthasdef @@ -485,8 +489,8 @@ JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = 'public' ---- oid relname adrelid adnum adbin adsrc -2546105486 t1 1509766457 4 12:::INT 12:::INT -2449897171 t3 1308729185 3 'FOO':::STRING 'FOO':::STRING +1371742922 t1 4183203597 4 12:::INT 12:::INT +1821466931 t3 226054345 3 'FOO':::STRING 'FOO':::STRING ## pg_catalog.pg_indexes @@ -496,13 +500,13 @@ FROM pg_catalog.pg_indexes WHERE schemaname = 'public' ---- crdb_oid schemaname tablename indexname tablespace -3075386613 public t1 primary NULL -3075386614 public t1 t1_a_key NULL -3075386615 public t1 index_key NULL -4026878981 public t2 primary NULL -4026878982 public t2 t2_t1_id_idx NULL -126881509 public t3 primary NULL -126881510 public t3 t3_a_b_idx NULL +586319997 public t1 primary NULL +586319998 public t1 t1_a_key NULL +586319999 public t1 index_key NULL +2761941313 public t2 primary NULL +2761941314 public t2 t2_t1_id_idx NULL +4084598993 public t3 primary NULL +4084598994 public t3 t3_a_b_idx NULL query OTTT colnames SELECT crdb_oid, tablename, indexname, indexdef @@ -510,13 +514,13 @@ FROM pg_catalog.pg_indexes WHERE schemaname = 'public' ---- crdb_oid tablename indexname indexdef -3075386613 t1 primary CREATE UNIQUE INDEX "primary" ON constraint_db.public.t1 (p ASC) -3075386614 t1 t1_a_key CREATE UNIQUE INDEX t1_a_key ON constraint_db.public.t1 (a ASC) -3075386615 t1 index_key CREATE UNIQUE INDEX index_key ON constraint_db.public.t1 (b ASC, c ASC) -4026878981 t2 primary CREATE UNIQUE INDEX "primary" ON constraint_db.public.t2 (rowid ASC) -4026878982 t2 t2_t1_id_idx CREATE INDEX t2_t1_id_idx ON constraint_db.public.t2 (t1_id ASC) -126881509 t3 primary CREATE UNIQUE INDEX "primary" ON constraint_db.public.t3 (rowid ASC) -126881510 t3 t3_a_b_idx CREATE INDEX t3_a_b_idx ON constraint_db.public.t3 (a ASC, b DESC) STORING (c) +586319997 t1 primary CREATE UNIQUE INDEX "primary" ON constraint_db.public.t1 (p ASC) +586319998 t1 t1_a_key CREATE UNIQUE INDEX t1_a_key ON constraint_db.public.t1 (a ASC) +586319999 t1 index_key CREATE UNIQUE INDEX index_key ON constraint_db.public.t1 (b ASC, c ASC) +2761941313 t2 primary CREATE UNIQUE INDEX "primary" ON constraint_db.public.t2 (rowid ASC) +2761941314 t2 t2_t1_id_idx CREATE INDEX t2_t1_id_idx ON constraint_db.public.t2 (t1_id ASC) +4084598993 t3 primary CREATE UNIQUE INDEX "primary" ON constraint_db.public.t3 (rowid ASC) +4084598994 t3 t3_a_b_idx CREATE INDEX t3_a_b_idx ON constraint_db.public.t3 (a ASC, b DESC) STORING (c) ## pg_catalog.pg_index @@ -526,8 +530,8 @@ from pg_catalog.pg_index WHERE indnatts = 2 ---- indexrelid indrelid indnatts indisunique indisprimary indisexclusion -3075386615 1509766457 2 true false false -126881510 1308729185 2 false false false +586319999 4183203597 2 true false false +4084598994 226054345 2 false false false query OBBBBB colnames SELECT indexrelid, indimmediate, indisclustered, indisvalid, indcheckxmin, indisready @@ -535,8 +539,8 @@ from pg_catalog.pg_index WHERE indnatts = 2 ---- indexrelid indimmediate indisclustered indisvalid indcheckxmin indisready -3075386615 true false true false false -126881510 false false true false false +586319999 true false true false false +4084598994 false false true false false query OOBBTIIITT colnames SELECT indexrelid, indrelid, indislive, indisreplident, indkey, indcollation, indclass, indoption, indexprs, indpred @@ -544,8 +548,8 @@ from pg_catalog.pg_index WHERE indnatts = 2 ---- indexrelid indrelid indislive indisreplident indkey indcollation indclass indoption indexprs indpred -3075386615 1509766457 true false 3 4 0 0 0 NULL NULL -126881510 1308729185 true false 1 2 0 0 0 NULL NULL +586319999 4183203597 true false 3 4 0 0 0 NULL NULL +4084598994 226054345 true false 1 2 0 0 0 NULL NULL ## pg_catalog.pg_collation @@ -554,7 +558,7 @@ SELECT * FROM pg_collation WHERE collname='en-US' ---- oid collname collnamespace collowner collencoding collcollate collctype -1661428263 en-US 3969441927 NULL 6 NULL NULL +1661428263 en-US 393119649 NULL 6 NULL NULL ## pg_catalog.pg_constraint ## @@ -569,12 +573,12 @@ WHERE n.nspname = 'public' ORDER BY con.oid ---- oid conname connamespace contype -302390735 check_b 3969441927 c -378079884 index_key 3969441927 u -378079885 t1_a_key 3969441927 u -2517385387 fk 3969441927 f -2704194502 fk 3969441927 f -3077848825 primary 3969441927 p +706565544 index_key 393119649 u +706565545 t1_a_key 393119649 u +1705475931 check_b 393119649 c +1968296057 fk 393119649 f +2304211364 fk 393119649 f +2922443201 primary 393119649 p query TTBBBOOO colnames SELECT conname, contype, condeferrable, condeferred, convalidated, conrelid, contypid, conindid @@ -584,12 +588,12 @@ WHERE n.nspname = 'public' ORDER BY con.oid ---- conname contype condeferrable condeferred convalidated conrelid contypid conindid -check_b c false false true 1308729185 0 0 -index_key u false false true 1509766457 0 3075386615 -t1_a_key u false false true 1509766457 0 3075386614 -fk f false false true 1275321073 0 3075386614 -fk f false false true 1308729185 0 3075386615 -primary p false false true 1509766457 0 3075386613 +index_key u false false true 4183203597 0 586319999 +t1_a_key u false false true 4183203597 0 586319998 +check_b c false false true 226054345 0 0 +fk f false false true 192646233 0 586319998 +fk f false false true 226054345 0 586319999 +primary p false false true 4183203597 0 586319997 query T SELECT conname @@ -607,9 +611,9 @@ WHERE n.nspname = 'public' AND contype IN ('c', 'p', 'u') ORDER BY con.oid ---- conname confrelid confupdtype confdeltype confmatchtype -check_b 0 NULL NULL NULL index_key 0 NULL NULL NULL t1_a_key 0 NULL NULL NULL +check_b 0 NULL NULL NULL primary 0 NULL NULL NULL query TOTTT colnames @@ -620,8 +624,8 @@ WHERE n.nspname = 'public' AND contype = 'f' ORDER BY con.oid ---- conname confrelid confupdtype confdeltype confmatchtype -fk 1509766457 a a s -fk 1509766457 a a s +fk 4183203597 a a s +fk 4183203597 a a s query TBIBT colnames SELECT conname, conislocal, coninhcount, connoinherit, conkey @@ -631,9 +635,9 @@ WHERE n.nspname = 'public' ORDER BY con.oid ---- conname conislocal coninhcount connoinherit conkey -check_b true 0 true {2} index_key true 0 true {3,4} t1_a_key true 0 true {2} +check_b true 0 true {2} fk true 0 true {1} fk true 0 true {1,2} primary true 0 true {1} @@ -646,9 +650,9 @@ WHERE n.nspname = 'public' AND contype IN ('c', 'p', 'u') ORDER BY con.oid ---- conname confkey conpfeqop conppeqop conffeqop conexclop conbin consrc -check_b NULL NULL NULL NULL NULL b > 11 b > 11 index_key NULL NULL NULL NULL NULL NULL NULL t1_a_key NULL NULL NULL NULL NULL NULL NULL +check_b NULL NULL NULL NULL NULL b > 11 b > 11 primary NULL NULL NULL NULL NULL NULL NULL query TTTTTTTT colnames @@ -669,9 +673,9 @@ SELECT classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype FROM pg_catalog.pg_depend ORDER BY objid ---- -classid objid objsubid refclassid refobjid refobjsubid deptype -1539915808 2517385387 0 2523326295 3075386614 0 n -1539915808 2704194502 0 2523326295 3075386615 0 n +classid objid objsubid refclassid refobjid refobjsubid deptype +2416812286 1968296057 0 2990889189 586319998 0 n +2416812286 2304211364 0 2990889189 586319999 0 n # All entries in pg_depend are dependency links from the pg_constraint system # table to the pg_class system table. @@ -683,7 +687,7 @@ JOIN pg_class cla ON classid=cla.oid JOIN pg_class refcla ON refclassid=refcla.oid ---- classid refclassid tablename reftablename -1539915808 2523326295 pg_constraint pg_class +2416812286 2990889189 pg_constraint pg_class # All entries in pg_depend are foreign key constraints that reference an index # in pg_class. @@ -718,57 +722,57 @@ FROM pg_catalog.pg_type ORDER BY oid ---- oid typname typnamespace typowner typlen typbyval typtype -16 bool 3572887043 NULL 1 true b -17 bytea 3572887043 NULL -1 false b -19 name 3572887043 NULL -1 false b -20 int8 3572887043 NULL 8 true b -21 int2 3572887043 NULL 8 true b -22 int2vector 3572887043 NULL -1 false b -23 int4 3572887043 NULL 8 true b -24 regproc 3572887043 NULL 8 true b -25 text 3572887043 NULL -1 false b -26 oid 3572887043 NULL 8 true b -30 oidvector 3572887043 NULL -1 false b -700 float4 3572887043 NULL 8 true b -701 float8 3572887043 NULL 8 true b -869 inet 3572887043 NULL 24 true b -1000 _bool 3572887043 NULL -1 false b -1001 _bytea 3572887043 NULL -1 false b -1003 _name 3572887043 NULL -1 false b -1005 _int2 3572887043 NULL -1 false b -1007 _int4 3572887043 NULL -1 false b -1009 _text 3572887043 NULL -1 false b -1015 _varchar 3572887043 NULL -1 false b -1016 _int8 3572887043 NULL -1 false b -1021 _float4 3572887043 NULL -1 false b -1022 _float8 3572887043 NULL -1 false b -1028 _oid 3572887043 NULL -1 false b -1041 _inet 3572887043 NULL -1 false b -1043 varchar 3572887043 NULL -1 false b -1082 date 3572887043 NULL 8 true b -1083 time 3572887043 NULL 8 true b -1114 timestamp 3572887043 NULL 24 true b -1115 _timestamp 3572887043 NULL -1 false b -1182 _date 3572887043 NULL -1 false b -1183 _time 3572887043 NULL -1 false b -1184 timestamptz 3572887043 NULL 24 true b -1185 _timestamptz 3572887043 NULL -1 false b -1186 interval 3572887043 NULL 24 true b -1187 _interval 3572887043 NULL -1 false b -1231 _numeric 3572887043 NULL -1 false b -1266 timetz 3572887043 NULL 16 true b -1270 _timetz 3572887043 NULL -1 false b -1700 numeric 3572887043 NULL -1 false b -2202 regprocedure 3572887043 NULL 8 true b -2205 regclass 3572887043 NULL 8 true b -2206 regtype 3572887043 NULL 8 true b -2249 record 3572887043 NULL 0 true p -2277 anyarray 3572887043 NULL -1 false p -2283 anyelement 3572887043 NULL -1 false p -2950 uuid 3572887043 NULL 16 true b -2951 _uuid 3572887043 NULL -1 false b -3802 jsonb 3572887043 NULL -1 false b -4089 regnamespace 3572887043 NULL 8 true b +16 bool 2980797153 NULL 1 true b +17 bytea 2980797153 NULL -1 false b +19 name 2980797153 NULL -1 false b +20 int8 2980797153 NULL 8 true b +21 int2 2980797153 NULL 8 true b +22 int2vector 2980797153 NULL -1 false b +23 int4 2980797153 NULL 8 true b +24 regproc 2980797153 NULL 8 true b +25 text 2980797153 NULL -1 false b +26 oid 2980797153 NULL 8 true b +30 oidvector 2980797153 NULL -1 false b +700 float4 2980797153 NULL 8 true b +701 float8 2980797153 NULL 8 true b +869 inet 2980797153 NULL 24 true b +1000 _bool 2980797153 NULL -1 false b +1001 _bytea 2980797153 NULL -1 false b +1003 _name 2980797153 NULL -1 false b +1005 _int2 2980797153 NULL -1 false b +1007 _int4 2980797153 NULL -1 false b +1009 _text 2980797153 NULL -1 false b +1015 _varchar 2980797153 NULL -1 false b +1016 _int8 2980797153 NULL -1 false b +1021 _float4 2980797153 NULL -1 false b +1022 _float8 2980797153 NULL -1 false b +1028 _oid 2980797153 NULL -1 false b +1041 _inet 2980797153 NULL -1 false b +1043 varchar 2980797153 NULL -1 false b +1082 date 2980797153 NULL 8 true b +1083 time 2980797153 NULL 8 true b +1114 timestamp 2980797153 NULL 24 true b +1115 _timestamp 2980797153 NULL -1 false b +1182 _date 2980797153 NULL -1 false b +1183 _time 2980797153 NULL -1 false b +1184 timestamptz 2980797153 NULL 24 true b +1185 _timestamptz 2980797153 NULL -1 false b +1186 interval 2980797153 NULL 24 true b +1187 _interval 2980797153 NULL -1 false b +1231 _numeric 2980797153 NULL -1 false b +1266 timetz 2980797153 NULL 16 true b +1270 _timetz 2980797153 NULL -1 false b +1700 numeric 2980797153 NULL -1 false b +2202 regprocedure 2980797153 NULL 8 true b +2205 regclass 2980797153 NULL 8 true b +2206 regtype 2980797153 NULL 8 true b +2249 record 2980797153 NULL 0 true p +2277 anyarray 2980797153 NULL -1 false p +2283 anyelement 2980797153 NULL -1 false p +2950 uuid 2980797153 NULL 16 true b +2951 _uuid 2980797153 NULL -1 false b +3802 jsonb 2980797153 NULL -1 false b +4089 regnamespace 2980797153 NULL 8 true b query OTTBBTOOO colnames SELECT oid, typname, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray @@ -1010,10 +1014,10 @@ FROM pg_catalog.pg_proc WHERE proname='substring' ---- proname pronamespace proowner prolang procost prorows provariadic -substring 3572887043 NULL 0 NULL NULL 0 -substring 3572887043 NULL 0 NULL NULL 0 -substring 3572887043 NULL 0 NULL NULL 0 -substring 3572887043 NULL 0 NULL NULL 0 +substring 2980797153 NULL 0 NULL NULL 0 +substring 2980797153 NULL 0 NULL NULL 0 +substring 2980797153 NULL 0 NULL NULL 0 +substring 2980797153 NULL 0 NULL NULL 0 query TTBBBB colnames SELECT proname, protransform, proisagg, proiswindow, prosecdef, proleakproof @@ -1266,8 +1270,8 @@ query OOIIIIIB colnames SELECT * FROM pg_catalog.pg_sequence ---- seqrelid seqtypid seqstart seqincrement seqmax seqmin seqcache seqcycle -1244912846 20 1 1 9223372036854775807 1 1 false -758146164 20 6 2 10 5 1 false +162412526 20 1 1 9223372036854775807 1 1 false +2864600840 20 6 2 10 5 1 false statement ok DROP DATABASE seq @@ -1286,7 +1290,7 @@ query OTOOTBBOOOOOOOO colnames SELECT * FROM pg_catalog.pg_operator where oprname='+' and oprleft='float8'::regtype ---- oid oprname oprnamespace oprowner oprkind oprcanmerge oprcanhash oprleft oprright oprresult oprcom oprnegate oprcode oprrest oprjoin -3695865198 + 3572887043 NULL b false false 701 701 701 NULL NULL NULL NULL NULL +3695865198 + 2980797153 NULL b false false 701 701 701 NULL NULL NULL NULL NULL # Verify proper functionality of system information functions. @@ -1310,8 +1314,8 @@ JOIN pg_catalog.pg_class c ON def.adrelid = c.oid JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = 'public' ---- -2546105486 t1 12:::INT -2449897171 t3 'FOO':::STRING +1371742922 t1 12:::INT +1821466931 t3 'FOO':::STRING # Verify that a set database shows tables from that database for a non-root # user, when that user has permissions. diff --git a/pkg/sql/logictest/testdata/logic_test/pgoidtype b/pkg/sql/logictest/testdata/logic_test/pgoidtype index 3272547ceac5..8d41a9b0d974 100644 --- a/pkg/sql/logictest/testdata/logic_test/pgoidtype +++ b/pkg/sql/logictest/testdata/logic_test/pgoidtype @@ -68,19 +68,19 @@ pg_constraint pg_constraint query OO SELECT 'pg_constraint '::REGCLASS, '"pg_constraint"'::REGCLASS::OID ---- -pg_constraint 4061301040 +pg_constraint 139623798 query O SELECT 4061301040::REGCLASS ---- -pg_constraint +4061301040 query OOIOT SELECT oid, oid::regclass, oid::regclass::int, oid::regclass::int::regclass, oid::regclass::text FROM pg_class WHERE relname = 'pg_constraint' ---- -4061301040 pg_constraint 4061301040 pg_constraint pg_constraint +139623798 pg_constraint 139623798 pg_constraint pg_constraint query OOOO SELECT 'upper'::REGPROC, 'upper'::REGPROCEDURE, 'pg_catalog.upper'::REGPROCEDURE, 'upper'::REGPROC::OID @@ -126,7 +126,7 @@ array_in array_in array_in array_in query OO SELECT 'public'::REGNAMESPACE, 'public'::REGNAMESPACE::OID ---- -public 1692868363 +public 2397796629 query OO SELECT 'bool'::REGTYPE, 'bool'::REGTYPE::OID @@ -167,7 +167,7 @@ pg_constraint query OO SELECT ('pg_constraint')::REGCLASS, ('pg_constraint')::REGCLASS::OID ---- -pg_constraint 4061301040 +pg_constraint 139623798 ## Test visibility of pg_* via oid casts. diff --git a/pkg/sql/logictest/testdata/logic_test/ranges b/pkg/sql/logictest/testdata/logic_test/ranges index bb61ed0b429d..112ada89d748 100644 --- a/pkg/sql/logictest/testdata/logic_test/ranges +++ b/pkg/sql/logictest/testdata/logic_test/ranges @@ -154,8 +154,8 @@ NULL /1 {1} 1 /1 /5/1 {3,4} 3 /5/1 /5/2 {1,2,3} 1 /5/2 /5/3 {2,3,5} 5 -/5/3 /7/8/#/52/1/9 {1,2,4} 4 -/7/8/#/52/1/9 /10 {1,2,4} 4 +/5/3 /7/8/#/54/1/9 {1,2,4} 4 +/7/8/#/54/1/9 /10 {1,2,4} 4 /10 NULL {1} 1 statement ok @@ -169,23 +169,23 @@ NULL /1 {1} 1 /1 /5/1 {3,4} 3 /5/1 /5/2 {1,2,3} 1 /5/2 /5/3 {2,3,5} 5 -/5/3 /7/8/#/52/1/9 {1,2,4} 4 -/7/8/#/52/1/9 /10 {1,2,4} 4 +/5/3 /7/8/#/54/1/9 {1,2,4} 4 +/7/8/#/54/1/9 /10 {1,2,4} 4 /10 /11 {1} 1 /11 NULL {1} 1 query TTTI colnames SELECT "Start Key", "End Key", "Replicas", "Lease Holder" FROM [SHOW TESTING_RANGES FROM TABLE t] ---- -Start Key End Key Replicas Lease Holder -NULL /1 {1} 1 -/1 /5/1 {3,4} 3 -/5/1 /5/2 {1,2,3} 1 -/5/2 /5/3 {2,3,5} 5 -/5/3 /7/8/#/52/1/9 {1,2,4} 4 -/7/8/#/52/1/9 /10 {1,2,4} 4 -/10 /11 {1} 1 -/11 NULL {1} 1 +Start Key End Key Replicas Lease Holder +NULL /1 {1} 1 +/1 /5/1 {3,4} 3 +/5/1 /5/2 {1,2,3} 1 +/5/2 /5/3 {2,3,5} 5 +/5/3 /7/8/#/54/1/9 {1,2,4} 4 +/7/8/#/54/1/9 /10 {1,2,4} 4 +/10 /11 {1} 1 +/11 NULL {1} 1 statement ok @@ -203,8 +203,8 @@ NULL /1 {1} 1 /1 /5/1 {3,4} 3 /5/1 /5/2 {1,2,3} 1 /5/2 /5/3 {2,3,5} 5 -/5/3 /7/8/#/52/1/9 {1,2,4} 4 -/7/8/#/52/1/9 /10 {1,2,4} 4 +/5/3 /7/8/#/54/1/9 {1,2,4} 4 +/7/8/#/54/1/9 /10 {1,2,4} 4 /10 /11 {1} 1 /11 NULL {1} 1 @@ -219,11 +219,11 @@ NULL /1 {1} 1 /1 /5/1 {3,4} 3 /5/1 /5/2 {1,2,3} 1 /5/2 /5/3 {2,3,5} 5 -/5/3 /7/8/#/52/1/9 {1,2,4} 4 -/7/8/#/52/1/9 /10 {1,2,4} 4 +/5/3 /7/8/#/54/1/9 {1,2,4} 4 +/7/8/#/54/1/9 /10 {1,2,4} 4 /10 /11 {1} 1 -/11 /15/16/#/53/2 {1} 1 -/15/16/#/53/2 NULL {1} 1 +/11 /15/16/#/55/2 {1} 1 +/15/16/#/55/2 NULL {1} 1 statement error too many columns in SPLIT AT data ALTER TABLE t SPLIT AT VALUES (1, 2, 3) @@ -276,19 +276,19 @@ query ITTTTTTTTI colnames SELECT * FROM crdb_internal.ranges ---- range_id start_key start_pretty end_key end_pretty database table index replicas lease_holder - 1 · /Min [187 137 137] /Table/51/1/1 · · · {1} 1 - 2 [187 137 137] /Table/51/1/1 [187 137 141 137] /Table/51/1/5/1 test t · {4,3} 3 - 11 [187 137 141 137] /Table/51/1/5/1 [187 137 141 138] /Table/51/1/5/2 test t · {3,1,2} 1 - 12 [187 137 141 138] /Table/51/1/5/2 [187 137 141 139] /Table/51/1/5/3 test t · {3,5,2} 5 - 13 [187 137 141 139] /Table/51/1/5/3 [187 137 143 144 254 188 137 145] /Table/51/1/7/8/#/52/1/9 test t · {4,1,2} 4 - 14 [187 137 143 144 254 188 137 145] /Table/51/1/7/8/#/52/1/9 [187 137 146] /Table/51/1/10 test t · {4,1,2} 4 - 3 [187 137 146] /Table/51/1/10 [187 137 147] /Table/51/1/11 test t · {1} 1 - 8 [187 137 147] /Table/51/1/11 [187 137 151 152 254 189 138] /Table/51/1/15/16/#/53/2 test t · {1} 1 - 9 [187 137 151 152 254 189 138] /Table/51/1/15/16/#/53/2 [187 138 144] /Table/51/2/8 test t · {1} 1 - 6 [187 138 144] /Table/51/2/8 [187 138 145] /Table/51/2/9 test t idx {1} 1 - 7 [187 138 145] /Table/51/2/9 [187 138 236 137] /Table/51/2/100/1 test t idx {1} 1 - 4 [187 138 236 137] /Table/51/2/100/1 [187 138 236 186] /Table/51/2/100/50 test t idx {3} 3 - 5 [187 138 236 186] /Table/51/2/100/50 [193 137 136] /Table/57/1/0 test t idx {1} 1 - 10 [193 137 136] /Table/57/1/0 [194 137 246 123] /Table/58/1/123 · b · {1} 1 - 21 [194 137 246 123] /Table/58/1/123 [194 138 136] /Table/58/2/0 d c · {1} 1 - 22 [194 138 136] /Table/58/2/0 [255 255] /Max d c c_i_idx {1} 1 +1 · /Min [189 137 137] /Table/53/1/1 · · · {1} 1 +2 [189 137 137] /Table/53/1/1 [189 137 141 137] /Table/53/1/5/1 test t · {4,3} 3 +11 [189 137 141 137] /Table/53/1/5/1 [189 137 141 138] /Table/53/1/5/2 test t · {3,1,2} 1 +12 [189 137 141 138] /Table/53/1/5/2 [189 137 141 139] /Table/53/1/5/3 test t · {3,5,2} 5 +13 [189 137 141 139] /Table/53/1/5/3 [189 137 143 144 254 190 137 145] /Table/53/1/7/8/#/54/1/9 test t · {4,1,2} 4 +14 [189 137 143 144 254 190 137 145] /Table/53/1/7/8/#/54/1/9 [189 137 146] /Table/53/1/10 test t · {4,1,2} 4 +3 [189 137 146] /Table/53/1/10 [189 137 147] /Table/53/1/11 test t · {1} 1 +8 [189 137 147] /Table/53/1/11 [189 137 151 152 254 191 138] /Table/53/1/15/16/#/55/2 test t · {1} 1 +9 [189 137 151 152 254 191 138] /Table/53/1/15/16/#/55/2 [189 138 144] /Table/53/2/8 test t · {1} 1 +6 [189 138 144] /Table/53/2/8 [189 138 145] /Table/53/2/9 test t idx {1} 1 +7 [189 138 145] /Table/53/2/9 [189 138 236 137] /Table/53/2/100/1 test t idx {1} 1 +4 [189 138 236 137] /Table/53/2/100/1 [189 138 236 186] /Table/53/2/100/50 test t idx {3} 3 +5 [189 138 236 186] /Table/53/2/100/50 [195 137 136] /Table/59/1/0 test t idx {1} 1 +10 [195 137 136] /Table/59/1/0 [196 137 246 123] /Table/60/1/123 · b · {1} 1 +21 [196 137 246 123] /Table/60/1/123 [196 138 136] /Table/60/2/0 d c · {1} 1 +22 [196 138 136] /Table/60/2/0 [255 255] /Max d c c_i_idx {1} 1 diff --git a/pkg/sql/logictest/testdata/logic_test/rename_database b/pkg/sql/logictest/testdata/logic_test/rename_database index 65420d858a60..4d9c34dcea6f 100644 --- a/pkg/sql/logictest/testdata/logic_test/rename_database +++ b/pkg/sql/logictest/testdata/logic_test/rename_database @@ -3,6 +3,8 @@ query T SHOW DATABASES ---- +defaultdb +postgres system test @@ -54,6 +56,8 @@ SHOW GRANTS ON DATABASE test query T SHOW DATABASES ---- +defaultdb +postgres system u @@ -136,3 +140,10 @@ CREATE VIEW v.v AS SELECT k,v FROM v.kv statement error cannot rename database because view "v" depends on table "kv" ALTER DATABASE v RENAME TO u + +# Check that the default databases can be renamed like any other. +statement ok +ALTER DATABASE defaultdb RENAME TO w; + ALTER DATABASE postgres RENAME TO defaultdb; + ALTER DATABASE w RENAME TO postgres + diff --git a/pkg/sql/logictest/testdata/logic_test/select_tighten_spans b/pkg/sql/logictest/testdata/logic_test/select_tighten_spans index 5b91ef65e652..d6edf791680a 100644 --- a/pkg/sql/logictest/testdata/logic_test/select_tighten_spans +++ b/pkg/sql/logictest/testdata/logic_test/select_tighten_spans @@ -153,8 +153,8 @@ SHOW TESTING_RANGES FROM TABLE p1 ---- Start Key End Key Range ID Replicas Lease Holder NULL /2 1 {1} 1 -/2 /2/1/#/52/1 2 {2} 2 -/2/1/#/52/1 NULL 3 {3} 3 +/2 /2/1/#/54/1 2 {2} 2 +/2/1/#/54/1 NULL 3 {3} 3 # Indexes @@ -174,8 +174,8 @@ SHOW TESTING_RANGES FROM TABLE p2 Start Key End Key Range ID Replicas Lease Holder NULL /0 5 {5} 5 /0 /2 6 {1} 1 -/2 /2/#/53/2 7 {2} 2 -/2/#/53/2 NULL 8 {3} 3 +/2 /2/#/55/2 7 {2} 2 +/2/#/55/2 NULL 8 {3} 3 ############### # Query tests # @@ -310,7 +310,7 @@ EXPLAIN SELECT * FROM c1 WHERE a <= 3 AND b <= 3 ---- scan · · · table c1@primary -· spans -/3/3/#/52/1/# +· spans -/3/3/#/54/1/# query II rowsort SELECT * FROM c1 WHERE a <= 3 AND b <= 3 @@ -368,7 +368,7 @@ EXPLAIN SELECT * FROM p2@p2_id WHERE i >= 1 AND d >= 2 ---- scan · · · table p2@p2_id -· spans /1/#/53/2/2- +· spans /1/#/55/2/2- query II rowsort SELECT * FROM p2@p2_id WHERE i>= 1 AND d >= 2 @@ -385,7 +385,7 @@ EXPLAIN SELECT * FROM p2@p2_id WHERE i <= 6 AND d <= 5 ---- scan · · · table p2@p2_id -· spans -/6/#/53/2/6 +· spans -/6/#/55/2/6 query II rowsort SELECT * FROM p2@p2_id WHERE i <= 6 AND d <= 5 @@ -400,7 +400,7 @@ EXPLAIN SELECT * FROM p2@p2_id WHERE i >= 1 AND d IS NULL ---- scan · · · table p2@p2_id -· spans /1/#/53/2/NULL- +· spans /1/#/55/2/NULL- query II rowsort SELECT * FROM p2@p2_id WHERE i>= 1 AND d IS NULL @@ -416,7 +416,7 @@ EXPLAIN SELECT * FROM p2@p2_id WHERE i >= 1 AND d IS NOT NULL ---- scan · · · table p2@p2_id -· spans /1/#/53/2/!NULL- +· spans /1/#/55/2/!NULL- query II rowsort SELECT * FROM p2@p2_id WHERE i>= 1 AND d IS NOT NULL diff --git a/pkg/sql/logictest/testdata/logic_test/sequences b/pkg/sql/logictest/testdata/logic_test/sequences index 775c8ecb1bf5..d421f50615a2 100644 --- a/pkg/sql/logictest/testdata/logic_test/sequences +++ b/pkg/sql/logictest/testdata/logic_test/sequences @@ -122,7 +122,7 @@ query ITTITTTTTTT colnames SELECT * FROM crdb_internal.create_statements WHERE descriptor_name = 'show_create_test' ---- database_id database_name schema_name descriptor_id descriptor_type descriptor_name create_statement state create_nofks alter_statements validate_statements -50 test public 64 sequence show_create_test CREATE SEQUENCE show_create_test MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1 PUBLIC CREATE SEQUENCE show_create_test MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1 {} {} +52 test public 66 sequence show_create_test CREATE SEQUENCE show_create_test MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1 PUBLIC CREATE SEQUENCE show_create_test MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1 {} {} query TT colnames SHOW CREATE SEQUENCE show_create_test diff --git a/pkg/sql/logictest/testdata/logic_test/show_source b/pkg/sql/logictest/testdata/logic_test/show_source index b28ebeaa6a7d..ae09ccbaf221 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_source +++ b/pkg/sql/logictest/testdata/logic_test/show_source @@ -79,6 +79,8 @@ query T colnames SELECT * FROM [SHOW DATABASES] ---- Database +defaultdb +postgres system test diff --git a/pkg/sql/logictest/testdata/logic_test/show_trace b/pkg/sql/logictest/testdata/logic_test/show_trace index b6161ccf63c3..6ebef1401c03 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_trace +++ b/pkg/sql/logictest/testdata/logic_test/show_trace @@ -62,8 +62,8 @@ dist sender querying next range at /Table/2/1/0/"t"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /System/"desc-idgen" dist sender r1: sending batch 1 Inc to (n1,s1):1 -sql txn CPut /Table/2/1/0/"t"/3/1 -> 51 -sql txn CPut /Table/3/1/51/2/1 -> database: users: > > +sql txn CPut /Table/2/1/0/"t"/3/1 -> 53 +sql txn CPut /Table/3/1/53/2/1 -> database: users: > > dist sender querying next range at /Table/SystemConfigSpan/Start dist sender r1: sending batch 2 CPut, 1 BeginTxn to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"system"/3/1 @@ -102,21 +102,21 @@ SELECT operation, regexp_replace(message, 'wall_time:\d+', 'wall_time:...') as m ---- dist sender querying next range at /Table/2/1/0/"test"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/50/2/1 +dist sender querying next range at /Table/3/1/52/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"t"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/51/2/1 +dist sender querying next range at /Table/3/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/2/1/51/"kv"/3/1 +dist sender querying next range at /Table/2/1/53/"kv"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /System/"desc-idgen" dist sender r1: sending batch 1 Inc to (n1,s1):1 -sql txn CPut /Table/2/1/51/"kv"/3/1 -> 52 -sql txn CPut /Table/3/1/52/2/1 -> table: columns: nullable:false hidden:false > columns: nullable:true hidden:false > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:2 privileges: users: > next_mutation_id:1 format_version:3 state:PUBLIC view_query:"" drop_time:0 replacement_of: > audit_mode:DISABLED > +sql txn CPut /Table/2/1/53/"kv"/3/1 -> 54 +sql txn CPut /Table/3/1/54/2/1 -> table: columns: nullable:false hidden:false > columns: nullable:true hidden:false > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:2 privileges: users: > next_mutation_id:1 format_version:3 state:PUBLIC view_query:"" drop_time:0 replacement_of: > audit_mode:DISABLED > dist sender querying next range at /Table/SystemConfigSpan/Start dist sender r1: sending batch 2 CPut, 1 BeginTxn to (n1,s1):1 -dist sender querying next range at /Table/3/1/51/2/1 +dist sender querying next range at /Table/3/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"system"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 @@ -174,8 +174,8 @@ dist sender querying next range at /Table/3/1/1/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/SystemConfigSpan/Start dist sender r1: sending batch 1 CPut, 1 BeginTxn, 1 InitPut to (n1,s1):1 -starting plan Put /Table/3/1/52/2/1 -> table: columns: nullable:false hidden:false > columns: nullable:true hidden:false > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:3 privileges: users: > mutations: interleave:<> partitioning: type:FORWARD > state:DELETE_ONLY direction:ADD mutation_id:1 rollback:false > next_mutation_id:2 format_version:3 state:PUBLIC view_query:"" mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED > -dist sender querying next range at /Table/3/1/52/2/1 +starting plan Put /Table/3/1/54/2/1 -> table: columns: nullable:false hidden:false > columns: nullable:true hidden:false > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:3 privileges: users: > mutations: interleave:<> partitioning: type:FORWARD > state:DELETE_ONLY direction:ADD mutation_id:1 rollback:false > next_mutation_id:2 format_version:3 state:PUBLIC view_query:"" mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED > +dist sender querying next range at /Table/3/1/54/2/1 dist sender r1: sending batch 1 Put to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"system"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 @@ -205,8 +205,8 @@ INSERT INTO t.kv(k, v) VALUES (1,2); SET tracing=off; SELECT operation, message FROM [SHOW KV TRACE FOR SESSION] ---- -sql txn CPut /Table/52/1/1/0 -> /TUPLE/2:2:Int/2 -dist sender querying next range at /Table/52/1/1/0 +sql txn CPut /Table/54/1/1/0 -> /TUPLE/2:2:Int/2 +dist sender querying next range at /Table/54/1/1/0 dist sender r1: sending batch 1 CPut, 1 BeginTxn, 1 EndTxn, 1 InitPut to (n1,s1):1 @@ -218,8 +218,8 @@ query TT set tracing=off; SELECT operation, message FROM [SHOW KV TRACE FOR SESSION] ---- -sql txn CPut /Table/52/1/1/0 -> /TUPLE/2:2:Int/2 -dist sender querying next range at /Table/52/1/1/0 +sql txn CPut /Table/54/1/1/0 -> /TUPLE/2:2:Int/2 +dist sender querying next range at /Table/54/1/1/0 dist sender r1: sending batch 1 CPut, 1 BeginTxn, 1 EndTxn, 1 InitPut to (n1,s1):1 statement error duplicate key value @@ -230,8 +230,8 @@ query TT set tracing=off; SELECT operation, message FROM [SHOW KV TRACE FOR SESSION] ---- -sql txn CPut /Table/52/1/2/0 -> /TUPLE/2:2:Int/2 -dist sender querying next range at /Table/52/1/2/0 +sql txn CPut /Table/54/1/2/0 -> /TUPLE/2:2:Int/2 +dist sender querying next range at /Table/54/1/2/0 dist sender r1: sending batch 1 CPut, 1 BeginTxn, 1 EndTxn, 1 InitPut to (n1,s1):1 query TT @@ -240,11 +240,11 @@ UPSERT INTO t.kv(k, v) VALUES (2,3); SET tracing=off; SELECT operation, message FROM [SHOW KV TRACE FOR SESSION] ---- -sql txn Scan /Table/52/1/{2-3} -dist sender querying next range at /Table/52/1/2 +sql txn Scan /Table/54/1/{2-3} +dist sender querying next range at /Table/54/1/2 dist sender r1: sending batch 1 Scan to (n1,s1):1 -sql txn CPut /Table/52/1/2/0 -> /TUPLE/2:2:Int/3 -dist sender querying next range at /Table/52/1/2/0 +sql txn CPut /Table/54/1/2/0 -> /TUPLE/2:2:Int/3 +dist sender querying next range at /Table/54/1/2/0 dist sender r1: sending batch 1 CPut, 1 BeginTxn, 1 EndTxn, 1 InitPut to (n1,s1):1 query TT @@ -253,12 +253,12 @@ UPSERT INTO t.kv(k, v) VALUES (1,2); SET tracing=off; SELECT operation, message FROM [SHOW KV TRACE FOR SESSION] ---- -sql txn Scan /Table/52/1/{1-2} -dist sender querying next range at /Table/52/1/1 +sql txn Scan /Table/54/1/{1-2} +dist sender querying next range at /Table/54/1/1 dist sender r1: sending batch 1 Scan to (n1,s1):1 sql txn fetched: /kv/primary/1/v -> /2 -sql txn Put /Table/52/1/1/0 -> /TUPLE/2:2:Int/2 -dist sender querying next range at /Table/52/1/1/0 +sql txn Put /Table/54/1/1/0 -> /TUPLE/2:2:Int/2 +dist sender querying next range at /Table/54/1/1/0 dist sender r1: sending batch 1 Put, 1 BeginTxn, 1 EndTxn to (n1,s1):1 statement error duplicate key value @@ -269,14 +269,14 @@ query TT set tracing=off; SELECT operation, message FROM [SHOW KV TRACE FOR SESSION] ---- -sql txn Scan /Table/52/1/{2-3} -dist sender querying next range at /Table/52/1/2 +sql txn Scan /Table/54/1/{2-3} +dist sender querying next range at /Table/54/1/2 dist sender r1: sending batch 1 Scan to (n1,s1):1 sql txn fetched: /kv/primary/2/v -> /3 -sql txn Put /Table/52/1/2/0 -> /TUPLE/2:2:Int/2 -sql txn Del /Table/52/2/3/0 -sql txn CPut /Table/52/2/2/0 -> /BYTES/Š -dist sender querying next range at /Table/52/1/2/0 +sql txn Put /Table/54/1/2/0 -> /TUPLE/2:2:Int/2 +sql txn Del /Table/54/2/3/0 +sql txn CPut /Table/54/2/2/0 -> /BYTES/Š +dist sender querying next range at /Table/54/1/2/0 dist sender r1: sending batch 1 Put, 1 CPut, 1 Del, 1 BeginTxn, 1 EndTxn to (n1,s1):1 query TT @@ -288,21 +288,21 @@ SELECT operation, regexp_replace(regexp_replace(message, 'wall_time:\d+', 'wall_ ---- dist sender querying next range at /Table/2/1/0/"test"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/50/2/1 +dist sender querying next range at /Table/3/1/52/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"t"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/51/2/1 +dist sender querying next range at /Table/3/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/2/1/51/"kv2"/3/1 +dist sender querying next range at /Table/2/1/53/"kv2"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /System/"desc-idgen" dist sender r1: sending batch 1 Inc to (n1,s1):1 -sql txn CPut /Table/2/1/51/"kv2"/3/1 -> 53 -sql txn CPut /Table/3/1/53/2/1 -> table: columns: nullable:true hidden:false > columns: nullable:true hidden:false > columns: nullable:false default_expr:"unique_rowid()" hidden:true > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:2 privileges: users: > next_mutation_id:1 format_version:3 state:PUBLIC view_query:"" drop_time:0 replacement_of: > audit_mode:DISABLED > +sql txn CPut /Table/2/1/53/"kv2"/3/1 -> 55 +sql txn CPut /Table/3/1/55/2/1 -> table: columns: nullable:true hidden:false > columns: nullable:true hidden:false > columns: nullable:false default_expr:"unique_rowid()" hidden:true > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:2 privileges: users: > next_mutation_id:1 format_version:3 state:PUBLIC view_query:"" drop_time:0 replacement_of: > audit_mode:DISABLED > dist sender querying next range at /Table/SystemConfigSpan/Start dist sender r1: sending batch 2 CPut, 1 BeginTxn to (n1,s1):1 -dist sender querying next range at /Table/3/1/51/2/1 +dist sender querying next range at /Table/3/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"system"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 @@ -325,13 +325,13 @@ dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/3/1/1/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender r1: sending batch 5 CPut to (n1,s1):1 -sql txn Scan /Table/52/{1-2} -dist sender querying next range at /Table/52/1 +sql txn Scan /Table/54/{1-2} +dist sender querying next range at /Table/54/1 dist sender r1: sending batch 1 Scan to (n1,s1):1 sql txn fetched: /kv/primary/1/v -> /2 -sql txn CPut /Table/53/1/...PK.../0 -> /TUPLE/1:1:Int/1/1:2:Int/2 +sql txn CPut /Table/55/1/...PK.../0 -> /TUPLE/1:1:Int/1/1:2:Int/2 sql txn fetched: /kv/primary/2/v -> /3 -sql txn CPut /Table/53/1/...PK.../0 -> /TUPLE/1:1:Int/2/1:2:Int/3 +sql txn CPut /Table/55/1/...PK.../0 -> /TUPLE/1:1:Int/2/1:2:Int/3 dist sender querying next range at /Table/SystemConfigSpan/Start dist sender r1: sending batch 2 CPut, 1 EndTxn to (n1,s1):1 @@ -342,9 +342,9 @@ SET tracing=off; SELECT operation, regexp_replace(message, '(\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.)?\d\d\d\d\d+', '...PK...') as message FROM [SHOW KV TRACE FOR SESSION] WHERE message NOT LIKE '%Z/%' ---- -dist sender querying next range at /Table/2/1/51/"kv2"/3/1 +dist sender querying next range at /Table/2/1/53/"kv2"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/53/2/1 +dist sender querying next range at /Table/3/1/55/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"system"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 @@ -358,14 +358,14 @@ dist sender querying next range at /Table/3/1/1/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender r1: sending batch 1 CPut, 1 BeginTxn to (n1,s1):1 dist sender r1: sending batch 1 EndTxn to (n1,s1):1 -sql txn Scan /Table/53/{1-2} -dist sender querying next range at /Table/53/1 +sql txn Scan /Table/55/{1-2} +dist sender querying next range at /Table/55/1 dist sender r1: sending batch 1 Scan to (n1,s1):1 sql txn fetched: /kv2/primary/...PK.../k/v -> /1/2 -sql txn Put /Table/53/1/...PK.../0 -> /TUPLE/1:1:Int/1/1:2:Int/4 +sql txn Put /Table/55/1/...PK.../0 -> /TUPLE/1:1:Int/1/1:2:Int/4 sql txn fetched: /kv2/primary/...PK.../k/v -> /2/3 -sql txn Put /Table/53/1/...PK.../0 -> /TUPLE/1:1:Int/2/1:2:Int/5 -dist sender querying next range at /Table/53/1/...PK.../0 +sql txn Put /Table/55/1/...PK.../0 -> /TUPLE/1:1:Int/2/1:2:Int/5 +dist sender querying next range at /Table/55/1/...PK.../0 dist sender r1: sending batch 2 Put, 1 BeginTxn, 1 EndTxn to (n1,s1):1 query TT @@ -374,11 +374,11 @@ DELETE FROM t.kv2; SET tracing=off; SELECT operation, message FROM [SHOW KV TRACE FOR SESSION] ---- -sql txn Scan /Table/53/{1-2} -dist sender querying next range at /Table/53/1 +sql txn Scan /Table/55/{1-2} +dist sender querying next range at /Table/55/1 dist sender r1: sending batch 1 Scan to (n1,s1):1 -sql txn DelRange /Table/53/1 - /Table/53/2 -dist sender querying next range at /Table/53/1 +sql txn DelRange /Table/55/1 - /Table/55/2 +dist sender querying next range at /Table/55/1 dist sender r1: sending batch 1 DelRng, 1 BeginTxn, 1 EndTxn to (n1,s1):1 # Like for CREATE UNIQUE INDEX ABOVE, we use SHOW KV TRACE FOR @@ -388,17 +388,17 @@ query TT SELECT operation, regexp_replace(regexp_replace(message, 'wall_time:\d+', 'wall_time:...'), 'drop_time:\d+', 'drop_time:...') as message FROM [SHOW KV TRACE FOR DROP TABLE t.kv2] WHERE message NOT LIKE '%Z/%' ---- -dist sender querying next range at /Table/5/1/53/2/1 +dist sender querying next range at /Table/5/1/55/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/53/2/1 +dist sender querying next range at /Table/3/1/55/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/5/1/51/2/1 +dist sender querying next range at /Table/5/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/51/2/1 +dist sender querying next range at /Table/3/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/5/1/0/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -starting plan Put /Table/3/1/53/2/1 -> table: columns: nullable:true hidden:false > columns: nullable:true hidden:false > columns: nullable:false default_expr:"unique_rowid()" hidden:true > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:2 privileges: users: > next_mutation_id:1 format_version:3 state:DROP draining_names: view_query:"" drop_time:... replacement_of: > audit_mode:DISABLED > +starting plan Put /Table/3/1/55/2/1 -> table: columns: nullable:true hidden:false > columns: nullable:true hidden:false > columns: nullable:false default_expr:"unique_rowid()" hidden:true > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:2 privileges: users: > next_mutation_id:1 format_version:3 state:DROP draining_names: view_query:"" drop_time:... replacement_of: > audit_mode:DISABLED > dist sender querying next range at /Table/SystemConfigSpan/Start dist sender r1: sending batch 1 Put, 1 BeginTxn to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"system"/3/1 @@ -429,16 +429,16 @@ DELETE FROM t.kv; SET tracing=off; SELECT operation, message FROM [SHOW KV TRACE FOR SESSION] ---- -sql txn Scan /Table/52/{1-2} -dist sender querying next range at /Table/52/1 +sql txn Scan /Table/54/{1-2} +dist sender querying next range at /Table/54/1 dist sender r1: sending batch 1 Scan to (n1,s1):1 sql txn fetched: /kv/primary/1/v -> /2 -sql txn Del /Table/52/2/2/0 -sql txn Del /Table/52/1/1/0 +sql txn Del /Table/54/2/2/0 +sql txn Del /Table/54/1/1/0 sql txn fetched: /kv/primary/2/v -> /3 -sql txn Del /Table/52/2/3/0 -sql txn Del /Table/52/1/2/0 -dist sender querying next range at /Table/52/1/1/0 +sql txn Del /Table/54/2/3/0 +sql txn Del /Table/54/1/2/0 +dist sender querying next range at /Table/54/1/1/0 dist sender r1: sending batch 4 Del, 1 BeginTxn, 1 EndTxn to (n1,s1):1 # Like for CREATE UNIQUE INDEX ABOVE, we use SHOW KV TRACE FOR @@ -450,15 +450,15 @@ SELECT operation, regexp_replace(regexp_replace(message, 'mutationJobs:<[^>]*>', ---- dist sender querying next range at /Table/2/1/0/"t"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/51/2/1 +dist sender querying next range at /Table/3/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/2/1/51/"kv"/3/1 +dist sender querying next range at /Table/2/1/53/"kv"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/52/2/1 +dist sender querying next range at /Table/3/1/54/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/51/2/1 +dist sender querying next range at /Table/3/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/51/2/1 +dist sender querying next range at /Table/3/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"system"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 @@ -482,8 +482,8 @@ dist sender querying next range at /Table/3/1/1/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/SystemConfigSpan/Start dist sender r1: sending batch 1 CPut, 1 BeginTxn, 1 InitPut to (n1,s1):1 -starting plan Put /Table/3/1/52/2/1 -> table: columns: nullable:false hidden:false > columns: nullable:true hidden:false > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:3 privileges: users: > mutations: interleave:<> partitioning: type:FORWARD > state:DELETE_AND_WRITE_ONLY direction:DROP mutation_id:2 rollback:false > next_mutation_id:3 format_version:3 state:PUBLIC view_query:"" mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED > -dist sender querying next range at /Table/3/1/52/2/1 +starting plan Put /Table/3/1/54/2/1 -> table: columns: nullable:false hidden:false > columns: nullable:true hidden:false > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:3 privileges: users: > mutations: interleave:<> partitioning: type:FORWARD > state:DELETE_AND_WRITE_ONLY direction:DROP mutation_id:2 rollback:false > next_mutation_id:3 format_version:3 state:PUBLIC view_query:"" mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED > +dist sender querying next range at /Table/3/1/54/2/1 dist sender r1: sending batch 1 Put to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"system"/3/1 dist sender r1: sending batch 1 Get to (n1,s1):1 @@ -514,17 +514,17 @@ query TT SELECT operation, regexp_replace(regexp_replace(regexp_replace(message, 'mutationJobs:<[^>]*>', 'mutationJobs:<...>'), 'wall_time:\d+', 'wall_time:...'), 'drop_time:\d+', 'drop_time:...') as message FROM [SHOW KV TRACE FOR DROP TABLE t.kv] WHERE message NOT LIKE '%Z/%' ---- -dist sender querying next range at /Table/5/1/52/2/1 +dist sender querying next range at /Table/5/1/54/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/52/2/1 +dist sender querying next range at /Table/3/1/54/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/5/1/51/2/1 +dist sender querying next range at /Table/5/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -dist sender querying next range at /Table/3/1/51/2/1 +dist sender querying next range at /Table/3/1/53/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 dist sender querying next range at /Table/5/1/0/2/1 dist sender r1: sending batch 1 Get to (n1,s1):1 -starting plan Put /Table/3/1/52/2/1 -> table: columns: nullable:false hidden:false > columns: nullable:true hidden:false > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:3 privileges: users: > next_mutation_id:3 format_version:3 state:DROP draining_names: view_query:"" drop_time:... replacement_of: > audit_mode:DISABLED > +starting plan Put /Table/3/1/54/2/1 -> table: columns: nullable:false hidden:false > columns: nullable:true hidden:false > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD > next_index_id:3 privileges: users: > next_mutation_id:3 format_version:3 state:DROP draining_names: view_query:"" drop_time:... replacement_of: > audit_mode:DISABLED > dist sender querying next range at /Table/SystemConfigSpan/Start dist sender r1: sending batch 1 Put, 1 BeginTxn to (n1,s1):1 dist sender querying next range at /Table/2/1/0/"system"/3/1 diff --git a/pkg/sql/logictest/testdata/logic_test/system b/pkg/sql/logictest/testdata/logic_test/system index 617ed9adced9..01d9f4be5ba4 100644 --- a/pkg/sql/logictest/testdata/logic_test/system +++ b/pkg/sql/logictest/testdata/logic_test/system @@ -3,6 +3,8 @@ query T SHOW DATABASES ---- +defaultdb +postgres system test @@ -28,10 +30,14 @@ query T SELECT message FROM [SHOW KV TRACE FOR SELECT * FROM system.namespace] WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ---- +fetched: /namespace/primary/0/'defaultdb'/id -> 50 +output row: [0 'defaultdb' 50] +fetched: /namespace/primary/0/'postgres'/id -> 51 +output row: [0 'postgres' 51] fetched: /namespace/primary/0/'system'/id -> 1 output row: [0 'system' 1] -fetched: /namespace/primary/0/'test'/id -> 50 -output row: [0 'test' 50] +fetched: /namespace/primary/0/'test'/id -> 52 +output row: [0 'test' 52] fetched: /namespace/primary/1/'descriptor'/id -> 3 output row: [1 'descriptor' 3] fetched: /namespace/primary/1/'eventlog'/id -> 12 @@ -64,8 +70,10 @@ output row: [1 'zones' 5] query ITI rowsort SELECT * FROM system.namespace ---- +0 defaultdb 50 +0 postgres 51 0 system 1 -0 test 50 +0 test 52 1 descriptor 3 1 eventlog 12 1 jobs 15 @@ -100,6 +108,8 @@ SELECT id FROM system.descriptor 21 23 50 +51 +52 # Verify we can read "protobuf" columns. query I diff --git a/pkg/sql/pgwire/pgwire_test.go b/pkg/sql/pgwire/pgwire_test.go index f9ff7f502b07..ed779b702b96 100644 --- a/pkg/sql/pgwire/pgwire_test.go +++ b/pkg/sql/pgwire/pgwire_test.go @@ -704,7 +704,7 @@ func TestPGPreparedQuery(t *testing.T) { baseTest.SetArgs("hello world"), }, "SHOW DATABASE": { - baseTest.Results(""), + baseTest.Results("defaultdb"), }, "SELECT descriptor FROM system.descriptor WHERE descriptor != $1 LIMIT 1": { baseTest.SetArgs([]byte("abc")).Results([]byte("\x12!\n\x06system\x10\x01\x1a\x15\n\t\n\x05admin\x100\n\b\n\x04root\x100")), @@ -716,7 +716,7 @@ func TestPGPreparedQuery(t *testing.T) { Results("isRole", "BOOL", false, false, "{}"), }, "SHOW DATABASES": { - baseTest.Results("d").Results("system"), + baseTest.Results("d").Results("defaultdb").Results("postgres").Results("system"), }, "SHOW GRANTS ON system.users": { baseTest.Results("system", "public", "users", sqlbase.AdminRole, "DELETE"). diff --git a/pkg/sql/rename_test.go b/pkg/sql/rename_test.go index 35d29f401bb4..2dd31dfbc84b 100644 --- a/pkg/sql/rename_test.go +++ b/pkg/sql/rename_test.go @@ -36,9 +36,8 @@ func TestRenameTable(t *testing.T) { s, db, kvDB := serverutils.StartServer(t, base.TestServerArgs{}) defer s.Stopper().Stop(context.TODO()) - counter := int64(keys.MaxReservedDescID) + counter := int64(keys.MinNonPredefinedUserDescID) - counter++ oldDBID := sqlbase.ID(counter) if _, err := db.Exec(`CREATE DATABASE test`); err != nil { t.Fatal(err) diff --git a/pkg/sql/schema_changer_test.go b/pkg/sql/schema_changer_test.go index d5f7805e2bdd..5a549e764423 100644 --- a/pkg/sql/schema_changer_test.go +++ b/pkg/sql/schema_changer_test.go @@ -71,6 +71,7 @@ func TestSchemaChangeLease(t *testing.T) { sql.MinSchemaChangeLeaseDuration = minLeaseDuration }() + const dbDescID = keys.MinNonPredefinedUserDescID if _, err := sqlDB.Exec(` CREATE DATABASE t; CREATE TABLE t.test (k CHAR PRIMARY KEY, v CHAR); @@ -79,7 +80,7 @@ CREATE TABLE t.test (k CHAR PRIMARY KEY, v CHAR); } var lease sqlbase.TableDescriptor_SchemaChangeLease - var id = sqlbase.ID(keys.MaxReservedDescID + 2) + var id = sqlbase.ID(dbDescID + 1) var node = roachpb.NodeID(2) execCfg := s.ExecutorConfig().(sql.ExecutorConfig) changer := sql.NewSchemaChangerForTesting( @@ -178,7 +179,7 @@ func TestSchemaChangeProcess(t *testing.T) { s, sqlDB, kvDB := serverutils.StartServer(t, params) defer s.Stopper().Stop(context.TODO()) - var id = sqlbase.ID(keys.MaxReservedDescID + 2) + var id = sqlbase.ID(keys.MinNonPredefinedUserDescID + 1 /* skip over DB ID */) var node = roachpb.NodeID(2) stopper := stop.NewStopper() cfg := base.NewLeaseManagerConfig() diff --git a/pkg/sql/sessiondata/search_path.go b/pkg/sql/sessiondata/search_path.go index eeff7d45808f..5a15df7e80c3 100644 --- a/pkg/sql/sessiondata/search_path.go +++ b/pkg/sql/sessiondata/search_path.go @@ -18,7 +18,14 @@ import ( "strings" ) -// PgCatalogName is the name of the pg_catalog system database. +// PgDatabaseName is the name of the default postgres system database. +const PgDatabaseName = "postgres" + +// DefaultDatabaseName is the name ofthe default CockroachDB database used +// for connections without a current db set. +const DefaultDatabaseName = "defaultdb" + +// PgCatalogName is the name of the pg_catalog system schema. const PgCatalogName = "pg_catalog" // SearchPath represents a list of namespaces to search builtins in. diff --git a/pkg/sql/sqlbase/metadata.go b/pkg/sql/sqlbase/metadata.go index d024eaa9b206..a564d9a26386 100644 --- a/pkg/sql/sqlbase/metadata.go +++ b/pkg/sql/sqlbase/metadata.go @@ -123,7 +123,7 @@ func (ms MetadataSchema) GetInitialValues() []roachpb.KeyValue { // Save the ID generator value, which will generate descriptor IDs for user // objects. value := roachpb.Value{} - value.SetInt(int64(keys.MaxReservedDescID + 1)) + value.SetInt(int64(keys.MinUserDescID)) ret = append(ret, roachpb.KeyValue{ Key: keys.DescIDGenerator, Value: value, diff --git a/pkg/sql/sqlbase/privilege_test.go b/pkg/sql/sqlbase/privilege_test.go index 93a50c47c799..e055f5589471 100644 --- a/pkg/sql/sqlbase/privilege_test.go +++ b/pkg/sql/sqlbase/privilege_test.go @@ -192,7 +192,7 @@ func TestAnyPrivilege(t *testing.T) { // TestPrivilegeValidate exercises validation for non-system descriptors. func TestPrivilegeValidate(t *testing.T) { defer leaktest.AfterTest(t)() - id := ID(keys.MaxReservedDescID + 1) + id := ID(keys.MinUserDescID) descriptor := NewDefaultPrivilegeDescriptor() if err := descriptor.Validate(id); err != nil { t.Fatal(err) @@ -323,7 +323,7 @@ func TestFixPrivileges(t *testing.T) { defer leaktest.AfterTest(t)() // Use a non-system ID. - userID := ID(keys.MaxReservedDescID + 1) + userID := ID(keys.MinUserDescID) userPrivs := privilege.List{privilege.ALL} // And create an entry for a fake system table. diff --git a/pkg/sql/sqlbase/structured.go b/pkg/sql/sqlbase/structured.go index cc9c100005ec..c7323abfdf43 100644 --- a/pkg/sql/sqlbase/structured.go +++ b/pkg/sql/sqlbase/structured.go @@ -596,7 +596,7 @@ func (desc *TableDescriptor) AllocateIDs() error { // before AllocateIDs. savedID := desc.ID if desc.ID == 0 { - desc.ID = keys.MaxReservedDescID + 1 + desc.ID = keys.MinUserDescID } err := desc.ValidateTable(nil) desc.ID = savedID diff --git a/pkg/sql/sqlbase/structured_test.go b/pkg/sql/sqlbase/structured_test.go index 4dfe6af596f6..a722cd50988f 100644 --- a/pkg/sql/sqlbase/structured_test.go +++ b/pkg/sql/sqlbase/structured_test.go @@ -53,8 +53,8 @@ func TestAllocateIDs(t *testing.T) { defer leaktest.AfterTest(t)() desc := TableDescriptor{ - ID: keys.MaxReservedDescID + 2, - ParentID: keys.MaxReservedDescID + 1, + ParentID: keys.MinUserDescID, + ID: keys.MinUserDescID + 1, Name: "foo", Columns: []ColumnDescriptor{ {Name: "a"}, @@ -74,8 +74,8 @@ func TestAllocateIDs(t *testing.T) { } expected := TableDescriptor{ - ID: keys.MaxReservedDescID + 2, - ParentID: keys.MaxReservedDescID + 1, + ParentID: keys.MinUserDescID, + ID: keys.MinUserDescID + 1, Version: 1, Name: "foo", Columns: []ColumnDescriptor{ diff --git a/pkg/sql/tests/split_test.go b/pkg/sql/tests/split_test.go index 8c99ef324b03..c6378a333156 100644 --- a/pkg/sql/tests/split_test.go +++ b/pkg/sql/tests/split_test.go @@ -100,7 +100,7 @@ func TestSplitOnTableBoundaries(t *testing.T) { }) // Verify the actual splits. - objectID := uint32(keys.MaxReservedDescID + 1) + objectID := uint32(keys.MinUserDescID) splits := []roachpb.RKey{keys.MakeTablePrefix(objectID), roachpb.RKeyMax} ranges, err := getRangeKeys(kvDB) if err != nil { diff --git a/pkg/sql/tests/system_table_test.go b/pkg/sql/tests/system_table_test.go index 4b578f762a63..e90484a9e16e 100644 --- a/pkg/sql/tests/system_table_test.go +++ b/pkg/sql/tests/system_table_test.go @@ -81,7 +81,7 @@ func TestInitialKeys(t *testing.T) { if err != nil { t.Fatal(err) } - if a, e := i, int64(keys.MaxReservedDescID+1); a != e { + if a, e := i, int64(keys.MinUserDescID); a != e { t.Fatalf("Expected next descriptor ID to be %d, was %d", e, a) } } diff --git a/pkg/sql/txn_restart_test.go b/pkg/sql/txn_restart_test.go index 5814b18cd0c6..a5698f194577 100644 --- a/pkg/sql/txn_restart_test.go +++ b/pkg/sql/txn_restart_test.go @@ -1471,7 +1471,7 @@ func TestDistSQLRetryableError(t *testing.T) { defer leaktest.AfterTest(t)() // One of the rows in the table. - targetKey := roachpb.Key("\273\211\212") + targetKey := roachpb.Key("\275\211\212") restarted := true diff --git a/pkg/sql/vars.go b/pkg/sql/vars.go index 2e9603b1b722..f8670728d1a5 100644 --- a/pkg/sql/vars.go +++ b/pkg/sql/vars.go @@ -128,8 +128,6 @@ var varGen = map[string]sessionVar{ }, // CockroachDB extension. - // TODO(knz): may need to be replaced by 1st element of search_path for - // pg compatibility. `database`: { Set: func( ctx context.Context, m *sessionDataMutator, @@ -140,6 +138,10 @@ var varGen = map[string]sessionVar{ return err } + if len(dbName) == 0 && evalCtx.SessionData.SafeUpdates { + return pgerror.NewDangerousStatementErrorf("SET database to empty string") + } + if len(dbName) != 0 { // Verify database descriptor exists. if _, err := evalCtx.schemaAccessors.logical.GetDatabaseDesc(dbName, diff --git a/pkg/sql/zone_config_test.go b/pkg/sql/zone_config_test.go index 1c1c375d5f5d..2546fd826d8f 100644 --- a/pkg/sql/zone_config_test.go +++ b/pkg/sql/zone_config_test.go @@ -92,7 +92,7 @@ func TestGetZoneConfig(t *testing.T) { defer srv.Stopper().Stop(context.TODO()) s := srv.(*server.TestServer) - expectedCounter := uint32(keys.MaxReservedDescID) + expectedCounter := uint32(keys.MinNonPredefinedUserDescID) defaultZoneConfig := config.DefaultZoneConfig() defaultZoneConfig.RangeMinBytes = 1 << 20 @@ -159,7 +159,6 @@ func TestGetZoneConfig(t *testing.T) { // db1 has tables tb11 and tb12 // db2 has tables tb21 and tb22 - expectedCounter++ db1 := expectedCounter if _, err := sqlDB.Exec(`CREATE DATABASE db1`); err != nil { t.Fatal(err) @@ -321,7 +320,7 @@ func BenchmarkGetZoneConfig(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - _, err := cfg.GetZoneConfigForKey(keys.MakeTablePrefix(keys.MaxReservedDescID + 1)) + _, err := cfg.GetZoneConfigForKey(keys.MakeTablePrefix(keys.MinUserDescID)) if err != nil { b.Fatal(err) } diff --git a/pkg/sql/zone_test.go b/pkg/sql/zone_test.go index 38636deb166e..68e484bc1f1f 100644 --- a/pkg/sql/zone_test.go +++ b/pkg/sql/zone_test.go @@ -68,18 +68,19 @@ func TestValidSetShowZones(t *testing.T) { CLISpecifier: "system.jobs", Config: zoneOverride, } + dbDescID := uint32(keys.MinNonPredefinedUserDescID) dbRow := sqlutils.ZoneRow{ - ID: keys.MaxReservedDescID + 1, + ID: dbDescID, CLISpecifier: "d", Config: zoneOverride, } tableRow := sqlutils.ZoneRow{ - ID: keys.MaxReservedDescID + 2, + ID: dbDescID + 1, CLISpecifier: "d.t", Config: zoneOverride, } tableDroppedRow := sqlutils.ZoneRow{ - ID: keys.MaxReservedDescID + 2, + ID: dbDescID + 1, CLISpecifier: "NULL", Config: zoneOverride, } diff --git a/pkg/sqlmigrations/migrations.go b/pkg/sqlmigrations/migrations.go index 4d8bce2f1fa5..498b3b5ea8aa 100644 --- a/pkg/sqlmigrations/migrations.go +++ b/pkg/sqlmigrations/migrations.go @@ -30,6 +30,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" + "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" "github.com/cockroachdb/cockroach/pkg/util/envutil" "github.com/cockroachdb/cockroach/pkg/util/hlc" @@ -105,7 +106,8 @@ var backwardCompatibleMigrations = []migrationDescriptor{ }, { // Introduced in v2.0. Baked into v2.1. - name: "create system.table_statistics table", + name: "create system.table_statistics table", + newDescriptorIDs: staticIDs(keys.TableStatisticsTableID), }, { // Introduced in v2.0. Permanent migration. @@ -114,7 +116,8 @@ var backwardCompatibleMigrations = []migrationDescriptor{ }, { // Introduced in v2.0. Baked into v2.1. - name: "create system.locations table", + name: "create system.locations table", + newDescriptorIDs: staticIDs(keys.LocationsTableID), }, { // Introduced in v2.0. Baked into v2.1. @@ -122,7 +125,8 @@ var backwardCompatibleMigrations = []migrationDescriptor{ }, { // Introduced in v2.0. Baked into v2.1. - name: "create system.role_members table", + name: "create system.role_members table", + newDescriptorIDs: staticIDs(keys.RoleMembersTableID), }, { // Introduced in v2.0. Permanent migration. @@ -175,6 +179,31 @@ var backwardCompatibleMigrations = []migrationDescriptor{ name: "disallow public user or role name", workFn: disallowPublicUserOrRole, }, + { + // Introduced in v2.1. + // TODO(knz): bake this migration into v2.2. + name: "create default databases", + workFn: createDefaultDbs, + newDescriptorIDs: databaseIDs(sessiondata.DefaultDatabaseName, sessiondata.PgDatabaseName), + }, +} + +func staticIDs(ids ...sqlbase.ID) func(ctx context.Context, db db) ([]sqlbase.ID, error) { + return func(ctx context.Context, db db) ([]sqlbase.ID, error) { return ids, nil } +} + +func databaseIDs(names ...string) func(ctx context.Context, db db) ([]sqlbase.ID, error) { + return func(ctx context.Context, db db) ([]sqlbase.ID, error) { + var ids []sqlbase.ID + for _, name := range names { + kv, err := db.Get(ctx, sqlbase.MakeNameMetadataKey(keys.RootNamespaceID, name)) + if err != nil { + return nil, err + } + ids = append(ids, sqlbase.ID(kv.ValueInt())) + } + return ids, nil + } } // migrationDescriptor describes a single migration hook that's used to modify @@ -188,10 +217,11 @@ type migrationDescriptor struct { workFn func(context.Context, runner) error // doesBackfill should be set to true if the migration triggers a backfill. doesBackfill bool - // newDescriptorIDs lists the IDs of any additional descriptors added by this - // migration. This is needed to automate certain tests, which check the number - // of ranges/descriptors present on server bootup. - newDescriptorIDs sqlbase.IDs + // newDescriptorIDs is a function that returns the IDs of any additional + // descriptors that were added by this migration. This is needed to automate + // certain tests, which check the number of ranges/descriptors present on + // server bootup. + newDescriptorIDs func(ctx context.Context, db db) ([]sqlbase.ID, error) } func init() { @@ -224,6 +254,7 @@ type leaseManager interface { // package. type db interface { Scan(ctx context.Context, begin, end interface{}, maxRows int64) ([]client.KeyValue, error) + Get(ctx context.Context, key interface{}) (client.KeyValue, error) Put(ctx context.Context, key, value interface{}) error Txn(ctx context.Context, retryable func(ctx context.Context, txn *client.Txn) error) error } @@ -274,8 +305,15 @@ func ExpectedDescriptorIDs(ctx context.Context, db db) (sqlbase.IDs, error) { } descriptorIDs := sqlbase.MakeMetadataSchema().DescriptorIDs() for _, migration := range backwardCompatibleMigrations { + if migration.newDescriptorIDs == nil { + continue + } if _, ok := completedMigrations[string(migrationKey(migration))]; ok { - descriptorIDs = append(descriptorIDs, migration.newDescriptorIDs...) + newIDs, err := migration.newDescriptorIDs(ctx, db) + if err != nil { + return nil, err + } + descriptorIDs = append(descriptorIDs, newIDs...) } } sort.Sort(descriptorIDs) @@ -726,3 +764,26 @@ func disallowPublicUserOrRole(ctx context.Context, r runner) error { } return nil } + +func createDefaultDbs(ctx context.Context, r runner) error { + // Create the default databases. These are plain databases with + // default permissions. Nothing special happens if they exist + // already. + const createDbStmt = `CREATE DATABASE IF NOT EXISTS "%s"` + + var err error + for retry := retry.Start(retry.Options{MaxRetries: 5}); retry.Next(); { + for _, dbName := range []string{sessiondata.DefaultDatabaseName, sessiondata.PgDatabaseName} { + stmt := fmt.Sprintf(createDbStmt, dbName) + _, err = r.sqlExecutor.Exec(ctx, "create-default-db", nil /* txn */, stmt) + if err != nil { + log.Warningf(ctx, "failed attempt to add database %q: %s", dbName, err) + break + } + } + if err == nil { + break + } + } + return err +} diff --git a/pkg/sqlmigrations/migrations_test.go b/pkg/sqlmigrations/migrations_test.go index c586bfc447a2..b2141e813323 100644 --- a/pkg/sqlmigrations/migrations_test.go +++ b/pkg/sqlmigrations/migrations_test.go @@ -114,6 +114,10 @@ func (f *fakeDB) Scan( return results, nil } +func (f *fakeDB) Get(ctx context.Context, key interface{}) (client.KeyValue, error) { + return client.KeyValue{}, errors.New("unimplemented") +} + func (f *fakeDB) Put(ctx context.Context, key, value interface{}) error { if f.putErr != nil { return f.putErr diff --git a/pkg/storage/client_split_test.go b/pkg/storage/client_split_test.go index b00ee7d56c38..258a5d47b391 100644 --- a/pkg/storage/client_split_test.go +++ b/pkg/storage/client_split_test.go @@ -124,7 +124,7 @@ func TestStoreRangeSplitAtTablePrefix(t *testing.T) { return err } // We don't care about the values, just the keys. - k := sqlbase.MakeDescMetadataKey(sqlbase.ID(keys.MaxReservedDescID + 1)) + k := sqlbase.MakeDescMetadataKey(sqlbase.ID(keys.MinUserDescID)) return txn.Put(ctx, k, &desc) }); err != nil { t.Fatal(err) @@ -164,7 +164,7 @@ func TestStoreRangeSplitInsideRow(t *testing.T) { // Manually create some the column keys corresponding to the table: // // CREATE TABLE t (id STRING PRIMARY KEY, col1 INT, col2 INT) - tableKey := keys.MakeTablePrefix(keys.MaxReservedDescID + 1) + tableKey := keys.MakeTablePrefix(keys.MinUserDescID) rowKey := roachpb.Key(encoding.EncodeVarintAscending(append([]byte(nil), tableKey...), 1)) rowKey = encoding.EncodeStringAscending(encoding.EncodeVarintAscending(rowKey, 1), "a") col1Key, err := keys.EnsureSafeSplitKey(keys.MakeFamilyKey(append([]byte(nil), rowKey...), 1)) @@ -537,7 +537,7 @@ func TestStoreRangeSplitStats(t *testing.T) { ctx := context.Background() // Split the range after the last table data key. - keyPrefix := keys.MakeTablePrefix(keys.MaxReservedDescID + 1) + keyPrefix := keys.MakeTablePrefix(keys.MinUserDescID) args := adminSplitArgs(keyPrefix) if _, pErr := client.SendWrapped(ctx, store.TestSender(), args); pErr != nil { t.Fatal(pErr) @@ -669,7 +669,7 @@ func TestStoreEmptyRangeSnapshotSize(t *testing.T) { // Split the range after the last table data key to get a range that contains // no user data. - splitKey := keys.MakeTablePrefix(keys.MaxReservedDescID + 1) + splitKey := keys.MakeTablePrefix(keys.MinUserDescID) splitArgs := adminSplitArgs(splitKey) if _, err := client.SendWrapped(ctx, mtc.distSenders[0], splitArgs); err != nil { t.Fatal(err) @@ -736,7 +736,7 @@ func TestStoreRangeSplitStatsWithMerges(t *testing.T) { ctx := context.Background() // Split the range after the last table data key. - keyPrefix := keys.MakeTablePrefix(keys.MaxReservedDescID + 1) + keyPrefix := keys.MakeTablePrefix(keys.MinUserDescID) args := adminSplitArgs(keyPrefix) if _, pErr := client.SendWrapped(ctx, store.TestSender(), args); pErr != nil { t.Fatal(pErr) @@ -846,7 +846,7 @@ func TestStoreZoneUpdateAndRangeSplit(t *testing.T) { const maxBytes = 1 << 16 // Set max bytes. - descID := uint32(keys.MaxReservedDescID + 1) + descID := uint32(keys.MinUserDescID) config.TestingSetZoneConfig(descID, config.ZoneConfig{RangeMaxBytes: maxBytes}) // Trigger gossip callback. @@ -904,7 +904,7 @@ func TestStoreRangeSplitWithMaxBytesUpdate(t *testing.T) { // Set max bytes. const maxBytes = 1 << 16 - descID := uint32(keys.MaxReservedDescID + 1) + descID := uint32(keys.MinUserDescID) config.TestingSetZoneConfig(descID, config.ZoneConfig{RangeMaxBytes: maxBytes}) // Trigger gossip callback. @@ -1083,7 +1083,7 @@ func TestStoreRangeSystemSplits(t *testing.T) { defer stopper.Stop(context.TODO()) store, _ := createTestStore(t, stopper) - userTableMax := keys.MaxReservedDescID + 5 + userTableMax := keys.MinUserDescID + 4 schema := sqlbase.MakeMetadataSchema() // Write table descriptors for the tables in the metadata schema as well as // five dummy user tables. This does two things: @@ -1103,7 +1103,7 @@ func TestStoreRangeSystemSplits(t *testing.T) { return err } } - for i := keys.MaxReservedDescID + 1; i <= userTableMax; i++ { + for i := keys.MinUserDescID; i <= userTableMax; i++ { // We don't care about the value, just the key. key := sqlbase.MakeDescMetadataKey(sqlbase.ID(i)) if err := txn.Put(ctx, key, &sqlbase.TableDescriptor{}); err != nil { @@ -1134,7 +1134,7 @@ func TestStoreRangeSystemSplits(t *testing.T) { testutils.MakeKey(keys.Meta2Prefix, keys.MakeTablePrefix(i)), ) } - for i := keys.MaxReservedDescID + 1; i <= userTableMax; i++ { + for i := keys.MinUserDescID; i <= userTableMax; i++ { expKeys = append(expKeys, testutils.MakeKey(keys.Meta2Prefix, keys.MakeTablePrefix(uint32(i))), ) @@ -2708,7 +2708,7 @@ func TestRangeLookupAfterMeta2Split(t *testing.T) { // will first search for meta(/Table/49) which is on the left meta2 range. However, // the user range [/Table/48-/Max) is stored on the right meta2 range, so the lookup // will require a scan that continues into the next meta2 range. - const tableID = keys.MaxReservedDescID + 2 // 51 + const tableID = keys.MinUserDescID + 1 // 51 splitReq := adminSplitArgs(keys.MakeTablePrefix(tableID - 3 /* 48 */)) if _, pErr := client.SendWrapped(ctx, s.DB().GetSender(), splitReq); pErr != nil { t.Fatal(pErr) diff --git a/pkg/storage/engine/mvcc_test.go b/pkg/storage/engine/mvcc_test.go index 5aab114d8138..63bfe1e5e6cb 100644 --- a/pkg/storage/engine/mvcc_test.go +++ b/pkg/storage/engine/mvcc_test.go @@ -3438,7 +3438,7 @@ func TestFindSplitKey(t *testing.T) { func TestFindValidSplitKeys(t *testing.T) { defer leaktest.AfterTest(t)() - const userID = keys.MaxReservedDescID + 1 + const userID = keys.MinUserDescID // Manually creates rows corresponding to the schema: // CREATE TABLE t (id1 STRING, id2 STRING, ... PRIMARY KEY (id1, id2, ...)) tablePrefix := func(id uint32, rowVals ...string) roachpb.Key { @@ -3602,7 +3602,7 @@ func TestFindValidSplitKeys(t *testing.T) { addColFam(tablePrefix(userID, "b"), 1), addColFam(tablePrefix(userID, "c"), 1), }, - rangeStart: keys.MakeTablePrefix(keys.MaxReservedDescID + 1), + rangeStart: keys.MakeTablePrefix(keys.MinUserDescID), expSplit: tablePrefix(userID, "b"), expError: false, }, diff --git a/pkg/storage/replicate_queue_test.go b/pkg/storage/replicate_queue_test.go index 82aa6ea03664..a9a1f2b0e793 100644 --- a/pkg/storage/replicate_queue_test.go +++ b/pkg/storage/replicate_queue_test.go @@ -56,7 +56,7 @@ func TestReplicateQueueRebalance(t *testing.T) { const newRanges = 5 for i := 0; i < newRanges; i++ { - tableID := keys.MaxReservedDescID + i + 1 + tableID := keys.MinUserDescID + i splitKey := keys.MakeTablePrefix(uint32(tableID)) if _, _, err := tc.SplitRange(splitKey); err != nil { t.Fatal(err) diff --git a/pkg/storage/store_test.go b/pkg/storage/store_test.go index 31ca16c7f2ed..3e0a317175e3 100644 --- a/pkg/storage/store_test.go +++ b/pkg/storage/store_test.go @@ -1351,7 +1351,7 @@ func TestStoreSetRangesMaxBytes(t *testing.T) { defer stopper.Stop(context.TODO()) store, _ := createTestStore(t, stopper) - baseID := uint32(keys.MaxReservedDescID + 1) + baseID := uint32(keys.MinUserDescID) testData := []struct { repl *Replica expMaxBytes int64