Commit 4fb7ab05 authored by craig[bot]'s avatar craig[bot]

Merge #48754

48754: sql: introduce pg_extension schema r=rohany a=otan

Also added a barebones geography_columns, geometry_columns and
spatial_ref_sys table definition which I will delegate to another
reviewer - this bit is SQL Feature-y by itself :)

Release note (sql change): Introduced the pg_extension virtual schema,
which contains tables which are on the public schema when using postgres
style extensions.
Co-authored-by: default avatarOliver Tan <[email protected]>
parents 53607a3a 86641f90
......@@ -38,7 +38,9 @@ func (d *delegator) delegateShowTables(n *tree.ShowTables) (tree.Statement, erro
}
schemaClause = fmt.Sprintf("AND ns.nspname = %s", schema)
} else {
schemaClause = "AND ns.nspname NOT IN ('information_schema', 'pg_catalog', 'crdb_internal')"
// These must be custom defined until the sql <-> sql/delegate cyclic dependency
// is resolved. When we have that, we should read the names off "virtualSchemas" instead.
schemaClause = "AND ns.nspname NOT IN ('information_schema', 'pg_catalog', 'crdb_internal', 'pg_extension')"
}
var query string
......
......@@ -132,7 +132,7 @@ query III colnames
SELECT * FROM bar
----
a b c
1 2 4
1 2 5
statement ok
CREATE TABLE baz (a, b, c) AS SELECT 1, 2, count(*) FROM foo
......@@ -141,7 +141,7 @@ query III colnames
SELECT * FROM baz
----
a b c
1 2 4
1 2 5
# Check that CREATE TABLE AS allows users to specify primary key (#20940)
statement ok
......
......@@ -42,6 +42,7 @@ schema_name
crdb_internal
information_schema
pg_catalog
pg_extension
public
statement ok
......
......@@ -103,7 +103,8 @@ INSERT INTO parse_test (geom, geog) VALUES
(ST_GeomFromGeoJSON('{"type":"Feature","geometry":{"type":"Point","coordinates":[1,2]},"properties":null}'::jsonb), ST_GeogFromGeoJSON('{"type":"Feature","geometry":{"type":"Point","coordinates":[1,2]},"properties":null}'::jsonb)),
(ST_GeomFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex')), ST_GeogFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'))),
(ST_GeomFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'), 3857), ST_GeogFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'), 3857)),
(ST_GeomFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex')), ST_GeogFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex')))
(ST_GeomFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex')), ST_GeogFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'))),
(st_geomfromgeojson('null':::jsonb), st_geogfromgeojson('null':::jsonb))
query TTTTTTTT
SELECT
......@@ -141,6 +142,7 @@ POINT (1 1) SRID=3857;POINT (1 1)
<Point><coordinates>1,1</coordinates></Point> {"type":"Feature","geometry":{"type":"Point","coordinates":[1,1]},"properties":null}
POINT (1 1) POINT (1 1) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] 0101000000000000000000F03F000000000000F03F 0101000000000000000000F03F000000000000F03F <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point> {"type":"Feature","geometry":{"type":"Point","coordinates":[1,1]},"properties":null}
NULL NULL NULL NULL NULL NULL NULL NULL
query TTTTTTTT
SELECT
......@@ -178,6 +180,7 @@ POINT (1 1) SRID=3857;POINT (1 1)
<Point><coordinates>1,1</coordinates></Point> {"type":"Feature","geometry":{"type":"Point","coordinates":[1,1]},"properties":null}
POINT (1 1) SRID=4326;POINT (1 1) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] 0101000000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point> {"type":"Feature","geometry":{"type":"Point","coordinates":[1,1]},"properties":null}
NULL NULL NULL NULL NULL NULL NULL NULL
query TTTTTTTT
SELECT
......@@ -719,9 +722,13 @@ Square overlapping left and right square Square (right)
Square overlapping left and right square Square overlapping left and right square true true true
subtest regression_48093
subtest pg_extension
query TT
SELECT st_geogfromgeojson('null':::jsonb), st_geomfromgeojson('null':::jsonb)
----
NULL NULL
statement error not yet implemented
SELECT * FROM pg_extension.geography_columns
statement error not yet implemented
SELECT * FROM pg_extension.geometry_columns
statement error not yet implemented
SELECT * FROM pg_extension.spatial_ref_sys ORDER BY srid ASC
......@@ -13,6 +13,8 @@ a information_schema admin ALL
a information_schema root ALL
a pg_catalog admin ALL
a pg_catalog root ALL
a pg_extension admin ALL
a pg_extension root ALL
a public admin ALL
a public root ALL
......@@ -55,6 +57,10 @@ a pg_catalog admin ALL
a pg_catalog readwrite ALL
a pg_catalog root ALL
a pg_catalog test-user ALL
a pg_extension admin ALL
a pg_extension readwrite ALL
a pg_extension root ALL
a pg_extension test-user ALL
a public admin ALL
a public readwrite ALL
a public root ALL
......@@ -82,6 +88,8 @@ a information_schema readwrite ALL
a information_schema test-user ALL
a pg_catalog readwrite ALL
a pg_catalog test-user ALL
a pg_extension readwrite ALL
a pg_extension test-user ALL
a public readwrite ALL
a public test-user ALL
......@@ -133,6 +141,20 @@ a pg_catalog test-user DROP
a pg_catalog test-user GRANT
a pg_catalog test-user SELECT
a pg_catalog test-user ZONECONFIG
a pg_extension admin ALL
a pg_extension readwrite CREATE
a pg_extension readwrite DELETE
a pg_extension readwrite DROP
a pg_extension readwrite GRANT
a pg_extension readwrite SELECT
a pg_extension readwrite ZONECONFIG
a pg_extension root ALL
a pg_extension test-user CREATE
a pg_extension test-user DELETE
a pg_extension test-user DROP
a pg_extension test-user GRANT
a pg_extension test-user SELECT
a pg_extension test-user ZONECONFIG
a public admin ALL
a public readwrite CREATE
a public readwrite DELETE
......@@ -187,6 +209,18 @@ a pg_catalog test-user DROP
a pg_catalog test-user GRANT
a pg_catalog test-user SELECT
a pg_catalog test-user ZONECONFIG
a pg_extension readwrite CREATE
a pg_extension readwrite DELETE
a pg_extension readwrite DROP
a pg_extension readwrite GRANT
a pg_extension readwrite SELECT
a pg_extension readwrite ZONECONFIG
a pg_extension test-user CREATE
a pg_extension test-user DELETE
a pg_extension test-user DROP
a pg_extension test-user GRANT
a pg_extension test-user SELECT
a pg_extension test-user ZONECONFIG
a public readwrite CREATE
a public readwrite DELETE
a public readwrite DROP
......@@ -245,6 +279,19 @@ a pg_catalog test-user DELETE
a pg_catalog test-user DROP
a pg_catalog test-user GRANT
a pg_catalog test-user ZONECONFIG
a pg_extension admin ALL
a pg_extension readwrite CREATE
a pg_extension readwrite DELETE
a pg_extension readwrite DROP
a pg_extension readwrite GRANT
a pg_extension readwrite SELECT
a pg_extension readwrite ZONECONFIG
a pg_extension root ALL
a pg_extension test-user CREATE
a pg_extension test-user DELETE
a pg_extension test-user DROP
a pg_extension test-user GRANT
a pg_extension test-user ZONECONFIG
a public admin ALL
a public readwrite CREATE
a public readwrite DELETE
......@@ -283,6 +330,12 @@ a pg_catalog readwrite DROP
a pg_catalog readwrite GRANT
a pg_catalog readwrite SELECT
a pg_catalog readwrite ZONECONFIG
a pg_extension readwrite CREATE
a pg_extension readwrite DELETE
a pg_extension readwrite DROP
a pg_extension readwrite GRANT
a pg_extension readwrite SELECT
a pg_extension readwrite ZONECONFIG
a public readwrite CREATE
a public readwrite DELETE
a public readwrite DROP
......@@ -302,6 +355,8 @@ a information_schema admin ALL
a information_schema root ALL
a pg_catalog admin ALL
a pg_catalog root ALL
a pg_extension admin ALL
a pg_extension root ALL
a public admin ALL
a public root ALL
......
......@@ -196,6 +196,7 @@ catalog_name schema_name default_character_set_name sql_path
test crdb_internal NULL NULL
test information_schema NULL NULL
test pg_catalog NULL NULL
test pg_extension NULL NULL
test public NULL NULL
query TTTT colnames
......@@ -205,6 +206,7 @@ catalog_name schema_name default_character_set_name sql_path
test crdb_internal NULL NULL
test information_schema NULL NULL
test pg_catalog NULL NULL
test pg_extension NULL NULL
test public NULL NULL
## information_schema.tables
......@@ -323,6 +325,9 @@ pg_catalog pg_type
pg_catalog pg_user
pg_catalog pg_user_mapping
pg_catalog pg_views
pg_extension geography_columns
pg_extension geometry_columns
pg_extension spatial_ref_sys
statement ok
CREATE DATABASE other_db
......@@ -467,6 +472,9 @@ pg_type
pg_user
pg_user_mapping
pg_views
geography_columns
geometry_columns
spatial_ref_sys
xyz
# Check that the other_db tables become visible to non-root when the current database is changed.
......@@ -618,6 +626,9 @@ system pg_catalog pg_type SYSTEM VIE
system pg_catalog pg_user SYSTEM VIEW NO 1
system pg_catalog pg_user_mapping SYSTEM VIEW NO 1
system pg_catalog pg_views SYSTEM VIEW NO 1
system pg_extension geography_columns SYSTEM VIEW NO 1
system pg_extension geometry_columns SYSTEM VIEW NO 1
system pg_extension spatial_ref_sys SYSTEM VIEW NO 1
system public namespace BASE TABLE YES 1
system public descriptor BASE TABLE YES 1
system public users BASE TABLE YES 1
......@@ -1083,6 +1094,20 @@ system public eventlog reportingID
system public eventlog targetID 3
system public eventlog timestamp 1
system public eventlog uniqueID 6
system pg_extension geography_columns coord_dimension 5
system pg_extension geography_columns f_geography_column 4
system pg_extension geography_columns f_table_catalog 1
system pg_extension geography_columns f_table_name 3
system pg_extension geography_columns f_table_schema 2
system pg_extension geography_columns srid 6
system pg_extension geography_columns type 7
system pg_extension geometry_columns coord_dimension 5
system pg_extension geometry_columns f_geometry_column 4
system pg_extension geometry_columns f_table_catalog 1
system pg_extension geometry_columns f_table_name 3
system pg_extension geometry_columns f_table_schema 2
system pg_extension geometry_columns srid 6
system pg_extension geometry_columns type 7
system public jobs created 3
system public jobs id 1
system public jobs payload 4
......@@ -1153,6 +1178,11 @@ system public settings lastUpdated
system public settings name 1
system public settings value 2
system public settings valueType 4
system pg_extension spatial_ref_sys auth_name 2
system pg_extension spatial_ref_sys auth_srid 3
system pg_extension spatial_ref_sys proj4text 5
system pg_extension spatial_ref_sys srid 1
system pg_extension spatial_ref_sys srtext 4
system public statement_bundle_chunks data 3
system public statement_bundle_chunks description 2
system public statement_bundle_chunks id 1
......@@ -1477,6 +1507,8 @@ admin other_db information_schema ALL NULL
root other_db information_schema ALL NULL
admin other_db pg_catalog ALL NULL
root other_db pg_catalog ALL NULL
admin other_db pg_extension ALL NULL
root other_db pg_extension ALL NULL
admin other_db public ALL NULL
root other_db public ALL NULL
......@@ -1496,6 +1528,9 @@ testuser other_db information_schema SELECT NULL
admin other_db pg_catalog ALL NULL
root other_db pg_catalog ALL NULL
testuser other_db pg_catalog SELECT NULL
admin other_db pg_extension ALL NULL
root other_db pg_extension ALL NULL
testuser other_db pg_extension SELECT NULL
admin other_db public ALL NULL
root other_db public ALL NULL
testuser other_db public SELECT NULL
......@@ -1616,6 +1651,9 @@ NULL public system pg_catalog pg_type
NULL public system pg_catalog pg_user SELECT NULL YES
NULL public system pg_catalog pg_user_mapping SELECT NULL YES
NULL public system pg_catalog pg_views SELECT NULL YES
NULL public system pg_extension geography_columns SELECT NULL YES
NULL public system pg_extension geometry_columns SELECT NULL YES
NULL public system pg_extension spatial_ref_sys SELECT NULL YES
NULL admin system public comments DELETE NULL NO
NULL admin system public comments GRANT NULL NO
NULL admin system public comments INSERT NULL NO
......@@ -1961,6 +1999,9 @@ NULL public system pg_catalog pg_type
NULL public system pg_catalog pg_user SELECT NULL YES
NULL public system pg_catalog pg_user_mapping SELECT NULL YES
NULL public system pg_catalog pg_views SELECT NULL YES
NULL public system pg_extension geography_columns SELECT NULL YES
NULL public system pg_extension geometry_columns SELECT NULL YES
NULL public system pg_extension spatial_ref_sys SELECT NULL YES
NULL admin system public namespace GRANT NULL NO
NULL admin system public namespace SELECT NULL YES
NULL root system public namespace GRANT NULL NO
......
......@@ -228,6 +228,7 @@ oid nspname nspowner nspacl
3604332469 crdb_internal NULL NULL
3672231114 information_schema NULL NULL
2508829085 pg_catalog NULL NULL
1841002695 pg_extension NULL NULL
3426283741 public NULL NULL
## pg_catalog.pg_database
......@@ -1597,6 +1598,9 @@ objoid classoid objsubid description
4294967193 4294967226 0 database users
4294967192 4294967226 0 local to remote user mapping (empty - feature does not exist)
4294967187 4294967226 0 view definitions (incomplete - see also information_schema.views)
4294967182 4294967226 0 Shows all defined geography columns. Matches PostGIS' geography_columns functionality.
4294967181 4294967226 0 Shows all defined geometry columns. Matches PostGIS' geometry_columns functionality.
4294967180 4294967226 0 Shows all defined Spatial Reference Identifiers (SRIDs). Matches PostGIS' spatial_ref_sys table.
## pg_catalog.pg_shdescription
......
......@@ -15,6 +15,8 @@ test information_schema admin ALL
test information_schema root ALL
test pg_catalog admin ALL
test pg_catalog root ALL
test pg_extension admin ALL
test pg_extension root ALL
test public admin ALL
test public root ALL
......@@ -69,6 +71,8 @@ u information_schema admin ALL
u information_schema root ALL
u pg_catalog admin ALL
u pg_catalog root ALL
u pg_extension admin ALL
u pg_extension root ALL
u public admin ALL
u public root ALL
......
......@@ -674,6 +674,9 @@ db2 information_schema root ALL
db2 pg_catalog admin ALL
db2 pg_catalog newgroup ALL
db2 pg_catalog root ALL
db2 pg_extension admin ALL
db2 pg_extension newgroup ALL
db2 pg_extension root ALL
db2 public admin ALL
db2 public newgroup ALL
db2 public root ALL
......
......@@ -170,6 +170,7 @@ schema_name
crdb_internal
information_schema
pg_catalog
pg_extension
public
query T colnames
......@@ -261,6 +262,7 @@ schema_name
crdb_internal
information_schema
pg_catalog
pg_extension
public
query TTT colnames
......
......@@ -173,6 +173,10 @@ system pg_catalog admin GRANT
system pg_catalog admin SELECT
system pg_catalog root GRANT
system pg_catalog root SELECT
system pg_extension admin GRANT
system pg_extension admin SELECT
system pg_extension root GRANT
system pg_extension root SELECT
system public admin GRANT
system public admin SELECT
system public root GRANT
......
......@@ -193,7 +193,7 @@ render · ·
│ type inner
│ equality (oid) = (relnamespace)
├── filter · ·
│ │ filter nspname NOT IN ('crdb_internal', 'information_schema', 'pg_catalog')
│ │ filter nspname NOT IN ('crdb_internal', 'information_schema', 'pg_catalog', 'pg_extension')
│ └── render · ·
│ └── virtual table · ·
│ source [email protected]
......@@ -219,7 +219,7 @@ render · ·
│ │ type inner
│ │ equality (oid) = (relnamespace)
│ ├── filter · ·
│ │ │ filter nspname NOT IN ('crdb_internal', 'information_schema', 'pg_catalog')
│ │ │ filter nspname NOT IN ('crdb_internal', 'information_schema', 'pg_catalog', 'pg_extension')
│ │ └── render · ·
│ │ └── virtual table · ·
│ │ source [email protected]
......
// Copyright 2017 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package sql
import (
"context"
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/errors"
)
// pgExtension is virtual schema which contains virtual tables and/or views
// which are used by postgres extensions. Postgres extensions typically install
// these tables and views on the public schema, but we instead do it in
// our own defined virtual table / schema.
var pgExtension = virtualSchema{
name: sessiondata.PgExtensionSchemaName,
tableDefs: map[sqlbase.ID]virtualSchemaDef{
sqlbase.PgExtensionGeographyColumnsTableID: pgExtensionGeographyColumnsTable,
sqlbase.PgExtensionGeometryColumnsTableID: pgExtensionGeometryColumnsTable,
sqlbase.PgExtensionSpatialRefSysTableID: pgExtensionSpatialRefSysTable,
},
validWithNoDatabaseContext: false,
}
var pgExtensionGeographyColumnsTable = virtualSchemaTable{
comment: `Shows all defined geography columns. Matches PostGIS' geography_columns functionality.`,
schema: `
CREATE TABLE pg_extension.geography_columns (
f_table_catalog name,
f_table_schema name,
f_table_name name,
f_geography_column name,
coord_dimension integer,
srid integer,
type text
)`,
generator: func(ctx context.Context, p *planner, db *DatabaseDescriptor) (virtualTableGenerator, cleanupFunc, error) {
return nil, func() {}, errors.Newf("not yet implemented")
},
}
var pgExtensionGeometryColumnsTable = virtualSchemaTable{
comment: `Shows all defined geometry columns. Matches PostGIS' geometry_columns functionality.`,
schema: `
CREATE TABLE pg_extension.geometry_columns (
f_table_catalog name,
f_table_schema name,
f_table_name name,
f_geometry_column name,
coord_dimension integer,
srid integer,
type text
)`,
generator: func(ctx context.Context, p *planner, db *DatabaseDescriptor) (virtualTableGenerator, cleanupFunc, error) {
return nil, func() {}, errors.Newf("not yet implemented")
},
}
var pgExtensionSpatialRefSysTable = virtualSchemaTable{
comment: `Shows all defined Spatial Reference Identifiers (SRIDs). Matches PostGIS' spatial_ref_sys table.`,
schema: `
CREATE TABLE pg_extension.spatial_ref_sys (
srid integer,
auth_name varchar(256),
auth_srid integer,
srtext varchar(2048),
proj4text varchar(2048)
)`,
generator: func(ctx context.Context, p *planner, db *DatabaseDescriptor) (virtualTableGenerator, cleanupFunc, error) {
return nil, func() {}, errors.Newf("not yet implemented")
},
}
......@@ -553,7 +553,7 @@ func TestPGPreparedQuery(t *testing.T) {
baseTest.Results("public", "comments", "table").Others(25),
}},
{"SHOW SCHEMAS FROM system", []preparedQueryTest{
baseTest.Results("crdb_internal").Others(3),
baseTest.Results("crdb_internal").Others(4),
}},
{"SHOW CONSTRAINTS FROM system.users", []preparedQueryTest{
baseTest.Results("users", "primary", "PRIMARY KEY", "PRIMARY KEY (username ASC)", true),
......
......@@ -29,6 +29,7 @@ var staticSchemaIDMap = map[sqlbase.ID]string{
sqlbase.PgCatalogID: sessiondata.PgCatalogName,
sqlbase.InformationSchemaID: sessiondata.InformationSchemaName,
sqlbase.CrdbInternalID: sessiondata.CRDBInternalSchemaName,
sqlbase.PgExtensionSchemaID: sessiondata.PgExtensionSchemaName,
}
// ResolveNameByID resolves a schema's name based on db and schema id.
......
......@@ -36,6 +36,10 @@ const CRDBInternalSchemaName = "crdb_internal"
// PgTempSchemaName is the alias for temporary schemas across sessions.
const PgTempSchemaName = "pg_temp"
// PgExtensionSchemaName is the alias for schemas which are usually "public" in postgres
// when installing an extension, but must be stored as a separate schema in CRDB.
const PgExtensionSchemaName = "pg_extension"
// SearchPath represents a list of namespaces to search builtins in.
// The names must be normalized (as per Name.Normalize) already.
type SearchPath struct {
......
......@@ -160,5 +160,9 @@ const (
PgCatalogStatActivityTableID
PgCatalogSecurityLabelTableID
PgCatalogSharedSecurityLabelTableID
MinVirtualID = PgCatalogSharedSecurityLabelTableID
PgExtensionSchemaID
PgExtensionGeographyColumnsTableID
PgExtensionGeometryColumnsTableID
PgExtensionSpatialRefSysTableID
MinVirtualID = PgExtensionSpatialRefSysTableID
)
......@@ -253,6 +253,7 @@ var virtualSchemas = map[sqlbase.ID]virtualSchema{
sqlbase.InformationSchemaID: informationSchema,
sqlbase.PgCatalogID: pgCatalog,
sqlbase.CrdbInternalID: crdbInternal,
sqlbase.PgExtensionSchemaID: pgExtension,
}
//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment