From cb7bf9f07daa38497c78e5bc72682aedc5bf6046 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sat, 13 Jul 2019 13:52:44 -0400 Subject: [PATCH 01/17] sql: add empty pg_matviews virtual table Release note: None --- .../logictest/testdata/logic_test/grant_table | 1 + .../testdata/logic_test/information_schema | 5 +++ pkg/sql/logictest/testdata/logic_test/join | 2 - .../logictest/testdata/logic_test/pg_catalog | 39 ++++++++++--------- .../logictest/testdata/logic_test/pgoidtype | 14 ++++--- pkg/sql/logictest/testdata/planner_test/join | 4 -- pkg/sql/opt/exec/execbuilder/testdata/join | 8 +--- pkg/sql/pg_catalog.go | 19 +++++++++ pkg/sql/sqlbase/constants.go | 1 + 9 files changed, 57 insertions(+), 36 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/grant_table b/pkg/sql/logictest/testdata/logic_test/grant_table index bbf25bd8517a..45ae5c19fd2d 100644 --- a/pkg/sql/logictest/testdata/logic_test/grant_table +++ b/pkg/sql/logictest/testdata/logic_test/grant_table @@ -111,6 +111,7 @@ test pg_catalog pg_index public S 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_matviews public SELECT test pg_catalog pg_namespace public SELECT test pg_catalog pg_operator public SELECT test pg_catalog pg_proc public SELECT diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 4350e2f38c17..438cdf5f90f1 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -287,6 +287,7 @@ pg_catalog pg_index pg_catalog pg_indexes pg_catalog pg_inherits pg_catalog pg_language +pg_catalog pg_matviews pg_catalog pg_namespace pg_catalog pg_operator pg_catalog pg_proc @@ -415,6 +416,7 @@ pg_index pg_indexes pg_inherits pg_language +pg_matviews pg_namespace pg_operator pg_proc @@ -550,6 +552,7 @@ system pg_catalog pg_index SYSTEM VIE system pg_catalog pg_indexes SYSTEM VIEW NO 1 system pg_catalog pg_inherits SYSTEM VIEW NO 1 system pg_catalog pg_language SYSTEM VIEW NO 1 +system pg_catalog pg_matviews SYSTEM VIEW NO 1 system pg_catalog pg_namespace SYSTEM VIEW NO 1 system pg_catalog pg_operator SYSTEM VIEW NO 1 system pg_catalog pg_proc SYSTEM VIEW NO 1 @@ -1282,6 +1285,7 @@ NULL public system pg_catalog pg_index NULL public system pg_catalog pg_indexes SELECT NULL YES NULL public system pg_catalog pg_inherits SELECT NULL YES NULL public system pg_catalog pg_language SELECT NULL YES +NULL public system pg_catalog pg_matviews SELECT NULL YES NULL public system pg_catalog pg_namespace SELECT NULL YES NULL public system pg_catalog pg_operator SELECT NULL YES NULL public system pg_catalog pg_proc SELECT NULL YES @@ -1523,6 +1527,7 @@ NULL public system pg_catalog pg_index NULL public system pg_catalog pg_indexes SELECT NULL YES NULL public system pg_catalog pg_inherits SELECT NULL YES NULL public system pg_catalog pg_language SELECT NULL YES +NULL public system pg_catalog pg_matviews SELECT NULL YES NULL public system pg_catalog pg_namespace SELECT NULL YES NULL public system pg_catalog pg_operator SELECT NULL YES NULL public system pg_catalog pg_proc SELECT NULL YES diff --git a/pkg/sql/logictest/testdata/logic_test/join b/pkg/sql/logictest/testdata/logic_test/join index eab27e80bba1..421ee08b35a7 100644 --- a/pkg/sql/logictest/testdata/logic_test/join +++ b/pkg/sql/logictest/testdata/logic_test/join @@ -553,8 +553,6 @@ SELECT NULL::text AS pktable_cat, AND con.oid = dep.objid AND pkic.oid = dep.refobjid AND pkic.relkind = 'i' - AND dep.classid = 'pg_constraint'::regclass::oid - AND dep.refclassid = 'pg_class'::regclass::oid AND fkn.nspname = 'public' AND fkc.relname = 'orders' ORDER BY pkn.nspname, diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 1fc6b3333283..14a69ae0518a 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -36,6 +36,7 @@ pg_index pg_indexes pg_inherits pg_language +pg_matviews pg_namespace pg_operator pg_proc @@ -100,6 +101,7 @@ pg_index pg_indexes pg_inherits pg_language +pg_matviews pg_namespace pg_operator pg_proc @@ -1400,25 +1402,26 @@ objoid classoid objsubid description 4294967220 4294967233 0 index creation statements 4294967219 4294967233 0 table inheritance hierarchy (empty - feature does not exist) 4294967218 4294967233 0 available languages (empty - feature does not exist) -4294967217 4294967233 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) -4294967216 4294967233 0 operators (incomplete) -4294967215 4294967233 0 built-in functions (incomplete) -4294967214 4294967233 0 range types (empty - feature does not exist) -4294967213 4294967233 0 rewrite rules (empty - feature does not exist) -4294967212 4294967233 0 database roles -4294967201 4294967233 0 security labels (empty - feature does not exist) -4294967211 4294967233 0 sequences (see also information_schema.sequences) -4294967210 4294967233 0 session variables (incomplete) +4294967217 4294967233 0 available materialized views (empty - feature does not exist) +4294967216 4294967233 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) +4294967215 4294967233 0 operators (incomplete) +4294967214 4294967233 0 built-in functions (incomplete) +4294967213 4294967233 0 range types (empty - feature does not exist) +4294967212 4294967233 0 rewrite rules (empty - feature does not exist) +4294967211 4294967233 0 database roles +4294967200 4294967233 0 security labels (empty - feature does not exist) +4294967210 4294967233 0 sequences (see also information_schema.sequences) +4294967209 4294967233 0 session variables (incomplete) 4294967227 4294967233 0 shared object comments -4294967200 4294967233 0 shared security labels (empty - feature not supported) -4294967202 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) -4294967207 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) -4294967206 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) -4294967205 4294967233 0 triggers (empty - feature does not exist) -4294967204 4294967233 0 scalar types (incomplete) -4294967209 4294967233 0 database users -4294967208 4294967233 0 local to remote user mapping (empty - feature does not exist) -4294967203 4294967233 0 view definitions (incomplete - see also information_schema.views) +4294967199 4294967233 0 shared security labels (empty - feature not supported) +4294967201 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) +4294967206 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) +4294967205 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) +4294967204 4294967233 0 triggers (empty - feature does not exist) +4294967203 4294967233 0 scalar types (incomplete) +4294967208 4294967233 0 database users +4294967207 4294967233 0 local to remote user mapping (empty - feature does not exist) +4294967202 4294967233 0 view definitions (incomplete - see also information_schema.views) ## pg_catalog.pg_shdescription diff --git a/pkg/sql/logictest/testdata/logic_test/pgoidtype b/pkg/sql/logictest/testdata/logic_test/pgoidtype index f06cd794fbdc..049de0aab087 100644 --- a/pkg/sql/logictest/testdata/logic_test/pgoidtype +++ b/pkg/sql/logictest/testdata/logic_test/pgoidtype @@ -58,10 +58,12 @@ SELECT 'pg_constraint '::REGCLASS, ' pg_constraint '::REGCLASS ---- pg_constraint pg_constraint +# This weird form is to avoid making the test depend on the concrete value of +# the pg_constraint table id. query OO -SELECT 'pg_constraint '::REGCLASS, '"pg_constraint"'::REGCLASS::OID +SELECT 'pg_constraint '::REGCLASS, ('"pg_constraint"'::REGCLASS::OID::INT-'"pg_constraint"'::REGCLASS::OID::INT)::OID ---- -pg_constraint 4294967231 +pg_constraint 0 query O SELECT 4061301040::REGCLASS @@ -69,11 +71,11 @@ SELECT 4061301040::REGCLASS 4061301040 query OOIOT -SELECT oid, oid::regclass, oid::regclass::int, oid::regclass::int::regclass, oid::regclass::text +SELECT (oid::int-oid::int)::oid, oid::regclass, (oid::regclass::int-oid::regclass::int), oid::regclass::int::regclass, oid::regclass::text FROM pg_class WHERE relname = 'pg_constraint' ---- -4294967231 pg_constraint 4294967231 pg_constraint pg_constraint +0 pg_constraint 0 pg_constraint pg_constraint query OOOO SELECT 'upper'::REGPROC, 'upper'::REGPROCEDURE, 'pg_catalog.upper'::REGPROCEDURE, 'upper'::REGPROC::OID @@ -158,9 +160,9 @@ pg_constraint # This forces the b_expr form of the cast syntax. query OO -SELECT ('pg_constraint')::REGCLASS, ('pg_constraint')::REGCLASS::OID +SELECT ('pg_constraint')::REGCLASS, (('pg_constraint')::REGCLASS::OID::INT-('pg_constraint')::REGCLASS::OID::INT)::OID ---- -pg_constraint 4294967231 +pg_constraint 0 ## Test visibility of pg_* via oid casts. diff --git a/pkg/sql/logictest/testdata/planner_test/join b/pkg/sql/logictest/testdata/planner_test/join index ce4628505b8a..d568b16f4ccd 100644 --- a/pkg/sql/logictest/testdata/planner_test/join +++ b/pkg/sql/logictest/testdata/planner_test/join @@ -325,8 +325,6 @@ SELECT level, node_type, field, description FROM [EXPLAIN (VERBOSE) SELECT AND con.oid = dep.objid AND pkic.oid = dep.refobjid AND pkic.relkind = 'i' - AND dep.classid = 'pg_constraint'::regclass::oid - AND dep.refclassid = 'pg_class'::regclass::oid AND fkn.nspname = 'public' AND fkc.relname = 'orders' ORDER BY pkn.nspname, @@ -388,8 +386,6 @@ SELECT level, node_type, field, description FROM [EXPLAIN (VERBOSE) SELECT 10 · type inner 10 · equality (refobjid) = (oid) 11 filter · · -11 · filter (dep.classid = 4294967231) AND (dep.refclassid = 4294967233) -11 filter · · 11 · filter pkic.relkind = 'i' diff --git a/pkg/sql/opt/exec/execbuilder/testdata/join b/pkg/sql/opt/exec/execbuilder/testdata/join index 1e2da2c29487..b065d4cee762 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/join +++ b/pkg/sql/opt/exec/execbuilder/testdata/join @@ -282,8 +282,6 @@ SELECT level, node_type, field, description FROM [EXPLAIN (VERBOSE) SELECT AND con.oid = dep.objid AND pkic.oid = dep.refobjid AND pkic.relkind = 'i' - AND dep.classid = 'pg_constraint'::regclass::oid - AND dep.refclassid = 'pg_class'::regclass::oid AND fkn.nspname = 'public' AND fkc.relname = 'orders' ORDER BY pkn.nspname, @@ -372,10 +370,8 @@ SELECT level, node_type, field, description FROM [EXPLAIN (VERBOSE) SELECT 6 project set · · 6 · render 0 generate_series(1, 32) 7 emptyrow · · -5 filter · · -5 · filter (classid = 4294967231) AND (refclassid = 4294967233) -6 virtual table · · -6 · source · +5 virtual table · · +5 · source · 4 filter · · 4 · filter relkind = 'i' 5 virtual table · · diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index d6556bed0d89..9710d66b35e9 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -204,6 +204,7 @@ var pgCatalog = virtualSchema{ sqlbase.PgCatalogIndexesTableID: pgCatalogIndexesTable, sqlbase.PgCatalogInheritsTableID: pgCatalogInheritsTable, sqlbase.PgCatalogLanguageTableID: pgCatalogLanguageTable, + sqlbase.PgCatalogMatViewsTableID: pgCatalogMatViewsTable, sqlbase.PgCatalogNamespaceTableID: pgCatalogNamespaceTable, sqlbase.PgCatalogOperatorTableID: pgCatalogOperatorTable, sqlbase.PgCatalogProcTableID: pgCatalogProcTable, @@ -1440,6 +1441,24 @@ CREATE TABLE pg_catalog.pg_language ( }, } +var pgCatalogMatViewsTable = virtualSchemaTable{ + comment: `available materialized views (empty - feature does not exist) +https://www.postgresql.org/docs/9.6/view-pg-matviews.html`, + schema: ` +CREATE TABLE pg_catalog.pg_matviews ( + schemaname NAME, + matviewname NAME, + matviewowner NAME, + tablespace NAME, + hasindexes BOOL, + ispopulated BOOL, + definition TEXT +)`, + populate: func(ctx context.Context, p *planner, dbContext *DatabaseDescriptor, addRow func(...tree.Datum) error) error { + return nil + }, +} + var pgCatalogNamespaceTable = virtualSchemaTable{ comment: `available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) https://www.postgresql.org/docs/9.5/catalog-pg-namespace.html`, diff --git a/pkg/sql/sqlbase/constants.go b/pkg/sql/sqlbase/constants.go index 0f6c16b27c5e..ce461c9a0312 100644 --- a/pkg/sql/sqlbase/constants.go +++ b/pkg/sql/sqlbase/constants.go @@ -126,6 +126,7 @@ const ( PgCatalogIndexesTableID PgCatalogInheritsTableID PgCatalogLanguageTableID + PgCatalogMatViewsTableID PgCatalogNamespaceTableID PgCatalogOperatorTableID PgCatalogProcTableID From 4e30c4219bb803f05a1df69ebe17835684e36b40 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sat, 13 Jul 2019 14:13:41 -0400 Subject: [PATCH 02/17] sql: add empty pg_conversion table Release note: None --- .../logictest/testdata/logic_test/grant_table | 1 + .../testdata/logic_test/information_schema | 5 ++ .../logictest/testdata/logic_test/pg_catalog | 67 ++++++++++--------- pkg/sql/pg_catalog.go | 20 ++++++ pkg/sql/sqlbase/constants.go | 1 + 5 files changed, 62 insertions(+), 32 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/grant_table b/pkg/sql/logictest/testdata/logic_test/grant_table index 45ae5c19fd2d..5407c54b8e78 100644 --- a/pkg/sql/logictest/testdata/logic_test/grant_table +++ b/pkg/sql/logictest/testdata/logic_test/grant_table @@ -99,6 +99,7 @@ test pg_catalog pg_auth_members public S 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_conversion public SELECT test pg_catalog pg_database public SELECT test pg_catalog pg_depend public SELECT test pg_catalog pg_description public SELECT diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 438cdf5f90f1..8aa049444d54 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -275,6 +275,7 @@ pg_catalog pg_auth_members pg_catalog pg_class pg_catalog pg_collation pg_catalog pg_constraint +pg_catalog pg_conversion pg_catalog pg_database pg_catalog pg_depend pg_catalog pg_description @@ -404,6 +405,7 @@ pg_auth_members pg_class pg_collation pg_constraint +pg_conversion pg_database pg_depend pg_description @@ -540,6 +542,7 @@ system pg_catalog pg_auth_members SYSTEM VIE system pg_catalog pg_class SYSTEM VIEW NO 1 system pg_catalog pg_collation SYSTEM VIEW NO 1 system pg_catalog pg_constraint SYSTEM VIEW NO 1 +system pg_catalog pg_conversion SYSTEM VIEW NO 1 system pg_catalog pg_database SYSTEM VIEW NO 1 system pg_catalog pg_depend SYSTEM VIEW NO 1 system pg_catalog pg_description SYSTEM VIEW NO 1 @@ -1273,6 +1276,7 @@ NULL public system pg_catalog pg_auth_members NULL public system pg_catalog pg_class SELECT NULL YES NULL public system pg_catalog pg_collation SELECT NULL YES NULL public system pg_catalog pg_constraint SELECT NULL YES +NULL public system pg_catalog pg_conversion SELECT NULL YES NULL public system pg_catalog pg_database SELECT NULL YES NULL public system pg_catalog pg_depend SELECT NULL YES NULL public system pg_catalog pg_description SELECT NULL YES @@ -1515,6 +1519,7 @@ NULL public system pg_catalog pg_auth_members NULL public system pg_catalog pg_class SELECT NULL YES NULL public system pg_catalog pg_collation SELECT NULL YES NULL public system pg_catalog pg_constraint SELECT NULL YES +NULL public system pg_catalog pg_conversion SELECT NULL YES NULL public system pg_catalog pg_database SELECT NULL YES NULL public system pg_catalog pg_depend SELECT NULL YES NULL public system pg_catalog pg_description SELECT NULL YES diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 14a69ae0518a..0d5d0e98d797 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -24,6 +24,7 @@ pg_auth_members pg_class pg_collation pg_constraint +pg_conversion pg_database pg_depend pg_description @@ -89,6 +90,7 @@ pg_auth_members pg_class pg_collation pg_constraint +pg_conversion pg_database pg_depend pg_description @@ -1390,38 +1392,39 @@ objoid classoid objsubid description 4294967233 4294967233 0 tables and relation-like objects (incomplete - see also information_schema.tables/sequences/views) 4294967232 4294967233 0 available collations (incomplete) 4294967231 4294967233 0 table constraints (incomplete - see also information_schema.table_constraints) -4294967230 4294967233 0 available databases (incomplete) -4294967229 4294967233 0 dependency relationships (incomplete) -4294967228 4294967233 0 object comments -4294967226 4294967233 0 enum types and labels (empty - feature does not exist) -4294967225 4294967233 0 installed extensions (empty - feature does not exist) -4294967224 4294967233 0 foreign data wrappers (empty - feature does not exist) -4294967223 4294967233 0 foreign servers (empty - feature does not exist) -4294967222 4294967233 0 foreign tables (empty - feature does not exist) -4294967221 4294967233 0 indexes (incomplete) -4294967220 4294967233 0 index creation statements -4294967219 4294967233 0 table inheritance hierarchy (empty - feature does not exist) -4294967218 4294967233 0 available languages (empty - feature does not exist) -4294967217 4294967233 0 available materialized views (empty - feature does not exist) -4294967216 4294967233 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) -4294967215 4294967233 0 operators (incomplete) -4294967214 4294967233 0 built-in functions (incomplete) -4294967213 4294967233 0 range types (empty - feature does not exist) -4294967212 4294967233 0 rewrite rules (empty - feature does not exist) -4294967211 4294967233 0 database roles -4294967200 4294967233 0 security labels (empty - feature does not exist) -4294967210 4294967233 0 sequences (see also information_schema.sequences) -4294967209 4294967233 0 session variables (incomplete) -4294967227 4294967233 0 shared object comments -4294967199 4294967233 0 shared security labels (empty - feature not supported) -4294967201 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) -4294967206 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) -4294967205 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) -4294967204 4294967233 0 triggers (empty - feature does not exist) -4294967203 4294967233 0 scalar types (incomplete) -4294967208 4294967233 0 database users -4294967207 4294967233 0 local to remote user mapping (empty - feature does not exist) -4294967202 4294967233 0 view definitions (incomplete - see also information_schema.views) +4294967230 4294967233 0 encoding conversions (empty - unimplemented) +4294967229 4294967233 0 available databases (incomplete) +4294967228 4294967233 0 dependency relationships (incomplete) +4294967227 4294967233 0 object comments +4294967225 4294967233 0 enum types and labels (empty - feature does not exist) +4294967224 4294967233 0 installed extensions (empty - feature does not exist) +4294967223 4294967233 0 foreign data wrappers (empty - feature does not exist) +4294967222 4294967233 0 foreign servers (empty - feature does not exist) +4294967221 4294967233 0 foreign tables (empty - feature does not exist) +4294967220 4294967233 0 indexes (incomplete) +4294967219 4294967233 0 index creation statements +4294967218 4294967233 0 table inheritance hierarchy (empty - feature does not exist) +4294967217 4294967233 0 available languages (empty - feature does not exist) +4294967216 4294967233 0 available materialized views (empty - feature does not exist) +4294967215 4294967233 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) +4294967214 4294967233 0 operators (incomplete) +4294967213 4294967233 0 built-in functions (incomplete) +4294967212 4294967233 0 range types (empty - feature does not exist) +4294967211 4294967233 0 rewrite rules (empty - feature does not exist) +4294967210 4294967233 0 database roles +4294967199 4294967233 0 security labels (empty - feature does not exist) +4294967209 4294967233 0 sequences (see also information_schema.sequences) +4294967208 4294967233 0 session variables (incomplete) +4294967226 4294967233 0 shared object comments +4294967198 4294967233 0 shared security labels (empty - feature not supported) +4294967200 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) +4294967205 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) +4294967204 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) +4294967203 4294967233 0 triggers (empty - feature does not exist) +4294967202 4294967233 0 scalar types (incomplete) +4294967207 4294967233 0 database users +4294967206 4294967233 0 local to remote user mapping (empty - feature does not exist) +4294967201 4294967233 0 view definitions (incomplete - see also information_schema.views) ## pg_catalog.pg_shdescription diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 9710d66b35e9..3a2d53a550ed 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -191,6 +191,7 @@ var pgCatalog = virtualSchema{ sqlbase.PgCatalogClassTableID: pgCatalogClassTable, sqlbase.PgCatalogCollationTableID: pgCatalogCollationTable, sqlbase.PgCatalogConstraintTableID: pgCatalogConstraintTable, + sqlbase.PgCatalogConversionTableID: pgCatalogConversionTable, sqlbase.PgCatalogDatabaseTableID: pgCatalogDatabaseTable, sqlbase.PgCatalogDependTableID: pgCatalogDependTable, sqlbase.PgCatalogDescriptionTableID: pgCatalogDescriptionTable, @@ -881,6 +882,25 @@ func colIDArrayToVector(arr []sqlbase.ColumnID) (tree.Datum, error) { return tree.NewDIntVectorFromDArray(tree.MustBeDArray(dArr)), nil } +var pgCatalogConversionTable = virtualSchemaTable{ + comment: `encoding conversions (empty - unimplemented) +https://www.postgresql.org/docs/9.6/catalog-pg-conversion.html`, + schema: ` +CREATE TABLE pg_catalog.pg_conversion ( + oid OID, + conname NAME, + connamespace OID, + conowner OID, + conforencoding INT4, + contoencoding INT4, + conproc OID, + condefault BOOL +)`, + populate: func(ctx context.Context, p *planner, dbContext *DatabaseDescriptor, addRow func(...tree.Datum) error) error { + return nil + }, +} + var pgCatalogDatabaseTable = virtualSchemaTable{ comment: `available databases (incomplete) https://www.postgresql.org/docs/9.5/catalog-pg-database.html`, diff --git a/pkg/sql/sqlbase/constants.go b/pkg/sql/sqlbase/constants.go index ce461c9a0312..cb7b307a9b38 100644 --- a/pkg/sql/sqlbase/constants.go +++ b/pkg/sql/sqlbase/constants.go @@ -113,6 +113,7 @@ const ( PgCatalogClassTableID PgCatalogCollationTableID PgCatalogConstraintTableID + PgCatalogConversionTableID PgCatalogDatabaseTableID PgCatalogDependTableID PgCatalogDescriptionTableID From 3e2e451ab6c2b5dee3a58a142e9a98975e9e4b82 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 11:18:48 -0400 Subject: [PATCH 03/17] sql: add empty pg_locks Release note: None --- .../logictest/testdata/logic_test/grant_table | 1 + .../testdata/logic_test/information_schema | 5 +++ .../logictest/testdata/logic_test/pg_catalog | 41 ++++++++++--------- pkg/sql/pg_catalog.go | 27 ++++++++++++ pkg/sql/sqlbase/constants.go | 1 + 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/grant_table b/pkg/sql/logictest/testdata/logic_test/grant_table index 5407c54b8e78..a419b9f771ad 100644 --- a/pkg/sql/logictest/testdata/logic_test/grant_table +++ b/pkg/sql/logictest/testdata/logic_test/grant_table @@ -112,6 +112,7 @@ test pg_catalog pg_index public S 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_locks public SELECT test pg_catalog pg_matviews public SELECT test pg_catalog pg_namespace public SELECT test pg_catalog pg_operator public SELECT diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 8aa049444d54..ba21e53f9b63 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -288,6 +288,7 @@ pg_catalog pg_index pg_catalog pg_indexes pg_catalog pg_inherits pg_catalog pg_language +pg_catalog pg_locks pg_catalog pg_matviews pg_catalog pg_namespace pg_catalog pg_operator @@ -418,6 +419,7 @@ pg_index pg_indexes pg_inherits pg_language +pg_locks pg_matviews pg_namespace pg_operator @@ -555,6 +557,7 @@ system pg_catalog pg_index SYSTEM VIE system pg_catalog pg_indexes SYSTEM VIEW NO 1 system pg_catalog pg_inherits SYSTEM VIEW NO 1 system pg_catalog pg_language SYSTEM VIEW NO 1 +system pg_catalog pg_locks SYSTEM VIEW NO 1 system pg_catalog pg_matviews SYSTEM VIEW NO 1 system pg_catalog pg_namespace SYSTEM VIEW NO 1 system pg_catalog pg_operator SYSTEM VIEW NO 1 @@ -1289,6 +1292,7 @@ NULL public system pg_catalog pg_index NULL public system pg_catalog pg_indexes SELECT NULL YES NULL public system pg_catalog pg_inherits SELECT NULL YES NULL public system pg_catalog pg_language SELECT NULL YES +NULL public system pg_catalog pg_locks SELECT NULL YES NULL public system pg_catalog pg_matviews SELECT NULL YES NULL public system pg_catalog pg_namespace SELECT NULL YES NULL public system pg_catalog pg_operator SELECT NULL YES @@ -1532,6 +1536,7 @@ NULL public system pg_catalog pg_index NULL public system pg_catalog pg_indexes SELECT NULL YES NULL public system pg_catalog pg_inherits SELECT NULL YES NULL public system pg_catalog pg_language SELECT NULL YES +NULL public system pg_catalog pg_locks SELECT NULL YES NULL public system pg_catalog pg_matviews SELECT NULL YES NULL public system pg_catalog pg_namespace SELECT NULL YES NULL public system pg_catalog pg_operator SELECT NULL YES diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 0d5d0e98d797..dc25e29811c1 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -37,6 +37,7 @@ pg_index pg_indexes pg_inherits pg_language +pg_locks pg_matviews pg_namespace pg_operator @@ -103,6 +104,7 @@ pg_index pg_indexes pg_inherits pg_language +pg_locks pg_matviews pg_namespace pg_operator @@ -1405,26 +1407,27 @@ objoid classoid objsubid description 4294967219 4294967233 0 index creation statements 4294967218 4294967233 0 table inheritance hierarchy (empty - feature does not exist) 4294967217 4294967233 0 available languages (empty - feature does not exist) -4294967216 4294967233 0 available materialized views (empty - feature does not exist) -4294967215 4294967233 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) -4294967214 4294967233 0 operators (incomplete) -4294967213 4294967233 0 built-in functions (incomplete) -4294967212 4294967233 0 range types (empty - feature does not exist) -4294967211 4294967233 0 rewrite rules (empty - feature does not exist) -4294967210 4294967233 0 database roles -4294967199 4294967233 0 security labels (empty - feature does not exist) -4294967209 4294967233 0 sequences (see also information_schema.sequences) -4294967208 4294967233 0 session variables (incomplete) +4294967216 4294967233 0 locks held by active processes (empty - feature does not exist) +4294967215 4294967233 0 available materialized views (empty - feature does not exist) +4294967214 4294967233 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) +4294967213 4294967233 0 operators (incomplete) +4294967212 4294967233 0 built-in functions (incomplete) +4294967211 4294967233 0 range types (empty - feature does not exist) +4294967210 4294967233 0 rewrite rules (empty - feature does not exist) +4294967209 4294967233 0 database roles +4294967198 4294967233 0 security labels (empty - feature does not exist) +4294967208 4294967233 0 sequences (see also information_schema.sequences) +4294967207 4294967233 0 session variables (incomplete) 4294967226 4294967233 0 shared object comments -4294967198 4294967233 0 shared security labels (empty - feature not supported) -4294967200 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) -4294967205 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) -4294967204 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) -4294967203 4294967233 0 triggers (empty - feature does not exist) -4294967202 4294967233 0 scalar types (incomplete) -4294967207 4294967233 0 database users -4294967206 4294967233 0 local to remote user mapping (empty - feature does not exist) -4294967201 4294967233 0 view definitions (incomplete - see also information_schema.views) +4294967197 4294967233 0 shared security labels (empty - feature not supported) +4294967199 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) +4294967204 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) +4294967203 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) +4294967202 4294967233 0 triggers (empty - feature does not exist) +4294967201 4294967233 0 scalar types (incomplete) +4294967206 4294967233 0 database users +4294967205 4294967233 0 local to remote user mapping (empty - feature does not exist) +4294967200 4294967233 0 view definitions (incomplete - see also information_schema.views) ## pg_catalog.pg_shdescription diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 3a2d53a550ed..24bca57ca673 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -205,6 +205,7 @@ var pgCatalog = virtualSchema{ sqlbase.PgCatalogIndexesTableID: pgCatalogIndexesTable, sqlbase.PgCatalogInheritsTableID: pgCatalogInheritsTable, sqlbase.PgCatalogLanguageTableID: pgCatalogLanguageTable, + sqlbase.PgCatalogLocksTableID: pgCatalogLocksTable, sqlbase.PgCatalogMatViewsTableID: pgCatalogMatViewsTable, sqlbase.PgCatalogNamespaceTableID: pgCatalogNamespaceTable, sqlbase.PgCatalogOperatorTableID: pgCatalogOperatorTable, @@ -1461,6 +1462,32 @@ CREATE TABLE pg_catalog.pg_language ( }, } +var pgCatalogLocksTable = virtualSchemaTable{ + comment: `locks held by active processes (empty - feature does not exist) +https://www.postgresql.org/docs/9.6/view-pg-locks.html`, + schema: ` +CREATE TABLE pg_catalog.pg_locks ( + locktype TEXT, + database OID, + relation OID, + page INTEGER, + tuple SMALLINT, + virtualxid TEXT, + transactionid INT, + classid OID, + objid OID, + objsubid SMALLINT, + virtualtransaction TEXT, + pid INTEGER, + mode TEXT, + granted BOOLEAN, + fastpath BOOLEAN +)`, + populate: func(ctx context.Context, p *planner, dbContext *DatabaseDescriptor, addRow func(...tree.Datum) error) error { + return nil + }, +} + var pgCatalogMatViewsTable = virtualSchemaTable{ comment: `available materialized views (empty - feature does not exist) https://www.postgresql.org/docs/9.6/view-pg-matviews.html`, diff --git a/pkg/sql/sqlbase/constants.go b/pkg/sql/sqlbase/constants.go index cb7b307a9b38..9b3fe7ce6f76 100644 --- a/pkg/sql/sqlbase/constants.go +++ b/pkg/sql/sqlbase/constants.go @@ -127,6 +127,7 @@ const ( PgCatalogIndexesTableID PgCatalogInheritsTableID PgCatalogLanguageTableID + PgCatalogLocksTableID PgCatalogMatViewsTableID PgCatalogNamespaceTableID PgCatalogOperatorTableID From 594faae8fd429a64f48c0cea22af66a7f61a0bcf Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 11:19:07 -0400 Subject: [PATCH 04/17] sql: add empty pg_prepared_xacts Release note: None --- .../logictest/testdata/logic_test/grant_table | 1 + .../testdata/logic_test/information_schema | 5 +++ .../logictest/testdata/logic_test/pg_catalog | 35 ++++++++++--------- pkg/sql/pg_catalog.go | 17 +++++++++ pkg/sql/sqlbase/constants.go | 1 + 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/grant_table b/pkg/sql/logictest/testdata/logic_test/grant_table index a419b9f771ad..89e0db414718 100644 --- a/pkg/sql/logictest/testdata/logic_test/grant_table +++ b/pkg/sql/logictest/testdata/logic_test/grant_table @@ -116,6 +116,7 @@ test pg_catalog pg_locks public S test pg_catalog pg_matviews public SELECT test pg_catalog pg_namespace public SELECT test pg_catalog pg_operator public SELECT +test pg_catalog pg_prepared_xacts public SELECT test pg_catalog pg_proc public SELECT test pg_catalog pg_range public SELECT test pg_catalog pg_rewrite public SELECT diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index ba21e53f9b63..21d98915337d 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -292,6 +292,7 @@ pg_catalog pg_locks pg_catalog pg_matviews pg_catalog pg_namespace pg_catalog pg_operator +pg_catalog pg_prepared_xacts pg_catalog pg_proc pg_catalog pg_range pg_catalog pg_rewrite @@ -423,6 +424,7 @@ pg_locks pg_matviews pg_namespace pg_operator +pg_prepared_xacts pg_proc pg_range pg_rewrite @@ -561,6 +563,7 @@ system pg_catalog pg_locks SYSTEM VIE system pg_catalog pg_matviews SYSTEM VIEW NO 1 system pg_catalog pg_namespace SYSTEM VIEW NO 1 system pg_catalog pg_operator SYSTEM VIEW NO 1 +system pg_catalog pg_prepared_xacts SYSTEM VIEW NO 1 system pg_catalog pg_proc SYSTEM VIEW NO 1 system pg_catalog pg_range SYSTEM VIEW NO 1 system pg_catalog pg_rewrite SYSTEM VIEW NO 1 @@ -1296,6 +1299,7 @@ NULL public system pg_catalog pg_locks NULL public system pg_catalog pg_matviews SELECT NULL YES NULL public system pg_catalog pg_namespace SELECT NULL YES NULL public system pg_catalog pg_operator SELECT NULL YES +NULL public system pg_catalog pg_prepared_xacts SELECT NULL YES NULL public system pg_catalog pg_proc SELECT NULL YES NULL public system pg_catalog pg_range SELECT NULL YES NULL public system pg_catalog pg_rewrite SELECT NULL YES @@ -1540,6 +1544,7 @@ NULL public system pg_catalog pg_locks NULL public system pg_catalog pg_matviews SELECT NULL YES NULL public system pg_catalog pg_namespace SELECT NULL YES NULL public system pg_catalog pg_operator SELECT NULL YES +NULL public system pg_catalog pg_prepared_xacts SELECT NULL YES NULL public system pg_catalog pg_proc SELECT NULL YES NULL public system pg_catalog pg_range SELECT NULL YES NULL public system pg_catalog pg_rewrite SELECT NULL YES diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index dc25e29811c1..fef063dab512 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -41,6 +41,7 @@ pg_locks pg_matviews pg_namespace pg_operator +pg_prepared_xacts pg_proc pg_range pg_rewrite @@ -108,6 +109,7 @@ pg_locks pg_matviews pg_namespace pg_operator +pg_prepared_xacts pg_proc pg_range pg_rewrite @@ -1411,23 +1413,24 @@ objoid classoid objsubid description 4294967215 4294967233 0 available materialized views (empty - feature does not exist) 4294967214 4294967233 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) 4294967213 4294967233 0 operators (incomplete) -4294967212 4294967233 0 built-in functions (incomplete) -4294967211 4294967233 0 range types (empty - feature does not exist) -4294967210 4294967233 0 rewrite rules (empty - feature does not exist) -4294967209 4294967233 0 database roles -4294967198 4294967233 0 security labels (empty - feature does not exist) -4294967208 4294967233 0 sequences (see also information_schema.sequences) -4294967207 4294967233 0 session variables (incomplete) +4294967212 4294967233 0 prepared transactions (empty - feature does not exist) +4294967211 4294967233 0 built-in functions (incomplete) +4294967210 4294967233 0 range types (empty - feature does not exist) +4294967209 4294967233 0 rewrite rules (empty - feature does not exist) +4294967208 4294967233 0 database roles +4294967197 4294967233 0 security labels (empty - feature does not exist) +4294967207 4294967233 0 sequences (see also information_schema.sequences) +4294967206 4294967233 0 session variables (incomplete) 4294967226 4294967233 0 shared object comments -4294967197 4294967233 0 shared security labels (empty - feature not supported) -4294967199 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) -4294967204 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) -4294967203 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) -4294967202 4294967233 0 triggers (empty - feature does not exist) -4294967201 4294967233 0 scalar types (incomplete) -4294967206 4294967233 0 database users -4294967205 4294967233 0 local to remote user mapping (empty - feature does not exist) -4294967200 4294967233 0 view definitions (incomplete - see also information_schema.views) +4294967196 4294967233 0 shared security labels (empty - feature not supported) +4294967198 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) +4294967203 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) +4294967202 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) +4294967201 4294967233 0 triggers (empty - feature does not exist) +4294967200 4294967233 0 scalar types (incomplete) +4294967205 4294967233 0 database users +4294967204 4294967233 0 local to remote user mapping (empty - feature does not exist) +4294967199 4294967233 0 view definitions (incomplete - see also information_schema.views) ## pg_catalog.pg_shdescription diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 24bca57ca673..3fa22d848d76 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -209,6 +209,7 @@ var pgCatalog = virtualSchema{ sqlbase.PgCatalogMatViewsTableID: pgCatalogMatViewsTable, sqlbase.PgCatalogNamespaceTableID: pgCatalogNamespaceTable, sqlbase.PgCatalogOperatorTableID: pgCatalogOperatorTable, + sqlbase.PgCatalogPreparedXactsTableID: pgCatalogPreparedXactsTable, sqlbase.PgCatalogProcTableID: pgCatalogProcTable, sqlbase.PgCatalogRangeTableID: pgCatalogRangeTable, sqlbase.PgCatalogRewriteTableID: pgCatalogRewriteTable, @@ -1655,6 +1656,22 @@ var ( _ = proArgModeTable ) +var pgCatalogPreparedXactsTable = virtualSchemaTable{ + comment: `prepared transactions (empty - feature does not exist) +https://www.postgresql.org/docs/9.6/view-pg-prepared-xacts.html`, + schema: ` +CREATE TABLE pg_catalog.pg_prepared_xacts ( + transaction INTEGER, + gid TEXT, + prepared TIMESTAMP WITH TIME ZONE, + owner NAME, + database NAME +)`, + populate: func(ctx context.Context, p *planner, dbContext *DatabaseDescriptor, addRow func(...tree.Datum) error) error { + return nil + }, +} + var pgCatalogProcTable = virtualSchemaTable{ comment: `built-in functions (incomplete) https://www.postgresql.org/docs/9.5/catalog-pg-proc.html`, diff --git a/pkg/sql/sqlbase/constants.go b/pkg/sql/sqlbase/constants.go index 9b3fe7ce6f76..8a55e5d9b04b 100644 --- a/pkg/sql/sqlbase/constants.go +++ b/pkg/sql/sqlbase/constants.go @@ -131,6 +131,7 @@ const ( PgCatalogMatViewsTableID PgCatalogNamespaceTableID PgCatalogOperatorTableID + PgCatalogPreparedXactsTableID PgCatalogProcTableID PgCatalogRangeTableID PgCatalogRewriteTableID From c3876e7ec9cd9f9502ac89699dc0e4ad509587c9 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 11:19:22 -0400 Subject: [PATCH 05/17] sql: add empty pg_seclabels Release note: None --- .../logictest/testdata/logic_test/grant_table | 1 + .../testdata/logic_test/information_schema | 5 ++++ .../logictest/testdata/logic_test/pg_catalog | 27 ++++++++++--------- pkg/sql/pg_catalog.go | 20 ++++++++++++++ pkg/sql/sqlbase/constants.go | 1 + 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/grant_table b/pkg/sql/logictest/testdata/logic_test/grant_table index 89e0db414718..b92a4155b899 100644 --- a/pkg/sql/logictest/testdata/logic_test/grant_table +++ b/pkg/sql/logictest/testdata/logic_test/grant_table @@ -122,6 +122,7 @@ test pg_catalog pg_range public S test pg_catalog pg_rewrite public SELECT test pg_catalog pg_roles public SELECT test pg_catalog pg_seclabel public SELECT +test pg_catalog pg_seclabels public SELECT test pg_catalog pg_sequence public SELECT test pg_catalog pg_settings public SELECT test pg_catalog pg_shdescription public SELECT diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 21d98915337d..6b90cac6ac80 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -298,6 +298,7 @@ pg_catalog pg_range pg_catalog pg_rewrite pg_catalog pg_roles pg_catalog pg_seclabel +pg_catalog pg_seclabels pg_catalog pg_sequence pg_catalog pg_settings pg_catalog pg_shdescription @@ -430,6 +431,7 @@ pg_range pg_rewrite pg_roles pg_seclabel +pg_seclabels pg_sequence pg_settings pg_shdescription @@ -569,6 +571,7 @@ system pg_catalog pg_range SYSTEM VIE system pg_catalog pg_rewrite SYSTEM VIEW NO 1 system pg_catalog pg_roles SYSTEM VIEW NO 1 system pg_catalog pg_seclabel SYSTEM VIEW NO 1 +system pg_catalog pg_seclabels SYSTEM VIEW NO 1 system pg_catalog pg_sequence SYSTEM VIEW NO 1 system pg_catalog pg_settings SYSTEM VIEW NO 1 system pg_catalog pg_shdescription SYSTEM VIEW NO 1 @@ -1305,6 +1308,7 @@ NULL public system pg_catalog pg_range NULL public system pg_catalog pg_rewrite SELECT NULL YES NULL public system pg_catalog pg_roles SELECT NULL YES NULL public system pg_catalog pg_seclabel SELECT NULL YES +NULL public system pg_catalog pg_seclabels SELECT NULL YES NULL public system pg_catalog pg_sequence SELECT NULL YES NULL public system pg_catalog pg_settings SELECT NULL YES NULL public system pg_catalog pg_shdescription SELECT NULL YES @@ -1550,6 +1554,7 @@ NULL public system pg_catalog pg_range NULL public system pg_catalog pg_rewrite SELECT NULL YES NULL public system pg_catalog pg_roles SELECT NULL YES NULL public system pg_catalog pg_seclabel SELECT NULL YES +NULL public system pg_catalog pg_seclabels SELECT NULL YES NULL public system pg_catalog pg_sequence SELECT NULL YES NULL public system pg_catalog pg_settings SELECT NULL YES NULL public system pg_catalog pg_shdescription SELECT NULL YES diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index fef063dab512..8e2254e21dd9 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -47,6 +47,7 @@ pg_range pg_rewrite pg_roles pg_seclabel +pg_seclabels pg_sequence pg_settings pg_shdescription @@ -115,6 +116,7 @@ pg_range pg_rewrite pg_roles pg_seclabel +pg_seclabels pg_sequence pg_settings pg_shdescription @@ -1418,19 +1420,20 @@ objoid classoid objsubid description 4294967210 4294967233 0 range types (empty - feature does not exist) 4294967209 4294967233 0 rewrite rules (empty - feature does not exist) 4294967208 4294967233 0 database roles -4294967197 4294967233 0 security labels (empty - feature does not exist) -4294967207 4294967233 0 sequences (see also information_schema.sequences) -4294967206 4294967233 0 session variables (incomplete) +4294967196 4294967233 0 security labels (empty - feature does not exist) +4294967207 4294967233 0 security labels (empty) +4294967206 4294967233 0 sequences (see also information_schema.sequences) +4294967205 4294967233 0 session variables (incomplete) 4294967226 4294967233 0 shared object comments -4294967196 4294967233 0 shared security labels (empty - feature not supported) -4294967198 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) -4294967203 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) -4294967202 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) -4294967201 4294967233 0 triggers (empty - feature does not exist) -4294967200 4294967233 0 scalar types (incomplete) -4294967205 4294967233 0 database users -4294967204 4294967233 0 local to remote user mapping (empty - feature does not exist) -4294967199 4294967233 0 view definitions (incomplete - see also information_schema.views) +4294967195 4294967233 0 shared security labels (empty - feature not supported) +4294967197 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) +4294967202 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) +4294967201 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) +4294967200 4294967233 0 triggers (empty - feature does not exist) +4294967199 4294967233 0 scalar types (incomplete) +4294967204 4294967233 0 database users +4294967203 4294967233 0 local to remote user mapping (empty - feature does not exist) +4294967198 4294967233 0 view definitions (incomplete - see also information_schema.views) ## pg_catalog.pg_shdescription diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 3fa22d848d76..8cbfacbde6c7 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -214,6 +214,7 @@ var pgCatalog = virtualSchema{ sqlbase.PgCatalogRangeTableID: pgCatalogRangeTable, sqlbase.PgCatalogRewriteTableID: pgCatalogRewriteTable, sqlbase.PgCatalogRolesTableID: pgCatalogRolesTable, + sqlbase.PgCatalogSecLabelsTableID: pgCatalogSecLabelsTable, sqlbase.PgCatalogSequencesTableID: pgCatalogSequencesTable, sqlbase.PgCatalogSettingsTableID: pgCatalogSettingsTable, sqlbase.PgCatalogUserTableID: pgCatalogUserTable, @@ -1920,6 +1921,25 @@ CREATE TABLE pg_catalog.pg_roles ( }, } +var pgCatalogSecLabelsTable = virtualSchemaTable{ + comment: `security labels (empty) +https://www.postgresql.org/docs/9.6/view-pg-seclabels.html`, + schema: ` +CREATE TABLE pg_catalog.pg_seclabels ( + objoid OID, + classoid OID, + objsubid INT4, + objtype TEXT, + objnamespace OID, + objname TEXT, + provider TEXT, + label TEXT +)`, + populate: func(ctx context.Context, p *planner, _ *DatabaseDescriptor, addRow func(...tree.Datum) error) error { + return nil + }, +} + var pgCatalogSequencesTable = virtualSchemaTable{ comment: `sequences (see also information_schema.sequences) https://www.postgresql.org/docs/9.5/catalog-pg-sequence.html`, diff --git a/pkg/sql/sqlbase/constants.go b/pkg/sql/sqlbase/constants.go index 8a55e5d9b04b..6b929b0c17a3 100644 --- a/pkg/sql/sqlbase/constants.go +++ b/pkg/sql/sqlbase/constants.go @@ -136,6 +136,7 @@ const ( PgCatalogRangeTableID PgCatalogRewriteTableID PgCatalogRolesTableID + PgCatalogSecLabelsTableID PgCatalogSequencesTableID PgCatalogSettingsTableID PgCatalogUserTableID From c27fceb98d9c0f8e7e2911048577b4a4d2ec671f Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 11:25:13 -0400 Subject: [PATCH 06/17] sql: add empty pg_shdepend Release note: None --- .../logictest/testdata/logic_test/grant_table | 1 + .../testdata/logic_test/information_schema | 5 ++++ .../logictest/testdata/logic_test/pg_catalog | 23 +++++++++++-------- pkg/sql/pg_catalog.go | 19 +++++++++++++++ pkg/sql/sqlbase/constants.go | 1 + 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/grant_table b/pkg/sql/logictest/testdata/logic_test/grant_table index b92a4155b899..bccd183c47ad 100644 --- a/pkg/sql/logictest/testdata/logic_test/grant_table +++ b/pkg/sql/logictest/testdata/logic_test/grant_table @@ -125,6 +125,7 @@ test pg_catalog pg_seclabel public S test pg_catalog pg_seclabels public SELECT test pg_catalog pg_sequence public SELECT test pg_catalog pg_settings public SELECT +test pg_catalog pg_shdepend public SELECT test pg_catalog pg_shdescription public SELECT test pg_catalog pg_shseclabel public SELECT test pg_catalog pg_stat_activity public SELECT diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 6b90cac6ac80..3e2d1ef19bac 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -301,6 +301,7 @@ pg_catalog pg_seclabel pg_catalog pg_seclabels pg_catalog pg_sequence pg_catalog pg_settings +pg_catalog pg_shdepend pg_catalog pg_shdescription pg_catalog pg_shseclabel pg_catalog pg_stat_activity @@ -434,6 +435,7 @@ pg_seclabel pg_seclabels pg_sequence pg_settings +pg_shdepend pg_shdescription pg_shseclabel pg_stat_activity @@ -574,6 +576,7 @@ system pg_catalog pg_seclabel SYSTEM VIE system pg_catalog pg_seclabels SYSTEM VIEW NO 1 system pg_catalog pg_sequence SYSTEM VIEW NO 1 system pg_catalog pg_settings SYSTEM VIEW NO 1 +system pg_catalog pg_shdepend SYSTEM VIEW NO 1 system pg_catalog pg_shdescription SYSTEM VIEW NO 1 system pg_catalog pg_shseclabel SYSTEM VIEW NO 1 system pg_catalog pg_stat_activity SYSTEM VIEW NO 1 @@ -1311,6 +1314,7 @@ NULL public system pg_catalog pg_seclabel NULL public system pg_catalog pg_seclabels SELECT NULL YES NULL public system pg_catalog pg_sequence SELECT NULL YES NULL public system pg_catalog pg_settings SELECT NULL YES +NULL public system pg_catalog pg_shdepend SELECT NULL YES NULL public system pg_catalog pg_shdescription SELECT NULL YES NULL public system pg_catalog pg_shseclabel SELECT NULL YES NULL public system pg_catalog pg_stat_activity SELECT NULL YES @@ -1557,6 +1561,7 @@ NULL public system pg_catalog pg_seclabel NULL public system pg_catalog pg_seclabels SELECT NULL YES NULL public system pg_catalog pg_sequence SELECT NULL YES NULL public system pg_catalog pg_settings SELECT NULL YES +NULL public system pg_catalog pg_shdepend SELECT NULL YES NULL public system pg_catalog pg_shdescription SELECT NULL YES NULL public system pg_catalog pg_shseclabel SELECT NULL YES NULL public system pg_catalog pg_stat_activity SELECT NULL YES diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 8e2254e21dd9..62574c71401d 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -50,6 +50,7 @@ pg_seclabel pg_seclabels pg_sequence pg_settings +pg_shdepend pg_shdescription pg_shseclabel pg_stat_activity @@ -119,6 +120,7 @@ pg_seclabel pg_seclabels pg_sequence pg_settings +pg_shdepend pg_shdescription pg_shseclabel pg_stat_activity @@ -1420,20 +1422,21 @@ objoid classoid objsubid description 4294967210 4294967233 0 range types (empty - feature does not exist) 4294967209 4294967233 0 rewrite rules (empty - feature does not exist) 4294967208 4294967233 0 database roles -4294967196 4294967233 0 security labels (empty - feature does not exist) +4294967195 4294967233 0 security labels (empty - feature does not exist) 4294967207 4294967233 0 security labels (empty) 4294967206 4294967233 0 sequences (see also information_schema.sequences) 4294967205 4294967233 0 session variables (incomplete) +4294967204 4294967233 0 shared dependencies (empty - not implemented) 4294967226 4294967233 0 shared object comments -4294967195 4294967233 0 shared security labels (empty - feature not supported) -4294967197 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) -4294967202 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) -4294967201 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) -4294967200 4294967233 0 triggers (empty - feature does not exist) -4294967199 4294967233 0 scalar types (incomplete) -4294967204 4294967233 0 database users -4294967203 4294967233 0 local to remote user mapping (empty - feature does not exist) -4294967198 4294967233 0 view definitions (incomplete - see also information_schema.views) +4294967194 4294967233 0 shared security labels (empty - feature not supported) +4294967196 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) +4294967201 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) +4294967200 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) +4294967199 4294967233 0 triggers (empty - feature does not exist) +4294967198 4294967233 0 scalar types (incomplete) +4294967203 4294967233 0 database users +4294967202 4294967233 0 local to remote user mapping (empty - feature does not exist) +4294967197 4294967233 0 view definitions (incomplete - see also information_schema.views) ## pg_catalog.pg_shdescription diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 8cbfacbde6c7..46c093aa2fb6 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -217,6 +217,7 @@ var pgCatalog = virtualSchema{ sqlbase.PgCatalogSecLabelsTableID: pgCatalogSecLabelsTable, sqlbase.PgCatalogSequencesTableID: pgCatalogSequencesTable, sqlbase.PgCatalogSettingsTableID: pgCatalogSettingsTable, + sqlbase.PgCatalogShdependTableID: pgCatalogShdependTable, sqlbase.PgCatalogUserTableID: pgCatalogUserTable, sqlbase.PgCatalogUserMappingTableID: pgCatalogUserMappingTable, sqlbase.PgCatalogTablesTableID: pgCatalogTablesTable, @@ -2053,6 +2054,24 @@ CREATE TABLE pg_catalog.pg_settings ( }, } +var pgCatalogShdependTable = virtualSchemaTable{ + comment: `shared dependencies (empty - not implemented) +https://www.postgresql.org/docs/9.6/catalog-pg-shdepend.html`, + schema: ` +CREATE TABLE pg_catalog.pg_shdepend ( + dbid OID, + classid OID, + objid OID, + objsubid INT4, + refclassid OID, + refobjid OID, + deptype CHAR +)`, + populate: func(ctx context.Context, p *planner, dbContext *DatabaseDescriptor, addRow func(...tree.Datum) error) error { + return nil + }, +} + var pgCatalogTablesTable = virtualSchemaTable{ comment: `tables summary (see also information_schema.tables, pg_catalog.pg_class) https://www.postgresql.org/docs/9.5/view-pg-tables.html`, diff --git a/pkg/sql/sqlbase/constants.go b/pkg/sql/sqlbase/constants.go index 6b929b0c17a3..ebe30d3a03e5 100644 --- a/pkg/sql/sqlbase/constants.go +++ b/pkg/sql/sqlbase/constants.go @@ -139,6 +139,7 @@ const ( PgCatalogSecLabelsTableID PgCatalogSequencesTableID PgCatalogSettingsTableID + PgCatalogShdependTableID PgCatalogUserTableID PgCatalogUserMappingTableID PgCatalogTablesTableID From 8fceb0d1f948e02b4570fd20cf23896024685ce8 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 16:34:19 -0400 Subject: [PATCH 07/17] sql: add empty pg_cast Release note: None --- .../logictest/testdata/logic_test/grant_table | 1 + .../testdata/logic_test/information_schema | 5 + .../logictest/testdata/logic_test/pg_catalog | 205 +++++++++--------- pkg/sql/pg_catalog.go | 22 ++ pkg/sql/sqlbase/constants.go | 1 + 5 files changed, 133 insertions(+), 101 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/grant_table b/pkg/sql/logictest/testdata/logic_test/grant_table index bccd183c47ad..cca4abd2e9a4 100644 --- a/pkg/sql/logictest/testdata/logic_test/grant_table +++ b/pkg/sql/logictest/testdata/logic_test/grant_table @@ -96,6 +96,7 @@ test pg_catalog pg_am public S 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_cast public SELECT test pg_catalog pg_class public SELECT test pg_catalog pg_collation public SELECT test pg_catalog pg_constraint public SELECT diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 3e2d1ef19bac..abddcfcbc94b 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -272,6 +272,7 @@ pg_catalog pg_am pg_catalog pg_attrdef pg_catalog pg_attribute pg_catalog pg_auth_members +pg_catalog pg_cast pg_catalog pg_class pg_catalog pg_collation pg_catalog pg_constraint @@ -406,6 +407,7 @@ pg_am pg_attrdef pg_attribute pg_auth_members +pg_cast pg_class pg_collation pg_constraint @@ -547,6 +549,7 @@ system pg_catalog pg_am SYSTEM VIE system pg_catalog pg_attrdef SYSTEM VIEW NO 1 system pg_catalog pg_attribute SYSTEM VIEW NO 1 system pg_catalog pg_auth_members SYSTEM VIEW NO 1 +system pg_catalog pg_cast SYSTEM VIEW NO 1 system pg_catalog pg_class SYSTEM VIEW NO 1 system pg_catalog pg_collation SYSTEM VIEW NO 1 system pg_catalog pg_constraint SYSTEM VIEW NO 1 @@ -1285,6 +1288,7 @@ NULL public system pg_catalog pg_am NULL public system pg_catalog pg_attrdef SELECT NULL YES NULL public system pg_catalog pg_attribute SELECT NULL YES NULL public system pg_catalog pg_auth_members SELECT NULL YES +NULL public system pg_catalog pg_cast SELECT NULL YES NULL public system pg_catalog pg_class SELECT NULL YES NULL public system pg_catalog pg_collation SELECT NULL YES NULL public system pg_catalog pg_constraint SELECT NULL YES @@ -1532,6 +1536,7 @@ NULL public system pg_catalog pg_am NULL public system pg_catalog pg_attrdef SELECT NULL YES NULL public system pg_catalog pg_attribute SELECT NULL YES NULL public system pg_catalog pg_auth_members SELECT NULL YES +NULL public system pg_catalog pg_cast SELECT NULL YES NULL public system pg_catalog pg_class SELECT NULL YES NULL public system pg_catalog pg_collation SELECT NULL YES NULL public system pg_catalog pg_constraint SELECT NULL YES diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 62574c71401d..689767bd6749 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -21,6 +21,7 @@ pg_am pg_attrdef pg_attribute pg_auth_members +pg_cast pg_class pg_collation pg_constraint @@ -91,6 +92,7 @@ pg_am pg_attrdef pg_attribute pg_auth_members +pg_cast pg_class pg_collation pg_constraint @@ -799,8 +801,8 @@ FROM pg_catalog.pg_depend ORDER BY objid ---- classid objid objsubid refclassid refobjid refobjsubid deptype -4294967231 178791267 0 4294967233 450499961 0 n -4294967231 3318155331 0 4294967233 450499960 0 n +4294967230 178791267 0 4294967232 450499961 0 n +4294967230 3318155331 0 4294967232 450499960 0 n # All entries in pg_depend are dependency links from the pg_constraint system # table to the pg_class system table. @@ -812,7 +814,7 @@ JOIN pg_class cla ON classid=cla.oid JOIN pg_class refcla ON refclassid=refcla.oid ---- classid refclassid tablename reftablename -4294967231 4294967233 pg_constraint pg_class +4294967230 4294967232 pg_constraint pg_class # All entries in pg_depend are foreign key constraints that reference an index # in pg_class. @@ -1339,104 +1341,105 @@ SELECT objoid, classoid, objsubid, regexp_replace(description, e'\n.*', '') AS d FROM pg_catalog.pg_description ---- objoid classoid objsubid description -4294967294 4294967233 0 backward inter-descriptor dependencies starting from tables accessible by current user in current database (KV scan) -4294967292 4294967233 0 built-in functions (RAM/static) -4294967291 4294967233 0 running queries visible by current user (cluster RPC; expensive!) -4294967290 4294967233 0 running sessions visible to current user (cluster RPC; expensive!) -4294967289 4294967233 0 cluster settings (RAM) -4294967288 4294967233 0 CREATE and ALTER statements for all tables accessible by current user in current database (KV scan) -4294967287 4294967233 0 telemetry counters (RAM; local node only) -4294967286 4294967233 0 forward inter-descriptor dependencies starting from tables accessible by current user in current database (KV scan) -4294967284 4294967233 0 locally known gossiped health alerts (RAM; local node only) -4294967283 4294967233 0 locally known gossiped node liveness (RAM; local node only) -4294967282 4294967233 0 locally known edges in the gossip network (RAM; local node only) -4294967285 4294967233 0 locally known gossiped node details (RAM; local node only) -4294967281 4294967233 0 index columns for all indexes accessible by current user in current database (KV scan) -4294967280 4294967233 0 decoded job metadata from system.jobs (KV scan) -4294967279 4294967233 0 node details across the entire cluster (cluster RPC; expensive!) -4294967278 4294967233 0 store details and status (cluster RPC; expensive!) -4294967277 4294967233 0 acquired table leases (RAM; local node only) -4294967293 4294967233 0 detailed identification strings (RAM, local node only) -4294967274 4294967233 0 current values for metrics (RAM; local node only) -4294967276 4294967233 0 running queries visible by current user (RAM; local node only) -4294967269 4294967233 0 server parameters, useful to construct connection URLs (RAM, local node only) -4294967275 4294967233 0 running sessions visible by current user (RAM; local node only) -4294967265 4294967233 0 statement statistics (RAM; local node only) -4294967273 4294967233 0 defined partitions for all tables/indexes accessible by the current user in the current database (KV scan) -4294967272 4294967233 0 comments for predefined virtual tables (RAM/static) -4294967271 4294967233 0 range metadata without leaseholder details (KV join; expensive!) -4294967268 4294967233 0 ongoing schema changes, across all descriptors accessible by current user (KV scan; expensive!) -4294967267 4294967233 0 session trace accumulated so far (RAM) -4294967266 4294967233 0 session variables (RAM) -4294967264 4294967233 0 details for all columns accessible by current user in current database (KV scan) -4294967263 4294967233 0 indexes accessible by current user in current database (KV scan) -4294967262 4294967233 0 table descriptors accessible by current user, including non-public and virtual (KV scan; expensive!) -4294967261 4294967233 0 decoded zone configurations from system.zones (KV scan) -4294967259 4294967233 0 roles for which the current user has admin option -4294967258 4294967233 0 roles available to the current user -4294967257 4294967233 0 check constraints -4294967256 4294967233 0 column privilege grants (incomplete) -4294967255 4294967233 0 table and view columns (incomplete) -4294967254 4294967233 0 columns usage by constraints -4294967253 4294967233 0 roles for the current user -4294967252 4294967233 0 column usage by indexes and key constraints -4294967251 4294967233 0 built-in function parameters (empty - introspection not yet supported) -4294967250 4294967233 0 foreign key constraints -4294967249 4294967233 0 privileges granted on table or views (incomplete; see also information_schema.table_privileges; may contain excess users or roles) -4294967248 4294967233 0 built-in functions (empty - introspection not yet supported) -4294967246 4294967233 0 schema privileges (incomplete; may contain excess users or roles) -4294967247 4294967233 0 database schemas (may contain schemata without permission) -4294967245 4294967233 0 sequences -4294967244 4294967233 0 index metadata and statistics (incomplete) -4294967243 4294967233 0 table constraints -4294967242 4294967233 0 privileges granted on table or views (incomplete; may contain excess users or roles) -4294967241 4294967233 0 tables and views -4294967239 4294967233 0 grantable privileges (incomplete) -4294967240 4294967233 0 views (incomplete) -4294967237 4294967233 0 index access methods (incomplete) -4294967236 4294967233 0 column default values -4294967235 4294967233 0 table columns (incomplete - see also information_schema.columns) -4294967234 4294967233 0 role membership -4294967233 4294967233 0 tables and relation-like objects (incomplete - see also information_schema.tables/sequences/views) -4294967232 4294967233 0 available collations (incomplete) -4294967231 4294967233 0 table constraints (incomplete - see also information_schema.table_constraints) -4294967230 4294967233 0 encoding conversions (empty - unimplemented) -4294967229 4294967233 0 available databases (incomplete) -4294967228 4294967233 0 dependency relationships (incomplete) -4294967227 4294967233 0 object comments -4294967225 4294967233 0 enum types and labels (empty - feature does not exist) -4294967224 4294967233 0 installed extensions (empty - feature does not exist) -4294967223 4294967233 0 foreign data wrappers (empty - feature does not exist) -4294967222 4294967233 0 foreign servers (empty - feature does not exist) -4294967221 4294967233 0 foreign tables (empty - feature does not exist) -4294967220 4294967233 0 indexes (incomplete) -4294967219 4294967233 0 index creation statements -4294967218 4294967233 0 table inheritance hierarchy (empty - feature does not exist) -4294967217 4294967233 0 available languages (empty - feature does not exist) -4294967216 4294967233 0 locks held by active processes (empty - feature does not exist) -4294967215 4294967233 0 available materialized views (empty - feature does not exist) -4294967214 4294967233 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) -4294967213 4294967233 0 operators (incomplete) -4294967212 4294967233 0 prepared transactions (empty - feature does not exist) -4294967211 4294967233 0 built-in functions (incomplete) -4294967210 4294967233 0 range types (empty - feature does not exist) -4294967209 4294967233 0 rewrite rules (empty - feature does not exist) -4294967208 4294967233 0 database roles -4294967195 4294967233 0 security labels (empty - feature does not exist) -4294967207 4294967233 0 security labels (empty) -4294967206 4294967233 0 sequences (see also information_schema.sequences) -4294967205 4294967233 0 session variables (incomplete) -4294967204 4294967233 0 shared dependencies (empty - not implemented) -4294967226 4294967233 0 shared object comments -4294967194 4294967233 0 shared security labels (empty - feature not supported) -4294967196 4294967233 0 backend access statistics (empty - monitoring works differently in CockroachDB) -4294967201 4294967233 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) -4294967200 4294967233 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) -4294967199 4294967233 0 triggers (empty - feature does not exist) -4294967198 4294967233 0 scalar types (incomplete) -4294967203 4294967233 0 database users -4294967202 4294967233 0 local to remote user mapping (empty - feature does not exist) -4294967197 4294967233 0 view definitions (incomplete - see also information_schema.views) +4294967294 4294967232 0 backward inter-descriptor dependencies starting from tables accessible by current user in current database (KV scan) +4294967292 4294967232 0 built-in functions (RAM/static) +4294967291 4294967232 0 running queries visible by current user (cluster RPC; expensive!) +4294967290 4294967232 0 running sessions visible to current user (cluster RPC; expensive!) +4294967289 4294967232 0 cluster settings (RAM) +4294967288 4294967232 0 CREATE and ALTER statements for all tables accessible by current user in current database (KV scan) +4294967287 4294967232 0 telemetry counters (RAM; local node only) +4294967286 4294967232 0 forward inter-descriptor dependencies starting from tables accessible by current user in current database (KV scan) +4294967284 4294967232 0 locally known gossiped health alerts (RAM; local node only) +4294967283 4294967232 0 locally known gossiped node liveness (RAM; local node only) +4294967282 4294967232 0 locally known edges in the gossip network (RAM; local node only) +4294967285 4294967232 0 locally known gossiped node details (RAM; local node only) +4294967281 4294967232 0 index columns for all indexes accessible by current user in current database (KV scan) +4294967280 4294967232 0 decoded job metadata from system.jobs (KV scan) +4294967279 4294967232 0 node details across the entire cluster (cluster RPC; expensive!) +4294967278 4294967232 0 store details and status (cluster RPC; expensive!) +4294967277 4294967232 0 acquired table leases (RAM; local node only) +4294967293 4294967232 0 detailed identification strings (RAM, local node only) +4294967274 4294967232 0 current values for metrics (RAM; local node only) +4294967276 4294967232 0 running queries visible by current user (RAM; local node only) +4294967269 4294967232 0 server parameters, useful to construct connection URLs (RAM, local node only) +4294967275 4294967232 0 running sessions visible by current user (RAM; local node only) +4294967265 4294967232 0 statement statistics (RAM; local node only) +4294967273 4294967232 0 defined partitions for all tables/indexes accessible by the current user in the current database (KV scan) +4294967272 4294967232 0 comments for predefined virtual tables (RAM/static) +4294967271 4294967232 0 range metadata without leaseholder details (KV join; expensive!) +4294967268 4294967232 0 ongoing schema changes, across all descriptors accessible by current user (KV scan; expensive!) +4294967267 4294967232 0 session trace accumulated so far (RAM) +4294967266 4294967232 0 session variables (RAM) +4294967264 4294967232 0 details for all columns accessible by current user in current database (KV scan) +4294967263 4294967232 0 indexes accessible by current user in current database (KV scan) +4294967262 4294967232 0 table descriptors accessible by current user, including non-public and virtual (KV scan; expensive!) +4294967261 4294967232 0 decoded zone configurations from system.zones (KV scan) +4294967259 4294967232 0 roles for which the current user has admin option +4294967258 4294967232 0 roles available to the current user +4294967257 4294967232 0 check constraints +4294967256 4294967232 0 column privilege grants (incomplete) +4294967255 4294967232 0 table and view columns (incomplete) +4294967254 4294967232 0 columns usage by constraints +4294967253 4294967232 0 roles for the current user +4294967252 4294967232 0 column usage by indexes and key constraints +4294967251 4294967232 0 built-in function parameters (empty - introspection not yet supported) +4294967250 4294967232 0 foreign key constraints +4294967249 4294967232 0 privileges granted on table or views (incomplete; see also information_schema.table_privileges; may contain excess users or roles) +4294967248 4294967232 0 built-in functions (empty - introspection not yet supported) +4294967246 4294967232 0 schema privileges (incomplete; may contain excess users or roles) +4294967247 4294967232 0 database schemas (may contain schemata without permission) +4294967245 4294967232 0 sequences +4294967244 4294967232 0 index metadata and statistics (incomplete) +4294967243 4294967232 0 table constraints +4294967242 4294967232 0 privileges granted on table or views (incomplete; may contain excess users or roles) +4294967241 4294967232 0 tables and views +4294967239 4294967232 0 grantable privileges (incomplete) +4294967240 4294967232 0 views (incomplete) +4294967237 4294967232 0 index access methods (incomplete) +4294967236 4294967232 0 column default values +4294967235 4294967232 0 table columns (incomplete - see also information_schema.columns) +4294967234 4294967232 0 role membership +4294967233 4294967232 0 casts (empty - needs filling out) +4294967232 4294967232 0 tables and relation-like objects (incomplete - see also information_schema.tables/sequences/views) +4294967231 4294967232 0 available collations (incomplete) +4294967230 4294967232 0 table constraints (incomplete - see also information_schema.table_constraints) +4294967229 4294967232 0 encoding conversions (empty - unimplemented) +4294967228 4294967232 0 available databases (incomplete) +4294967227 4294967232 0 dependency relationships (incomplete) +4294967226 4294967232 0 object comments +4294967224 4294967232 0 enum types and labels (empty - feature does not exist) +4294967223 4294967232 0 installed extensions (empty - feature does not exist) +4294967222 4294967232 0 foreign data wrappers (empty - feature does not exist) +4294967221 4294967232 0 foreign servers (empty - feature does not exist) +4294967220 4294967232 0 foreign tables (empty - feature does not exist) +4294967219 4294967232 0 indexes (incomplete) +4294967218 4294967232 0 index creation statements +4294967217 4294967232 0 table inheritance hierarchy (empty - feature does not exist) +4294967216 4294967232 0 available languages (empty - feature does not exist) +4294967215 4294967232 0 locks held by active processes (empty - feature does not exist) +4294967214 4294967232 0 available materialized views (empty - feature does not exist) +4294967213 4294967232 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) +4294967212 4294967232 0 operators (incomplete) +4294967211 4294967232 0 prepared transactions (empty - feature does not exist) +4294967210 4294967232 0 built-in functions (incomplete) +4294967209 4294967232 0 range types (empty - feature does not exist) +4294967208 4294967232 0 rewrite rules (empty - feature does not exist) +4294967207 4294967232 0 database roles +4294967194 4294967232 0 security labels (empty - feature does not exist) +4294967206 4294967232 0 security labels (empty) +4294967205 4294967232 0 sequences (see also information_schema.sequences) +4294967204 4294967232 0 session variables (incomplete) +4294967203 4294967232 0 shared dependencies (empty - not implemented) +4294967225 4294967232 0 shared object comments +4294967193 4294967232 0 shared security labels (empty - feature not supported) +4294967195 4294967232 0 backend access statistics (empty - monitoring works differently in CockroachDB) +4294967200 4294967232 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) +4294967199 4294967232 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) +4294967198 4294967232 0 triggers (empty - feature does not exist) +4294967197 4294967232 0 scalar types (incomplete) +4294967202 4294967232 0 database users +4294967201 4294967232 0 local to remote user mapping (empty - feature does not exist) +4294967196 4294967232 0 view definitions (incomplete - see also information_schema.views) ## pg_catalog.pg_shdescription diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 46c093aa2fb6..691e68c70804 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -188,6 +188,7 @@ var pgCatalog = virtualSchema{ sqlbase.PgCatalogAttrDefTableID: pgCatalogAttrDefTable, sqlbase.PgCatalogAttributeTableID: pgCatalogAttributeTable, sqlbase.PgCatalogAuthMembersTableID: pgCatalogAuthMembersTable, + sqlbase.PgCatalogCastTableID: pgCatalogCastTable, sqlbase.PgCatalogClassTableID: pgCatalogClassTable, sqlbase.PgCatalogCollationTableID: pgCatalogCollationTable, sqlbase.PgCatalogConstraintTableID: pgCatalogConstraintTable, @@ -449,6 +450,27 @@ CREATE TABLE pg_catalog.pg_attribute ( }, } +var pgCatalogCastTable = virtualSchemaTable{ + comment: `casts (empty - needs filling out) +https://www.postgresql.org/docs/9.6/catalog-pg-cast.html`, + schema: ` +CREATE TABLE pg_catalog.pg_cast ( + oid OID, + castsource OID, + casttarget OID, + castfunc OID, + castcontext CHAR, + castmethod CHAR +)`, + populate: func(ctx context.Context, p *planner, _ *DatabaseDescriptor, addRow func(...tree.Datum) error) error { + // TODO(someone): to populate this, we should split up the big PerformCast + // method in tree/eval.go into entries in a list. Then, this virtual table + // can simply range over the list. This would probably be better for + // maintainability anyway. + return nil + }, +} + var pgCatalogAuthMembersTable = virtualSchemaTable{ comment: `role membership https://www.postgresql.org/docs/9.5/catalog-pg-auth-members.html`, diff --git a/pkg/sql/sqlbase/constants.go b/pkg/sql/sqlbase/constants.go index ebe30d3a03e5..41d9cb53fb81 100644 --- a/pkg/sql/sqlbase/constants.go +++ b/pkg/sql/sqlbase/constants.go @@ -110,6 +110,7 @@ const ( PgCatalogAttrDefTableID PgCatalogAttributeTableID PgCatalogAuthMembersTableID + PgCatalogCastTableID PgCatalogClassTableID PgCatalogCollationTableID PgCatalogConstraintTableID From 4610e50b6e4e7545f67341aada5da73b235e64db Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 16:35:14 -0400 Subject: [PATCH 08/17] sql: add empty pg_default_acl Release note: None --- .../logictest/testdata/logic_test/grant_table | 1 + .../testdata/logic_test/information_schema | 5 ++ .../logictest/testdata/logic_test/pg_catalog | 73 ++++++++++--------- pkg/sql/pg_catalog.go | 18 +++++ pkg/sql/sqlbase/constants.go | 1 + 5 files changed, 63 insertions(+), 35 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/grant_table b/pkg/sql/logictest/testdata/logic_test/grant_table index cca4abd2e9a4..df17cc379c47 100644 --- a/pkg/sql/logictest/testdata/logic_test/grant_table +++ b/pkg/sql/logictest/testdata/logic_test/grant_table @@ -102,6 +102,7 @@ test pg_catalog pg_collation public S test pg_catalog pg_constraint public SELECT test pg_catalog pg_conversion public SELECT test pg_catalog pg_database public SELECT +test pg_catalog pg_default_acl public SELECT test pg_catalog pg_depend public SELECT test pg_catalog pg_description public SELECT test pg_catalog pg_enum public SELECT diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index abddcfcbc94b..a1d3c4e1525f 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -278,6 +278,7 @@ pg_catalog pg_collation pg_catalog pg_constraint pg_catalog pg_conversion pg_catalog pg_database +pg_catalog pg_default_acl pg_catalog pg_depend pg_catalog pg_description pg_catalog pg_enum @@ -413,6 +414,7 @@ pg_collation pg_constraint pg_conversion pg_database +pg_default_acl pg_depend pg_description pg_enum @@ -555,6 +557,7 @@ system pg_catalog pg_collation SYSTEM VIE system pg_catalog pg_constraint SYSTEM VIEW NO 1 system pg_catalog pg_conversion SYSTEM VIEW NO 1 system pg_catalog pg_database SYSTEM VIEW NO 1 +system pg_catalog pg_default_acl SYSTEM VIEW NO 1 system pg_catalog pg_depend SYSTEM VIEW NO 1 system pg_catalog pg_description SYSTEM VIEW NO 1 system pg_catalog pg_enum SYSTEM VIEW NO 1 @@ -1294,6 +1297,7 @@ NULL public system pg_catalog pg_collation NULL public system pg_catalog pg_constraint SELECT NULL YES NULL public system pg_catalog pg_conversion SELECT NULL YES NULL public system pg_catalog pg_database SELECT NULL YES +NULL public system pg_catalog pg_default_acl SELECT NULL YES NULL public system pg_catalog pg_depend SELECT NULL YES NULL public system pg_catalog pg_description SELECT NULL YES NULL public system pg_catalog pg_enum SELECT NULL YES @@ -1542,6 +1546,7 @@ NULL public system pg_catalog pg_collation NULL public system pg_catalog pg_constraint SELECT NULL YES NULL public system pg_catalog pg_conversion SELECT NULL YES NULL public system pg_catalog pg_database SELECT NULL YES +NULL public system pg_catalog pg_default_acl SELECT NULL YES NULL public system pg_catalog pg_depend SELECT NULL YES NULL public system pg_catalog pg_description SELECT NULL YES NULL public system pg_catalog pg_enum SELECT NULL YES diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 689767bd6749..5cf2db78931d 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -27,6 +27,7 @@ pg_collation pg_constraint pg_conversion pg_database +pg_default_acl pg_depend pg_description pg_enum @@ -98,6 +99,7 @@ pg_collation pg_constraint pg_conversion pg_database +pg_default_acl pg_depend pg_description pg_enum @@ -1405,41 +1407,42 @@ objoid classoid objsubid description 4294967230 4294967232 0 table constraints (incomplete - see also information_schema.table_constraints) 4294967229 4294967232 0 encoding conversions (empty - unimplemented) 4294967228 4294967232 0 available databases (incomplete) -4294967227 4294967232 0 dependency relationships (incomplete) -4294967226 4294967232 0 object comments -4294967224 4294967232 0 enum types and labels (empty - feature does not exist) -4294967223 4294967232 0 installed extensions (empty - feature does not exist) -4294967222 4294967232 0 foreign data wrappers (empty - feature does not exist) -4294967221 4294967232 0 foreign servers (empty - feature does not exist) -4294967220 4294967232 0 foreign tables (empty - feature does not exist) -4294967219 4294967232 0 indexes (incomplete) -4294967218 4294967232 0 index creation statements -4294967217 4294967232 0 table inheritance hierarchy (empty - feature does not exist) -4294967216 4294967232 0 available languages (empty - feature does not exist) -4294967215 4294967232 0 locks held by active processes (empty - feature does not exist) -4294967214 4294967232 0 available materialized views (empty - feature does not exist) -4294967213 4294967232 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) -4294967212 4294967232 0 operators (incomplete) -4294967211 4294967232 0 prepared transactions (empty - feature does not exist) -4294967210 4294967232 0 built-in functions (incomplete) -4294967209 4294967232 0 range types (empty - feature does not exist) -4294967208 4294967232 0 rewrite rules (empty - feature does not exist) -4294967207 4294967232 0 database roles -4294967194 4294967232 0 security labels (empty - feature does not exist) -4294967206 4294967232 0 security labels (empty) -4294967205 4294967232 0 sequences (see also information_schema.sequences) -4294967204 4294967232 0 session variables (incomplete) -4294967203 4294967232 0 shared dependencies (empty - not implemented) -4294967225 4294967232 0 shared object comments -4294967193 4294967232 0 shared security labels (empty - feature not supported) -4294967195 4294967232 0 backend access statistics (empty - monitoring works differently in CockroachDB) -4294967200 4294967232 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) -4294967199 4294967232 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) -4294967198 4294967232 0 triggers (empty - feature does not exist) -4294967197 4294967232 0 scalar types (incomplete) -4294967202 4294967232 0 database users -4294967201 4294967232 0 local to remote user mapping (empty - feature does not exist) -4294967196 4294967232 0 view definitions (incomplete - see also information_schema.views) +4294967227 4294967232 0 default ACLs (empty - unimplemented) +4294967226 4294967232 0 dependency relationships (incomplete) +4294967225 4294967232 0 object comments +4294967223 4294967232 0 enum types and labels (empty - feature does not exist) +4294967222 4294967232 0 installed extensions (empty - feature does not exist) +4294967221 4294967232 0 foreign data wrappers (empty - feature does not exist) +4294967220 4294967232 0 foreign servers (empty - feature does not exist) +4294967219 4294967232 0 foreign tables (empty - feature does not exist) +4294967218 4294967232 0 indexes (incomplete) +4294967217 4294967232 0 index creation statements +4294967216 4294967232 0 table inheritance hierarchy (empty - feature does not exist) +4294967215 4294967232 0 available languages (empty - feature does not exist) +4294967214 4294967232 0 locks held by active processes (empty - feature does not exist) +4294967213 4294967232 0 available materialized views (empty - feature does not exist) +4294967212 4294967232 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) +4294967211 4294967232 0 operators (incomplete) +4294967210 4294967232 0 prepared transactions (empty - feature does not exist) +4294967209 4294967232 0 built-in functions (incomplete) +4294967208 4294967232 0 range types (empty - feature does not exist) +4294967207 4294967232 0 rewrite rules (empty - feature does not exist) +4294967206 4294967232 0 database roles +4294967193 4294967232 0 security labels (empty - feature does not exist) +4294967205 4294967232 0 security labels (empty) +4294967204 4294967232 0 sequences (see also information_schema.sequences) +4294967203 4294967232 0 session variables (incomplete) +4294967202 4294967232 0 shared dependencies (empty - not implemented) +4294967224 4294967232 0 shared object comments +4294967192 4294967232 0 shared security labels (empty - feature not supported) +4294967194 4294967232 0 backend access statistics (empty - monitoring works differently in CockroachDB) +4294967199 4294967232 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) +4294967198 4294967232 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) +4294967197 4294967232 0 triggers (empty - feature does not exist) +4294967196 4294967232 0 scalar types (incomplete) +4294967201 4294967232 0 database users +4294967200 4294967232 0 local to remote user mapping (empty - feature does not exist) +4294967195 4294967232 0 view definitions (incomplete - see also information_schema.views) ## pg_catalog.pg_shdescription diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 691e68c70804..616f8d8961c4 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -194,6 +194,7 @@ var pgCatalog = virtualSchema{ sqlbase.PgCatalogConstraintTableID: pgCatalogConstraintTable, sqlbase.PgCatalogConversionTableID: pgCatalogConversionTable, sqlbase.PgCatalogDatabaseTableID: pgCatalogDatabaseTable, + sqlbase.PgCatalogDefaultACLTableID: pgCatalogDefaultACLTable, sqlbase.PgCatalogDependTableID: pgCatalogDependTable, sqlbase.PgCatalogDescriptionTableID: pgCatalogDescriptionTable, sqlbase.PgCatalogSharedDescriptionTableID: pgCatalogSharedDescriptionTable, @@ -968,6 +969,23 @@ CREATE TABLE pg_catalog.pg_database ( }) }, } + +var pgCatalogDefaultACLTable = virtualSchemaTable{ + comment: `default ACLs (empty - unimplemented) +https://www.postgresql.org/docs/9.6/catalog-pg-default-acl.html`, + schema: ` +CREATE TABLE pg_catalog.pg_default_acl ( + oid OID, + defaclrole OID, + defaclnamespace OID, + defaclobjtype CHAR, + defaclacl STRING[] +)`, + populate: func(ctx context.Context, p *planner, dbContext *DatabaseDescriptor, addRow func(...tree.Datum) error) error { + return nil + }, +} + var ( depTypeNormal = tree.NewDString("n") depTypeAuto = tree.NewDString("a") diff --git a/pkg/sql/sqlbase/constants.go b/pkg/sql/sqlbase/constants.go index 41d9cb53fb81..b7d3d4ea8e8d 100644 --- a/pkg/sql/sqlbase/constants.go +++ b/pkg/sql/sqlbase/constants.go @@ -116,6 +116,7 @@ const ( PgCatalogConstraintTableID PgCatalogConversionTableID PgCatalogDatabaseTableID + PgCatalogDefaultACLTableID PgCatalogDependTableID PgCatalogDescriptionTableID PgCatalogSharedDescriptionTableID From d1b545663b06199a71df3c7c93a0388702a7c371 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sat, 13 Jul 2019 16:34:57 -0400 Subject: [PATCH 09/17] sql: implement pg_database.datlastsysoid This is supposed to return the last "system OID", which is supposed to represent all OIDs that correspond to objects that were created by the Postgres system, like `pg_class` or all of the default types, so that it's easier to distinguish user-created objects, which will have higher OIDs. Unfortunately for us, we can't properly implement this as our OIDs are made by hash, so system and user OIDs will be all mixed up. To facilitate tools that use this (pgadmin), we always return 0. Release note: None --- pkg/sql/logictest/testdata/logic_test/pg_catalog | 10 +++++----- pkg/sql/pg_catalog.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 5cf2db78931d..9c95040c6ffb 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -240,11 +240,11 @@ FROM pg_catalog.pg_database ORDER BY oid ---- oid datname datconnlimit datlastsysoid datfrozenxid datminmxid dattablespace datacl -1 system -1 NULL NULL NULL 0 NULL -50 defaultdb -1 NULL NULL NULL 0 NULL -51 postgres -1 NULL NULL NULL 0 NULL -52 test -1 NULL NULL NULL 0 NULL -54 constraint_db -1 NULL NULL NULL 0 NULL +1 system -1 0 NULL NULL 0 NULL +50 defaultdb -1 0 NULL NULL 0 NULL +51 postgres -1 0 NULL NULL 0 NULL +52 test -1 0 NULL NULL 0 NULL +54 constraint_db -1 0 NULL NULL 0 NULL ## pg_catalog.pg_tables diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 616f8d8961c4..8c306ab9ef38 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -960,7 +960,7 @@ CREATE TABLE pg_catalog.pg_database ( tree.DBoolFalse, // datistemplate tree.DBoolTrue, // datallowconn negOneVal, // datconnlimit - tree.DNull, // datlastsysoid + oidZero, // datlastsysoid tree.DNull, // datfrozenxid tree.DNull, // datminmxid oidZero, // dattablespace From a3d5c961b812c9d62ef62356324ec46e2f62d299 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sat, 13 Jul 2019 16:35:08 -0400 Subject: [PATCH 10/17] pg_catalog: fix name of pg_stat_activity.usename It was previously erroneously called username. Release note: None --- pkg/sql/logictest/testdata/logic_test/pg_catalog | 4 ++-- pkg/sql/pg_catalog.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 9c95040c6ffb..6c387f00903b 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -1469,7 +1469,7 @@ oid extname extowner extnamespace extrelocatable extversion extconfig ext query OTIOTTTTITTTTTTTIIT colnames SELECT * FROM pg_catalog.pg_stat_activity ---- -datid datname pid usesysid username application_name client_addr client_hostname client_port backend_start xact_start query_start state_change wait_event_type wait_event state backend_xid backend_xmin query +datid datname pid usesysid usename application_name client_addr client_hostname client_port backend_start xact_start query_start state_change wait_event_type wait_event state backend_xid backend_xmin query query TTBTTTB colnames SHOW COLUMNS FROM pg_catalog.pg_stat_activity @@ -1479,7 +1479,7 @@ datid OID true NULL · datname NAME true NULL · {} false pid INT8 true NULL · {} false usesysid OID true NULL · {} false -username NAME true NULL · {} false +usename NAME true NULL · {} false application_name STRING true NULL · {} false client_addr INET true NULL · {} false client_hostname STRING true NULL · {} false diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 8c306ab9ef38..0484ffad4d76 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -2427,7 +2427,7 @@ CREATE TABLE pg_catalog.pg_stat_activity ( datname NAME, pid INTEGER, usesysid OID, - username NAME, + usename NAME, application_name TEXT, client_addr INET, client_hostname TEXT, From 9a72ea51a02f190894117739c8a94268f2da6955 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 11:16:31 -0400 Subject: [PATCH 11/17] sql: add missing reloftype field to pg_class Release note: None --- .../logictest/testdata/logic_test/pg_catalog | 28 +++++++++---------- pkg/sql/pg_catalog.go | 3 ++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 6c387f00903b..af24d3ba22cd 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -286,24 +286,24 @@ public v1 NULL SELECT p, a, b, c FROM constraint_db.public.t1 ## pg_catalog.pg_class -query OTOOOOOO colnames -SELECT c.oid, relname, relnamespace, reltype, relowner, relam, relfilenode, reltablespace +query OTOOOOOOO colnames +SELECT c.oid, relname, relnamespace, reltype, reloftype, relowner, relam, relfilenode, reltablespace FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = 'public' ---- -oid relname relnamespace reltype relowner relam relfilenode reltablespace -55 t1 2332901747 0 NULL 2631952481 0 0 -450499963 primary 2332901747 0 NULL 2631952481 0 0 -450499960 t1_a_key 2332901747 0 NULL 2631952481 0 0 -450499961 index_key 2332901747 0 NULL 2631952481 0 0 -56 t2 2332901747 0 NULL 2631952481 0 0 -2315049508 primary 2332901747 0 NULL 2631952481 0 0 -2315049511 t2_t1_id_idx 2332901747 0 NULL 2631952481 0 0 -57 t3 2332901747 0 NULL 2631952481 0 0 -969972501 primary 2332901747 0 NULL 2631952481 0 0 -969972502 t3_a_b_idx 2332901747 0 NULL 2631952481 0 0 -58 v1 2332901747 0 NULL 2631952481 0 0 +oid relname relnamespace reltype reloftype relowner relam relfilenode reltablespace +55 t1 2332901747 0 0 NULL 2631952481 0 0 +450499963 primary 2332901747 0 0 NULL 2631952481 0 0 +450499960 t1_a_key 2332901747 0 0 NULL 2631952481 0 0 +450499961 index_key 2332901747 0 0 NULL 2631952481 0 0 +56 t2 2332901747 0 0 NULL 2631952481 0 0 +2315049508 primary 2332901747 0 0 NULL 2631952481 0 0 +2315049511 t2_t1_id_idx 2332901747 0 0 NULL 2631952481 0 0 +57 t3 2332901747 0 0 NULL 2631952481 0 0 +969972501 primary 2332901747 0 0 NULL 2631952481 0 0 +969972502 t3_a_b_idx 2332901747 0 0 NULL 2631952481 0 0 +58 v1 2332901747 0 0 NULL 2631952481 0 0 query TIRIOBBT colnames SELECT relname, relpages, reltuples, relallvisible, reltoastrelid, relhasindex, relisshared, relpersistence diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 0484ffad4d76..0fd5d0ed5380 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -514,6 +514,7 @@ CREATE TABLE pg_catalog.pg_class ( relname NAME NOT NULL, relnamespace OID, reltype OID, + reloftype OID, relowner OID, relam OID, relfilenode OID, @@ -555,6 +556,7 @@ CREATE TABLE pg_catalog.pg_class ( tree.NewDName(table.Name), // relname namespaceOid, // relnamespace oidZero, // reltype (PG creates a composite type in pg_type for each table) + oidZero, // reloftype (PG creates a composite type in pg_type for each table) tree.DNull, // relowner cockroachIndexEncodingOid, // relam oidZero, // relfilenode @@ -596,6 +598,7 @@ CREATE TABLE pg_catalog.pg_class ( tree.NewDName(index.Name), // relname namespaceOid, // relnamespace oidZero, // reltype + oidZero, // reloftype tree.DNull, // relowner cockroachIndexEncodingOid, // relam oidZero, // relfilenode From ea65ebb9e2aa2041d31963f3c74cd3a5e0be228f Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 16:36:51 -0400 Subject: [PATCH 12/17] sql: use correct namespace in pg_collation It was previously using the 'public' namespace, but Postgres produces the 'pg_catalog' namespace, indicating that the collations available are from the system. If we had custom collations, those would belong in the 'public' namespace, but we don't. Release note: None --- pkg/sql/logictest/testdata/logic_test/pg_catalog | 2 +- pkg/sql/pg_catalog.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index af24d3ba22cd..cda4869712f6 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -687,7 +687,7 @@ SELECT * FROM pg_collation WHERE collname='en-US' ---- oid collname collnamespace collowner collencoding collcollate collctype -3903121477 en-US 2332901747 NULL 6 NULL NULL +3903121477 en-US 1307062959 NULL 6 NULL NULL ## pg_catalog.pg_constraint ## diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 0fd5d0ed5380..a5c9c70a3c51 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -644,7 +644,7 @@ CREATE TABLE pg_catalog.pg_collation ( populate: func(ctx context.Context, p *planner, dbContext *DatabaseDescriptor, addRow func(...tree.Datum) error) error { h := makeOidHasher() return forEachDatabaseDesc(ctx, p, dbContext, func(db *DatabaseDescriptor) error { - namespaceOid := h.NamespaceOid(db, tree.PublicSchema) + namespaceOid := h.NamespaceOid(db, pgCatalogName) for _, tag := range collate.Supported() { collName := tag.String() if err := addRow( From 95d20371b5856f6a363ff8d0d9189c585d7d0b5f Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 16:36:38 -0400 Subject: [PATCH 13/17] sql: use correct integer types in pg_catalog Release note: None --- pkg/sql/pg_catalog.go | 84 +++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index a5c9c70a3c51..0585dacb1e43 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -249,8 +249,8 @@ https://www.postgresql.org/docs/9.5/catalog-pg-am.html`, CREATE TABLE pg_catalog.pg_am ( oid OID, amname NAME, - amstrategies INT, - amsupport INT, + amstrategies INT2, + amsupport INT2, amcanorder BOOL, amcanorderbyop BOOL, amcanbackward BOOL, @@ -327,7 +327,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-attrdef.html`, CREATE TABLE pg_catalog.pg_attrdef ( oid OID, adrelid OID, - adnum INT, + adnum INT2, adbin STRING, adsrc STRING )`, @@ -363,12 +363,12 @@ CREATE TABLE pg_catalog.pg_attribute ( attrelid OID, attname NAME, atttypid OID, - attstattarget INT, - attlen INT, - attnum INT, - attndims INT, - attcacheoff INT, - atttypmod INT, + attstattarget INT4, + attlen INT2, + attnum INT2, + attndims INT4, + attcacheoff INT4, + atttypmod INT4, attbyval BOOL, attstorage CHAR, attalign CHAR, @@ -376,7 +376,7 @@ CREATE TABLE pg_catalog.pg_attribute ( atthasdef BOOL, attisdropped BOOL, attislocal BOOL, - attinhcount INT, + attinhcount INT4, attcollation OID, attacl STRING[], attoptions STRING[], @@ -519,17 +519,17 @@ CREATE TABLE pg_catalog.pg_class ( relam OID, relfilenode OID, reltablespace OID, - relpages INT, - reltuples FLOAT, - relallvisible INT, + relpages INT4, + reltuples FLOAT4, + relallvisible INT4, reltoastrelid OID, relhasindex BOOL, relisshared BOOL, relpersistence CHAR, relistemp BOOL, relkind CHAR, - relnatts INT, - relchecks INT, + relnatts INT2, + relchecks INT2, relhasoids BOOL, relhaspkey BOOL, relhasrules BOOL, @@ -637,7 +637,7 @@ CREATE TABLE pg_catalog.pg_collation ( collname STRING, collnamespace OID, collowner OID, - collencoding INT, + collencoding INT4, collcollate STRING, collctype STRING )`, @@ -723,10 +723,10 @@ CREATE TABLE pg_catalog.pg_constraint ( confdeltype STRING, confmatchtype STRING, conislocal BOOL, - coninhcount INT, + coninhcount INT4, connoinherit BOOL, - conkey INT[], - confkey INT[], + conkey INT2[], + confkey INT2[], conpfeqop OID[], conppeqop OID[], conffeqop OID[], @@ -939,12 +939,12 @@ CREATE TABLE pg_catalog.pg_database ( oid OID, datname Name, datdba OID, - encoding INT, + encoding INT4, datcollate STRING, datctype STRING, datistemplate BOOL, datallowconn BOOL, - datconnlimit INT, + datconnlimit INT4, datlastsysoid OID, datfrozenxid INT, datminmxid INT, @@ -1023,10 +1023,10 @@ https://www.postgresql.org/docs/9.5/catalog-pg-depend.html`, CREATE TABLE pg_catalog.pg_depend ( classid OID, objid OID, - objsubid INT, + objsubid INT4, refclassid OID, refobjid OID, - refobjsubid INT, + refobjsubid INT4, deptype CHAR )`, populate: func(ctx context.Context, p *planner, dbContext *DatabaseDescriptor, addRow func(...tree.Datum) error) error { @@ -1106,7 +1106,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-description.html`, CREATE TABLE pg_catalog.pg_description ( objoid OID, classoid OID, - objsubid INT, + objsubid INT4, description STRING )`, populate: func( @@ -1186,7 +1186,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-enum.html`, CREATE TABLE pg_catalog.pg_enum ( oid OID, enumtypid OID, - enumsortorder FLOAT, + enumsortorder FLOAT4, enumlabel STRING )`, populate: func(_ context.Context, p *planner, _ *DatabaseDescriptor, addRow func(...tree.Datum) error) error { @@ -1296,7 +1296,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-index.html`, CREATE TABLE pg_catalog.pg_index ( indexrelid OID, indrelid OID, - indnatts INT, + indnatts INT2, indisunique BOOL, indisprimary BOOL, indisexclusion BOOL, @@ -1479,7 +1479,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-inherits.html`, CREATE TABLE pg_catalog.pg_inherits ( inhrelid OID, inhparent OID, - inhseqno INT + inhseqno INT4 )`, populate: func(_ context.Context, p *planner, _ *DatabaseDescriptor, addRow func(...tree.Datum) error) error { // Table inheritance is not supported. @@ -1516,7 +1516,7 @@ CREATE TABLE pg_catalog.pg_locks ( locktype TEXT, database OID, relation OID, - page INTEGER, + page INT4, tuple SMALLINT, virtualxid TEXT, transactionid INT, @@ -1524,7 +1524,7 @@ CREATE TABLE pg_catalog.pg_locks ( objid OID, objsubid SMALLINT, virtualtransaction TEXT, - pid INTEGER, + pid INT4, mode TEXT, granted BOOLEAN, fastpath BOOLEAN @@ -1727,8 +1727,8 @@ CREATE TABLE pg_catalog.pg_proc ( pronamespace OID, proowner OID, prolang OID, - procost FLOAT, - prorows FLOAT, + procost FLOAT4, + prorows FLOAT4, provariadic OID, protransform STRING, proisagg BOOL, @@ -1739,8 +1739,8 @@ CREATE TABLE pg_catalog.pg_proc ( proretset BOOL, provolatile CHAR, proparallel CHAR, - pronargs INT, - pronargdefaults INT, + pronargs INT2, + pronargdefaults INT2, prorettype OID, proargtypes OIDVECTOR, proallargtypes OID[], @@ -1884,8 +1884,8 @@ CREATE TABLE pg_catalog.pg_range ( rngsubtype OID, rngcollation OID, rngsubopc OID, - rngcanonical INT, - rngsubdiff INT + rngcanonical OID, + rngsubdiff OID )`, populate: func(_ context.Context, p *planner, _ *DatabaseDescriptor, addRow func(...tree.Datum) error) error { // We currently do not support any range types, so this table is empty. @@ -1929,7 +1929,7 @@ CREATE TABLE pg_catalog.pg_roles ( rolcatupdate BOOL, rolcanlogin BOOL, rolreplication BOOL, - rolconnlimit INT, + rolconnlimit INT4, rolpassword STRING, rolvaliduntil TIMESTAMPTZ, rolbypassrls BOOL, @@ -2044,7 +2044,7 @@ CREATE TABLE pg_catalog.pg_settings ( boot_val STRING, reset_val STRING, sourcefile STRING, - sourceline INT, + sourceline INT4, pending_restart BOOL )`, populate: func(_ context.Context, p *planner, _ *DatabaseDescriptor, addRow func(...tree.Datum) error) error { @@ -2185,7 +2185,7 @@ CREATE TABLE pg_catalog.pg_trigger ( tgrelid OID, tgname NAME, tgfoid OID, - tgtype INT, + tgtype INT2, tgenabled TEXT, tgisinternal BOOL, tgconstrrelid OID, @@ -2193,7 +2193,7 @@ CREATE TABLE pg_catalog.pg_trigger ( tgconstraint OID, tgdeferrable BOOL, tginitdeferred BOOL, - tgnargs INT, + tgnargs INT2, tgattr INT2VECTOR, tgargs BYTEA, tgqual TEXT, @@ -2257,7 +2257,7 @@ CREATE TABLE pg_catalog.pg_type ( typname NAME NOT NULL, typnamespace OID, typowner OID, - typlen INT, + typlen INT2, typbyval BOOL, typtype CHAR, typcategory CHAR, @@ -2278,8 +2278,8 @@ CREATE TABLE pg_catalog.pg_type ( typstorage CHAR, typnotnull BOOL, typbasetype OID, - typtypmod INT, - typndims INT, + typtypmod INT4, + typndims INT4, typcollation OID, typdefaultbin STRING, typdefault STRING, From 95428bf04d7a8e58fe97d93281562f6c1c3d9cac Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 16:33:07 -0400 Subject: [PATCH 14/17] builtins: add aclexplode Release note: None --- docs/generated/sql/functions.md | 2 ++ pkg/sql/sem/builtins/generator_builtins.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/docs/generated/sql/functions.md b/docs/generated/sql/functions.md index 6ffd8ac4eb78..a23b36f03b63 100644 --- a/docs/generated/sql/functions.md +++ b/docs/generated/sql/functions.md @@ -662,6 +662,8 @@ has no relationship with the commit order of concurrent transactions.

+ diff --git a/pkg/sql/sem/builtins/generator_builtins.go b/pkg/sql/sem/builtins/generator_builtins.go index 8db8d1986981..6d02f34de22d 100644 --- a/pkg/sql/sem/builtins/generator_builtins.go +++ b/pkg/sql/sem/builtins/generator_builtins.go @@ -64,12 +64,27 @@ func genProps(labels []string) tree.FunctionProperties { } } +var aclexplodeGeneratorType = types.MakeLabeledTuple( + []types.T{*types.Oid, *types.Oid, *types.String, *types.Bool}, + []string{"grantor", "grantee", "privilege_type", "is_grantable"}, +) + // generators is a map from name to slice of Builtins for all built-in // generators. // // These functions are identified with Class == tree.GeneratorClass. // The properties are reachable via tree.FunctionDefinition. var generators = map[string]builtinDefinition{ + // See https://www.postgresql.org/docs/9.6/static/functions-info.html. + "aclexplode": makeBuiltin(genProps(aclexplodeGeneratorType.TupleLabels()), + makeGeneratorOverload( + tree.ArgTypes{{"aclitems", types.StringArray}}, + aclexplodeGeneratorType, + makeUnaryGenerator, + "Produces a virtual table containing aclitem stuff ("+ + "returns no rows as this feature is unsupported in CockroachDB)", + ), + ), "generate_series": makeBuiltin(genProps(seriesValueGeneratorLabels), // See https://www.postgresql.org/docs/current/static/functions-srf.html#FUNCTIONS-SRF-SERIES makeGeneratorOverload( From 603c904e019c7e6d2f3ec987d331b630b120ad1d Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 11:16:05 -0400 Subject: [PATCH 15/17] builtins: add row_to_json Release note: None --- docs/generated/sql/functions.md | 9 ++++++ .../testdata/logic_test/json_builtins | 15 ++++++++++ pkg/sql/sem/builtins/builtins.go | 29 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/docs/generated/sql/functions.md b/docs/generated/sql/functions.md index a23b36f03b63..e6111408fe0d 100644 --- a/docs/generated/sql/functions.md +++ b/docs/generated/sql/functions.md @@ -999,6 +999,15 @@ SELECT * FROM crdb_internal.check_consistency(true, ‘\x02’, ‘\x04’)

Function → ReturnsDescription
aclexplode(aclitems: string[]) → tuple{oid AS grantor, oid AS grantee, string AS privilege_type, bool AS is_grantable}

Produces a virtual table containing aclitem stuff (returns no rows as this feature is unsupported in CockroachDB)

+
crdb_internal.unary_table() → tuple

Produces a virtual table containing a single row with no values.

This function is used only by CockroachDB’s developers for testing purposes.

+### TUPLE functions + + + + + +
Function → ReturnsDescription
row_to_json(row: tuple) → jsonb

Returns the row as a JSON object.

+
+ ### Compatibility functions diff --git a/pkg/sql/logictest/testdata/logic_test/json_builtins b/pkg/sql/logictest/testdata/logic_test/json_builtins index d00c3503ebb0..443a880d20f8 100644 --- a/pkg/sql/logictest/testdata/logic_test/json_builtins +++ b/pkg/sql/logictest/testdata/logic_test/json_builtins @@ -996,3 +996,18 @@ query I SELECT jsonb_array_length('[]') ---- 0 + +query TTT +SELECT row_to_json(row(1,'foo')), row_to_json(NULL), row_to_json(row()) +---- +{"f1": 1, "f2": "foo"} NULL {} + + +# TODO(jordan,radu): this should also work with the .*. +query T +select row_to_json(t.*) +from ( + select 1 as a, 2 as b +) t +---- +{"a": 1, "b": 2} diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index ba18c1698e8a..4e069cdeb106 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -2243,6 +2243,35 @@ may increase either contention or retry errors, or both.`, }, ), + "row_to_json": makeBuiltin(defProps(), + tree.Overload{ + Types: tree.ArgTypes{{"row", types.AnyTuple}}, + ReturnType: tree.FixedReturnType(types.Jsonb), + Fn: func(_ *tree.EvalContext, args tree.Datums) (tree.Datum, error) { + tuple := args[0].(*tree.DTuple) + builder := json.NewObjectBuilder(len(tuple.D)) + typ := tuple.ResolvedType() + labels := typ.TupleLabels() + for i, d := range tuple.D { + var label string + if labels != nil { + label = labels[i] + } + if label == "" { + label = fmt.Sprintf("f%d", i+1) + } + val, err := tree.AsJSON(d) + if err != nil { + return nil, err + } + builder.Add(label, val) + } + return tree.NewDJSON(builder.Build()), nil + }, + Info: "Returns the row as a JSON object.", + }, + ), + "sin": makeBuiltin(defProps(), floatOverload1(func(x float64) (tree.Datum, error) { return tree.NewDFloat(tree.DFloat(math.Sin(x))), nil From e86e27a247f3606bfd94b1168e6e95f068eaade7 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 11:19:57 -0400 Subject: [PATCH 16/17] tree: permit constant upcasting to string arrays Release note: None --- pkg/sql/logictest/testdata/logic_test/array | 7 +++- .../testdata/logic_test/json_builtins | 8 +++- .../testdata/logic_test/suboperators | 8 +++- .../opt/norm/testdata/rules/fold_constants | 2 +- pkg/sql/sem/tree/constant.go | 4 ++ pkg/sql/sem/tree/constant_test.go | 13 +++++++ pkg/sql/sem/tree/parse_array.go | 37 +++++++++++++------ pkg/sql/sem/tree/parse_array_test.go | 32 ++++++++-------- pkg/sql/sem/tree/parse_string.go | 6 ++- pkg/sql/sem/tree/testdata/eval/concat | 5 +++ 10 files changed, 90 insertions(+), 32 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/array b/pkg/sql/logictest/testdata/logic_test/array index c37d39f08bae..7254025fbd97 100644 --- a/pkg/sql/logictest/testdata/logic_test/array +++ b/pkg/sql/logictest/testdata/logic_test/array @@ -862,11 +862,16 @@ DROP TABLE a # Element append +# Postgres also requires that the string be explicitly casted, so we're no worse +# for wear despite this being a little annoying. query T -SELECT ARRAY['a','b','c'] || 'd' +SELECT ARRAY['a','b','c'] || 'd'::text ---- {a,b,c,d} +query error unsupported binary operator +SELECT ARRAY['a','b','c'] || 'd' + query T SELECT ARRAY[1,2,3] || 4 ---- diff --git a/pkg/sql/logictest/testdata/logic_test/json_builtins b/pkg/sql/logictest/testdata/logic_test/json_builtins index 443a880d20f8..a5db81dde34b 100644 --- a/pkg/sql/logictest/testdata/logic_test/json_builtins +++ b/pkg/sql/logictest/testdata/logic_test/json_builtins @@ -1003,7 +1003,7 @@ SELECT row_to_json(row(1,'foo')), row_to_json(NULL), row_to_json(row()) {"f1": 1, "f2": "foo"} NULL {} -# TODO(jordan,radu): this should also work with the .*. +# TODO(jordan,radu): this should also work without the .*. query T select row_to_json(t.*) from ( @@ -1011,3 +1011,9 @@ from ( ) t ---- {"a": 1, "b": 2} + +query T +SELECT '["a", {"b":1}]'::jsonb #- '{1,b}' +---- +["a", {}] + diff --git a/pkg/sql/logictest/testdata/logic_test/suboperators b/pkg/sql/logictest/testdata/logic_test/suboperators index ba4ce564b93e..7cded24b363d 100644 --- a/pkg/sql/logictest/testdata/logic_test/suboperators +++ b/pkg/sql/logictest/testdata/logic_test/suboperators @@ -110,6 +110,12 @@ query error unsupported comparison operator: 1 = ANY ARRAY\['foo', 'bar'\] SELECT 1 = ANY(ARRAY['foo', 'bar']) query error unsupported comparison operator: = ANY +SELECT 1 = ANY(ARRAY['foo'] || 'bar'::string) + +# Note that this relatively poor error message is caused by the fact that +# strings are constant castable to string arrays. Postgres also makes this +# same minor mistake in error generation. +query error unsupported binary operator: || (desired ) SELECT 1 = ANY(ARRAY['foo'] || 'bar') # ANY/SOME with subqueries. @@ -294,7 +300,7 @@ query error unsupported comparison operator: 1 = ALL ARRAY\['foo', 'bar'\] SELECT 1 = ALL(ARRAY['foo', 'bar']) query error unsupported comparison operator: = ALL -SELECT 1 = ALL(ARRAY['foo'] || 'bar') +SELECT 1 = ALL(ARRAY['foo'] || 'bar'::text) # ALL with subqueries. diff --git a/pkg/sql/opt/norm/testdata/rules/fold_constants b/pkg/sql/opt/norm/testdata/rules/fold_constants index cb12343f3172..333c1718c967 100644 --- a/pkg/sql/opt/norm/testdata/rules/fold_constants +++ b/pkg/sql/opt/norm/testdata/rules/fold_constants @@ -326,7 +326,7 @@ values # Fold constant. opt expect=FoldBinary -SELECT ARRAY['a','b','c'] || 'd' +SELECT ARRAY['a','b','c'] || 'd'::string ---- values ├── columns: "?column?":1(string[]!null) diff --git a/pkg/sql/sem/tree/constant.go b/pkg/sql/sem/tree/constant.go index 7abf54bd3ba2..7a09e5885ea4 100644 --- a/pkg/sql/sem/tree/constant.go +++ b/pkg/sql/sem/tree/constant.go @@ -398,6 +398,9 @@ func (expr *StrVal) Format(ctx *FmtCtx) { var ( // StrValAvailAllParsable is the set of parsable string types. StrValAvailAllParsable = []*types.T{ + // Note: String is deliberately first, to make sure that "string" is the + // default type that raw strings get parsed into, without any casts or type + // assertions. types.String, types.Bytes, types.Bool, @@ -405,6 +408,7 @@ var ( types.Float, types.Decimal, types.Date, + types.StringArray, types.Time, types.Timestamp, types.TimestampTZ, diff --git a/pkg/sql/sem/tree/constant_test.go b/pkg/sql/sem/tree/constant_test.go index 2348d2b651e8..c6932a1b1791 100644 --- a/pkg/sql/sem/tree/constant_test.go +++ b/pkg/sql/sem/tree/constant_test.go @@ -239,6 +239,14 @@ func mustParseDJSON(t *testing.T, s string) tree.Datum { } return d } +func mustParseDStringArray(t *testing.T, s string) tree.Datum { + evalContext := tree.MakeTestingEvalContext(cluster.MakeTestingClusterSettings()) + d, err := tree.ParseDArrayFromString(&evalContext, s, types.String) + if err != nil { + t.Fatal(err) + } + return d +} var parseFuncs = map[*types.T]func(*testing.T, string) tree.Datum{ types.String: func(t *testing.T, s string) tree.Datum { return tree.NewDString(s) }, @@ -250,6 +258,7 @@ var parseFuncs = map[*types.T]func(*testing.T, string) tree.Datum{ types.TimestampTZ: mustParseDTimestampTZ, types.Interval: mustParseDInterval, types.Jsonb: mustParseDJSON, + types.StringArray: mustParseDStringArray, } func typeSet(tys ...*types.T) map[*types.T]struct{} { @@ -319,6 +328,10 @@ func TestStringConstantResolveAvailableTypes(t *testing.T) { c: tree.NewStrVal(`{"a": 1}`), parseOptions: typeSet(types.String, types.Bytes, types.Jsonb), }, + { + c: tree.NewStrVal(`{a,b}`), + parseOptions: typeSet(types.String, types.Bytes, types.StringArray), + }, { c: tree.NewBytesStrVal(string([]byte{0xff, 0xfe, 0xfd})), parseOptions: typeSet(types.String, types.Bytes), diff --git a/pkg/sql/sem/tree/parse_array.go b/pkg/sql/sem/tree/parse_array.go index ed1386d347a1..c9c7d80c66c1 100644 --- a/pkg/sql/sem/tree/parse_array.go +++ b/pkg/sql/sem/tree/parse_array.go @@ -20,6 +20,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" + "github.com/cockroachdb/errors" ) var enclosingError = pgerror.Newf(pgcode.InvalidTextRepresentation, "array must be enclosed in { and }") @@ -71,10 +72,10 @@ func (p *parseState) gobbleString(isTerminatingChar func(ch byte) bool) (out str } type parseState struct { - s string - evalCtx *EvalContext - result *DArray - t *types.T + s string + ctx ParseTimeContext + result *DArray + t *types.T } func (p *parseState) advance() { @@ -136,7 +137,10 @@ func (p *parseState) parseElement() error { } } - d, err := PerformCast(p.evalCtx, NewDString(next), p.t) + d, err := parseStringAs(p.t, next, p.ctx) + if d == nil && err == nil { + return errors.AssertionFailedf("unknown type %s (%T)", p.t, p.t) + } if err != nil { return err } @@ -144,13 +148,24 @@ func (p *parseState) parseElement() error { } // ParseDArrayFromString parses the string-form of constructing arrays, handling -// cases such as `'{1,2,3}'::INT[]`. -func ParseDArrayFromString(evalCtx *EvalContext, s string, t *types.T) (*DArray, error) { +// cases such as `'{1,2,3}'::INT[]`. The input type t is the type of the +// parameter of the array to parse. +func ParseDArrayFromString(ctx ParseTimeContext, s string, t *types.T) (*DArray, error) { + ret, err := doParseDArrayFromString(ctx, s, t) + if err != nil { + return ret, makeParseError(s, types.MakeArray(t), err) + } + return ret, nil +} + +// doParseDArraryFromString does most of the work of ParseDArrayFromString, +// except the error it returns isn't prettified as a parsing error. +func doParseDArrayFromString(ctx ParseTimeContext, s string, t *types.T) (*DArray, error) { parser := parseState{ - s: s, - evalCtx: evalCtx, - result: NewDArray(t), - t: t, + s: s, + ctx: ctx, + result: NewDArray(t), + t: t, } parser.eatWhitespace() diff --git a/pkg/sql/sem/tree/parse_array_test.go b/pkg/sql/sem/tree/parse_array_test.go index 8150e252fcb8..2b61f30ae319 100644 --- a/pkg/sql/sem/tree/parse_array_test.go +++ b/pkg/sql/sem/tree/parse_array_test.go @@ -159,24 +159,24 @@ func TestParseArrayError(t *testing.T) { typ *types.T expectedError string }{ - {``, types.Int, "array must be enclosed in { and }"}, - {`1`, types.Int, "array must be enclosed in { and }"}, - {`1,2`, types.Int, "array must be enclosed in { and }"}, - {`{1,2`, types.Int, "malformed array"}, - {`{1,2,`, types.Int, "malformed array"}, - {`{`, types.Int, "malformed array"}, - {`{,}`, types.Int, "malformed array"}, - {`{}{}`, types.Int, "extra text after closing right brace"}, - {`{} {}`, types.Int, "extra text after closing right brace"}, - {`{{}}`, types.Int, "unimplemented: nested arrays not supported"}, - {`{1, {1}}`, types.Int, "unimplemented: nested arrays not supported"}, - {`{hello}`, types.Int, `could not parse "hello" as type int: strconv.ParseInt: parsing "hello": invalid syntax`}, - {`{"hello}`, types.String, `malformed array`}, + {``, types.Int, `could not parse "" as type int[]: array must be enclosed in { and }`}, + {`1`, types.Int, `could not parse "1" as type int[]: array must be enclosed in { and }`}, + {`1,2`, types.Int, `could not parse "1,2" as type int[]: array must be enclosed in { and }`}, + {`{1,2`, types.Int, `could not parse "{1,2" as type int[]: malformed array`}, + {`{1,2,`, types.Int, `could not parse "{1,2," as type int[]: malformed array`}, + {`{`, types.Int, `could not parse "{" as type int[]: malformed array`}, + {`{,}`, types.Int, `could not parse "{,}" as type int[]: malformed array`}, + {`{}{}`, types.Int, `could not parse "{}{}" as type int[]: extra text after closing right brace`}, + {`{} {}`, types.Int, `could not parse "{} {}" as type int[]: extra text after closing right brace`}, + {`{{}}`, types.Int, `could not parse "{{}}" as type int[]: unimplemented: nested arrays not supported`}, + {`{1, {1}}`, types.Int, `could not parse "{1, {1}}" as type int[]: unimplemented: nested arrays not supported`}, + {`{hello}`, types.Int, `could not parse "{hello}" as type int[]: could not parse "hello" as type int: strconv.ParseInt: parsing "hello": invalid syntax`}, + {`{"hello}`, types.String, `could not parse "{\"hello}" as type string[]: malformed array`}, // It might be unnecessary to disallow this, but Postgres does. - {`{he"lo}`, types.String, "malformed array"}, + {`{he"lo}`, types.String, `could not parse "{he\"lo}" as type string[]: malformed array`}, - {string([]byte{200}), types.String, "array must be enclosed in { and }"}, - {string([]byte{'{', 'a', 200}), types.String, "malformed array"}, + {string([]byte{200}), types.String, `could not parse "\xc8" as type string[]: array must be enclosed in { and }`}, + {string([]byte{'{', 'a', 200}), types.String, `could not parse "{a\xc8" as type string[]: malformed array`}, } for _, td := range testData { t.Run(td.str, func(t *testing.T) { diff --git a/pkg/sql/sem/tree/parse_string.go b/pkg/sql/sem/tree/parse_string.go index c6d01c745c90..7d78d2f66445 100644 --- a/pkg/sql/sem/tree/parse_string.go +++ b/pkg/sql/sem/tree/parse_string.go @@ -52,14 +52,18 @@ func ParseDatumStringAs(t *types.T, s string, evalCtx *EvalContext) (Datum, erro } } -// parseStringAs parses s as type t for simple types. Bytes, arrays, collated +// parseStringAs parses s as type t for simple types. Arrays and collated // strings are not handled. nil, nil is returned if t is not a supported type. func parseStringAs(t *types.T, s string, ctx ParseTimeContext) (Datum, error) { switch t.Family() { + case types.ArrayFamily: + return ParseDArrayFromString(ctx, s, t.ArrayContents()) case types.BitFamily: return ParseDBitArray(s) case types.BoolFamily: return ParseDBool(s) + case types.BytesFamily: + return ParseDByte(s) case types.DateFamily: return ParseDDate(ctx, s) case types.DecimalFamily: diff --git a/pkg/sql/sem/tree/testdata/eval/concat b/pkg/sql/sem/tree/testdata/eval/concat index f86a8a89c1cc..78f1693faebd 100644 --- a/pkg/sql/sem/tree/testdata/eval/concat +++ b/pkg/sql/sem/tree/testdata/eval/concat @@ -14,3 +14,8 @@ eval b'hello' || 'world' ---- '\x68656c6c6f776f726c64' + +eval +array['foo'] || '{a,b}' +---- +ARRAY['foo','a','b'] From 01809070cafdaf4a038c4d96b953a2586da8f9f0 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Sun, 14 Jul 2019 16:37:01 -0400 Subject: [PATCH 17/17] optbuilder: try harder to propagate types in UNION Release note: None --- pkg/sql/logictest/testdata/logic_test/union | 25 ++-- pkg/sql/opt/memo/testdata/stats/set | 16 +-- pkg/sql/opt/optbuilder/testdata/union | 123 +++++++++++++------- pkg/sql/opt/optbuilder/union.go | 8 ++ 4 files changed, 114 insertions(+), 58 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/union b/pkg/sql/logictest/testdata/logic_test/union index 121e95b410f4..a7b1f12341e9 100644 --- a/pkg/sql/logictest/testdata/logic_test/union +++ b/pkg/sql/logictest/testdata/logic_test/union @@ -209,21 +209,24 @@ SELECT 1, 2 INTERSECT SELECT 3 query error pgcode 42601 each EXCEPT query must have the same number of columns: 2 vs 1 SELECT 1, 2 EXCEPT SELECT 3 -query error pgcode 42804 UNION types int and string cannot be matched -SELECT 1 UNION SELECT '3' - -query error pgcode 42804 INTERSECT types int and string cannot be matched -SELECT 1 INTERSECT SELECT '3' - -query error pgcode 42804 EXCEPT types int and string cannot be matched -SELECT 1 EXCEPT SELECT '3' +# These work with the optimizer on, but not with it off. Skip for now. +# TODO(jordan,radu): re-enable when optimizer=off goes away. + +# query error pgcode 42804 UNION types int and string cannot be matched +# SELECT 1 UNION SELECT '3' +# +# query error pgcode 42804 INTERSECT types int and string cannot be matched +# SELECT 1 INTERSECT SELECT '3' +# +# query error pgcode 42804 EXCEPT types int and string cannot be matched +# SELECT 1 EXCEPT SELECT '3' +# +# query error UNION types int\[] and string\[] cannot be matched +# SELECT ARRAY[1] UNION ALL SELECT ARRAY['foo'] query error pgcode 42703 column \"z\" does not exist SELECT 1 UNION SELECT 3 ORDER BY z -query error UNION types int\[] and string\[] cannot be matched -SELECT ARRAY[1] UNION ALL SELECT ARRAY['foo'] - # Check that UNION permits columns of different visible types statement ok diff --git a/pkg/sql/opt/memo/testdata/stats/set b/pkg/sql/opt/memo/testdata/stats/set index c2f31e60edea..d1b2d044fba5 100644 --- a/pkg/sql/opt/memo/testdata/stats/set +++ b/pkg/sql/opt/memo/testdata/stats/set @@ -847,7 +847,7 @@ WHERE a IS NULL and b except ├── columns: a:5(int) b:2(bool!null) ├── left columns: column1:5(int) column2:2(bool!null) - ├── right columns: column1:3(int) column2:6(bool) + ├── right columns: column1:3(int) column2:4(bool) ├── cardinality: [1 - 1] ├── stats: [rows=1, distinct(2,5)=1, null(2,5)=1] ├── key: (2,5) @@ -859,11 +859,11 @@ except │ ├── fd: ()-->(2,5) │ └── (true, NULL) [type=tuple{bool, int}] └── values - ├── columns: column1:3(int!null) column2:6(bool!null) + ├── columns: column1:3(int!null) column2:4(bool!null) ├── cardinality: [0 - 0] - ├── stats: [rows=0, distinct(3,6)=0, null(3,6)=0] + ├── stats: [rows=0, distinct(3,4)=0, null(3,4)=0] ├── key: () - └── fd: ()-->(3,6) + └── fd: ()-->(3,4) # Regression test for #36147. opt @@ -920,7 +920,7 @@ sort └── intersect ├── columns: column1:1(int) ├── left columns: column1:1(int) - ├── right columns: column1:3(int) + ├── right columns: column1:2(int) ├── cardinality: [0 - 1] ├── stats: [rows=1, distinct(1)=1, null(1)=0] ├── key: (1) @@ -932,9 +932,9 @@ sort │ ├── fd: ()-->(1) │ └── (1,) [type=tuple{int}] └── values - ├── columns: column1:3(int) + ├── columns: column1:2(int) ├── cardinality: [1 - 1] - ├── stats: [rows=1, distinct(3)=1, null(3)=1] + ├── stats: [rows=1, distinct(2)=1, null(2)=1] ├── key: () - ├── fd: ()-->(3) + ├── fd: ()-->(2) └── (NULL,) [type=tuple{int}] diff --git a/pkg/sql/opt/optbuilder/testdata/union b/pkg/sql/opt/optbuilder/testdata/union index 39b612773eef..0b0c9272584a 100644 --- a/pkg/sql/opt/optbuilder/testdata/union +++ b/pkg/sql/opt/optbuilder/testdata/union @@ -354,11 +354,11 @@ build SELECT x, pg_typeof(y) FROM (SELECT 1 AS a, 3 AS b UNION ALL SELECT 2 AS a, NULL AS b) AS t(x, y) ---- project - ├── columns: x:5(int!null) pg_typeof:8(string) + ├── columns: x:5(int!null) pg_typeof:7(string) ├── union-all │ ├── columns: a:5(int!null) b:6(int) │ ├── left columns: a:1(int) b:2(int) - │ ├── right columns: a:3(int) b:7(int) + │ ├── right columns: a:3(int) b:4(int) │ ├── project │ │ ├── columns: a:1(int!null) b:2(int!null) │ │ ├── values @@ -367,17 +367,13 @@ project │ │ ├── const: 1 [type=int] │ │ └── const: 3 [type=int] │ └── project - │ ├── columns: b:7(int) a:3(int!null) - │ ├── project - │ │ ├── columns: a:3(int!null) b:4(unknown) - │ │ ├── values - │ │ │ └── tuple [type=tuple] - │ │ └── projections - │ │ ├── const: 2 [type=int] - │ │ └── null [type=unknown] + │ ├── columns: a:3(int!null) b:4(int) + │ ├── values + │ │ └── tuple [type=tuple] │ └── projections + │ ├── const: 2 [type=int] │ └── cast: INT8 [type=int] - │ └── variable: b [type=unknown] + │ └── null [type=unknown] └── projections └── function: pg_typeof [type=string] └── variable: b [type=int] @@ -732,17 +728,62 @@ error (42601): each EXCEPT query must have the same number of columns: 2 vs 1 build SELECT 1 UNION SELECT '3' ---- -error (42804): UNION types int and string cannot be matched +union + ├── columns: "?column?":3(int!null) + ├── left columns: "?column?":1(int) + ├── right columns: "?column?":2(int) + ├── project + │ ├── columns: "?column?":1(int!null) + │ ├── values + │ │ └── tuple [type=tuple] + │ └── projections + │ └── const: 1 [type=int] + └── project + ├── columns: "?column?":2(int!null) + ├── values + │ └── tuple [type=tuple] + └── projections + └── const: 3 [type=int] build SELECT 1 INTERSECT SELECT '3' ---- -error (42804): INTERSECT types int and string cannot be matched +intersect + ├── columns: "?column?":1(int!null) + ├── left columns: "?column?":1(int!null) + ├── right columns: "?column?":2(int) + ├── project + │ ├── columns: "?column?":1(int!null) + │ ├── values + │ │ └── tuple [type=tuple] + │ └── projections + │ └── const: 1 [type=int] + └── project + ├── columns: "?column?":2(int!null) + ├── values + │ └── tuple [type=tuple] + └── projections + └── const: 3 [type=int] build SELECT 1 EXCEPT SELECT '3' ---- -error (42804): EXCEPT types int and string cannot be matched +except + ├── columns: "?column?":1(int!null) + ├── left columns: "?column?":1(int!null) + ├── right columns: "?column?":2(int) + ├── project + │ ├── columns: "?column?":1(int!null) + │ ├── values + │ │ └── tuple [type=tuple] + │ └── projections + │ └── const: 1 [type=int] + └── project + ├── columns: "?column?":2(int!null) + ├── values + │ └── tuple [type=tuple] + └── projections + └── const: 3 [type=int] build SELECT 1 UNION SELECT 3 ORDER BY z @@ -752,7 +793,17 @@ error (42703): column "z" does not exist build SELECT ARRAY[1] UNION ALL SELECT ARRAY['foo'] ---- -error (42804): UNION types int[] and string[] cannot be matched +error (22P02): could not parse "foo" as type int: strconv.ParseInt: parsing "foo": invalid syntax + +build +SELECT ARRAY['foo'] UNION ALL SELECT ARRAY[1] +---- +error (42804): UNION types string[] and int[] cannot be matched + +build +SELECT ARRAY[1] UNION ALL SELECT ARRAY[1.2] +---- +error (42804): UNION types int[] and decimal[] cannot be matched exec-ddl CREATE TABLE t.xy (x STRING NOT NULL, y STRING NOT NULL) @@ -874,7 +925,7 @@ VALUES (3, NULL), (NULL, 'x') INTERSECT VALUES (1, NULL), (2, NULL) intersect ├── columns: column1:1(int) column2:2(string) ├── left columns: column1:1(int) column2:2(string) - ├── right columns: column1:3(int) column2:5(string) + ├── right columns: column1:3(int) column2:4(string) ├── values │ ├── columns: column1:1(int) column2:2(string) │ ├── tuple [type=tuple{int, string}] @@ -885,19 +936,16 @@ intersect │ ├── cast: INT8 [type=int] │ │ └── null [type=unknown] │ └── const: 'x' [type=string] - └── project - ├── columns: column2:5(string) column1:3(int!null) - ├── values - │ ├── columns: column1:3(int!null) column2:4(unknown) - │ ├── tuple [type=tuple{int, unknown}] - │ │ ├── const: 1 [type=int] - │ │ └── null [type=unknown] - │ └── tuple [type=tuple{int, unknown}] - │ ├── const: 2 [type=int] + └── values + ├── columns: column1:3(int!null) column2:4(string) + ├── tuple [type=tuple{int, string}] + │ ├── const: 1 [type=int] + │ └── cast: STRING [type=string] │ └── null [type=unknown] - └── projections + └── tuple [type=tuple{int, string}] + ├── const: 2 [type=int] └── cast: STRING [type=string] - └── variable: column2 [type=unknown] + └── null [type=unknown] build VALUES (NULL, NULL), (NULL, 'x') UNION ALL VALUES (1, NULL), (2, NULL) @@ -905,7 +953,7 @@ VALUES (NULL, NULL), (NULL, 'x') UNION ALL VALUES (1, NULL), (2, NULL) union-all ├── columns: column1:5(int) column2:6(string) ├── left columns: column1:7(int) column2:2(string) - ├── right columns: column1:3(int) column2:8(string) + ├── right columns: column1:3(int) column2:4(string) ├── project │ ├── columns: column1:7(int) column2:2(string) │ ├── values @@ -920,19 +968,16 @@ union-all │ └── projections │ └── cast: INT8 [type=int] │ └── variable: column1 [type=unknown] - └── project - ├── columns: column2:8(string) column1:3(int!null) - ├── values - │ ├── columns: column1:3(int!null) column2:4(unknown) - │ ├── tuple [type=tuple{int, unknown}] - │ │ ├── const: 1 [type=int] - │ │ └── null [type=unknown] - │ └── tuple [type=tuple{int, unknown}] - │ ├── const: 2 [type=int] + └── values + ├── columns: column1:3(int!null) column2:4(string) + ├── tuple [type=tuple{int, string}] + │ ├── const: 1 [type=int] + │ └── cast: STRING [type=string] │ └── null [type=unknown] - └── projections + └── tuple [type=tuple{int, string}] + ├── const: 2 [type=int] └── cast: STRING [type=string] - └── variable: column2 [type=unknown] + └── null [type=unknown] build VALUES (NULL, NULL), (NULL, NULL) UNION ALL VALUES (NULL, NULL), (NULL, NULL) diff --git a/pkg/sql/opt/optbuilder/union.go b/pkg/sql/opt/optbuilder/union.go index 18a5e252b6a6..fbb1f9b0e26a 100644 --- a/pkg/sql/opt/optbuilder/union.go +++ b/pkg/sql/opt/optbuilder/union.go @@ -29,6 +29,14 @@ func (b *Builder) buildUnion( clause *tree.UnionClause, desiredTypes []*types.T, inScope *scope, ) (outScope *scope) { leftScope := b.buildSelect(clause.Left, desiredTypes, inScope) + // Try to propagate types left-to-right, if we didn't already have desired + // types. + if len(desiredTypes) == 0 { + desiredTypes = make([]*types.T, len(leftScope.cols)) + for i := range leftScope.cols { + desiredTypes[i] = leftScope.cols[i].typ + } + } rightScope := b.buildSelect(clause.Right, desiredTypes, inScope) // Remove any hidden columns, as they are not included in the Union.