-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql, *: allow table scoping under pg_temp_<session_id> physical schema
Previously, CRDB only supported the `public` physical schema. All table entries in `system.namespace` assumed an implied `public` schema, so name resolution for tables only required a databaseID and table name to uniquely identify a table. As highlighted in the temp tables RFC, temp tables will be scoped under a session specific schema of the form `pg_temp_<session_id>`. This motivated adding support for additional physical schemas. This PR involves the following changes to `system.namespace`: - A new `system.namespace` table is constructed for cluster versions >= 20.1, which has an additional primary key column `publicSchemaID`. - The older `system.namespace` table is marked deprecated. All `system.namespace` read accesses default to the new `system.namespace`. If a match isn't found, the deprecated `system.namespace` is checked. - All `system.namespace` write accesses for key deletions remove entries from both versions of the table. This ensures the fallback code doesn't read an old key that was deleted. - All `system.namespace` write accesses that involve creating new entries are added to the `system.namespace` table according to the cluster version. - Selecting from `system.namespace` in mixed version clusters actually selects from `system.namespace_deprecated`, ensuring that the change is invisible to users. - The new `system.namespace` table is moved out of the SystemConfig range. This means `system.namespace` is no longer gossiped for cluster versions >= 20.1 . - Every new database creation adds the `public` schema to `system.namespace` by default. As a result of the above changes to `system.namespace`, there is a new interface that all accesses should go through. - Lookups Previously: Keys were constructed and directly used to perform KV lookups. Now: Use LookupObjectID, or another specialized lookup method provided. This ensures correct fallback semantics for mixed-version 19.2/20.1 clusters. - Removals Previously: Keys were constructed and directly used to perform KV deletes. Now: Use RemoveObjectNamespaceEntry or another specialized method provided. This ensures correct behavior for mixed-version 19.2/20.1 clusters. - Additions Previously: Keys were constructed and directly used to perform CPuts with the appropriate value. Now: Use MakeObjectNameKey or another specialized method provided to construct the key. This ensures that the key created is for the appropriate cluster version. These methods should only be used to create keys for adding entries -- removals/lookups should go through the appropriate interfaces. The `search_path` is responsible for establishing the order in which schemas are searched during name resolution. This PR involves the following changes to the `search_path.go`: - The search semantics are updated to match those described in the temp tables RFC. - The search path is now aware of the session specific temporary schema, which can be used during name resolution. - The distSQL api proto had to be updated to pass the temporary schema to other nodes in addition to the list of paths. Benchmarks: TPC-C with 3 nodes/16CPUs: - max warehouses: 1565 Microbenchmarks for system.namespace access: | name | master time/op | new approach time/op | delta | | ----------------------------------- | -------------- | -------------------- | ----- | | NameResolution/Cockroach-8 | 163µs ± 0% | 252µs ± 0% | ~ | | NameResolution/MultinodeCockroach-8 | 419µs ± 0% | 797µs ± 0% | ~ | | name | master time/op | new approach time/op | delta | | -------------------------------------------------- | -------------- | -------------------- | ----- | | NameResolutionTempTablesExist/Cockroach-8 | 175µs ± 0% | 337µs ± 0% | ~ | | NameResolutionTempTablesExist/MultinodeCockroach-8 | 1.06ms ± 0% | 1.07ms ± 0% | ~ | Follow-up work: - The `TableCollection` cache needs to be updated to have knowledge about schemaIDs. Once this is done, there is a TODO in the code that allows the `CachedPhysicalAccessor` to work correctly. - Migration for clusters upgrading to 20.1. The new `system.namespace` table needs to be populated from the deprecated table and a `public` schema needs to be added for every database during migration. Release note (sql change): CREATE TABLE pg_temp.abc(a int) now creates a temporary table. See temp tables RFC (guide-level explanation) for more details about the search path semantics.
- Loading branch information
1 parent
e1c1a9a
commit 90f5b69
Showing
94 changed files
with
2,022 additions
and
800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2229,6 +2229,8 @@ writing ` + os.DevNull + ` | |
debug/nodes/1/ranges/22.json | ||
debug/nodes/1/ranges/23.json | ||
debug/nodes/1/ranges/24.json | ||
debug/nodes/1/ranges/25.json | ||
debug/nodes/1/ranges/26.json | ||
debug/schema/[email protected] | ||
debug/schema/[email protected] | ||
debug/schema/[email protected] | ||
|
@@ -2239,6 +2241,7 @@ writing ` + os.DevNull + ` | |
debug/schema/system/lease.json | ||
debug/schema/system/locations.json | ||
debug/schema/system/namespace.json | ||
debug/schema/system/namespace_deprecated.json | ||
debug/schema/system/rangelog.json | ||
debug/schema/system/replication_constraint_stats.json | ||
debug/schema/system/replication_critical_localities.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.