# LogicTest: local

# Set the distsql_workmem to the default production value because of a problem
# with losing 'name' attribute when spilling to disk (#78547).
statement ok
SET distsql_workmem = '64MiB'

# Verify pg_catalog database handles mutation statements correctly.

query error database "pg_catalog" does not exist
ALTER DATABASE pg_catalog RENAME TO not_pg_catalog

statement error schema cannot be modified: "pg_catalog"
CREATE TABLE pg_catalog.t (x INT)

query error database "pg_catalog" does not exist
DROP DATABASE pg_catalog

query TTTTIT rowsort
SHOW TABLES FROM pg_catalog
----
pg_catalog  pg_aggregate                     table  node  NULL  NULL
pg_catalog  pg_am                            table  node  NULL  NULL
pg_catalog  pg_amop                          table  node  NULL  NULL
pg_catalog  pg_amproc                        table  node  NULL  NULL
pg_catalog  pg_attrdef                       table  node  NULL  NULL
pg_catalog  pg_attribute                     table  node  NULL  NULL
pg_catalog  pg_auth_members                  table  node  NULL  NULL
pg_catalog  pg_authid                        table  node  NULL  NULL
pg_catalog  pg_available_extension_versions  table  node  NULL  NULL
pg_catalog  pg_available_extensions          table  node  NULL  NULL
pg_catalog  pg_cast                          table  node  NULL  NULL
pg_catalog  pg_class                         table  node  NULL  NULL
pg_catalog  pg_collation                     table  node  NULL  NULL
pg_catalog  pg_config                        table  node  NULL  NULL
pg_catalog  pg_constraint                    table  node  NULL  NULL
pg_catalog  pg_conversion                    table  node  NULL  NULL
pg_catalog  pg_cursors                       table  node  NULL  NULL
pg_catalog  pg_database                      table  node  NULL  NULL
pg_catalog  pg_db_role_setting               table  node  NULL  NULL
pg_catalog  pg_default_acl                   table  node  NULL  NULL
pg_catalog  pg_depend                        table  node  NULL  NULL
pg_catalog  pg_description                   view   node  NULL  NULL
pg_catalog  pg_enum                          table  node  NULL  NULL
pg_catalog  pg_event_trigger                 table  node  NULL  NULL
pg_catalog  pg_extension                     table  node  NULL  NULL
pg_catalog  pg_file_settings                 table  node  NULL  NULL
pg_catalog  pg_foreign_data_wrapper          table  node  NULL  NULL
pg_catalog  pg_foreign_server                table  node  NULL  NULL
pg_catalog  pg_foreign_table                 table  node  NULL  NULL
pg_catalog  pg_group                         table  node  NULL  NULL
pg_catalog  pg_hba_file_rules                table  node  NULL  NULL
pg_catalog  pg_index                         table  node  NULL  NULL
pg_catalog  pg_indexes                       table  node  NULL  NULL
pg_catalog  pg_inherits                      table  node  NULL  NULL
pg_catalog  pg_init_privs                    table  node  NULL  NULL
pg_catalog  pg_language                      table  node  NULL  NULL
pg_catalog  pg_largeobject                   table  node  NULL  NULL
pg_catalog  pg_largeobject_metadata          table  node  NULL  NULL
pg_catalog  pg_locks                         table  node  NULL  NULL
pg_catalog  pg_matviews                      table  node  NULL  NULL
pg_catalog  pg_namespace                     table  node  NULL  NULL
pg_catalog  pg_opclass                       table  node  NULL  NULL
pg_catalog  pg_operator                      table  node  NULL  NULL
pg_catalog  pg_opfamily                      table  node  NULL  NULL
pg_catalog  pg_partitioned_table             table  node  NULL  NULL
pg_catalog  pg_policies                      table  node  NULL  NULL
pg_catalog  pg_policy                        table  node  NULL  NULL
pg_catalog  pg_prepared_statements           table  node  NULL  NULL
pg_catalog  pg_prepared_xacts                table  node  NULL  NULL
pg_catalog  pg_proc                          table  node  NULL  NULL
pg_catalog  pg_publication                   table  node  NULL  NULL
pg_catalog  pg_publication_rel               table  node  NULL  NULL
pg_catalog  pg_publication_tables            table  node  NULL  NULL
pg_catalog  pg_range                         table  node  NULL  NULL
pg_catalog  pg_replication_origin            table  node  NULL  NULL
pg_catalog  pg_replication_origin_status     table  node  NULL  NULL
pg_catalog  pg_replication_slots             table  node  NULL  NULL
pg_catalog  pg_rewrite                       table  node  NULL  NULL
pg_catalog  pg_roles                         table  node  NULL  NULL
pg_catalog  pg_rules                         table  node  NULL  NULL
pg_catalog  pg_seclabel                      table  node  NULL  NULL
pg_catalog  pg_seclabels                     table  node  NULL  NULL
pg_catalog  pg_sequence                      table  node  NULL  NULL
pg_catalog  pg_sequences                     table  node  NULL  NULL
pg_catalog  pg_settings                      table  node  NULL  NULL
pg_catalog  pg_shadow                        table  node  NULL  NULL
pg_catalog  pg_shdepend                      table  node  NULL  NULL
pg_catalog  pg_shdescription                 view   node  NULL  NULL
pg_catalog  pg_shmem_allocations             table  node  NULL  NULL
pg_catalog  pg_shseclabel                    table  node  NULL  NULL
pg_catalog  pg_stat_activity                 table  node  NULL  NULL
pg_catalog  pg_stat_all_indexes              table  node  NULL  NULL
pg_catalog  pg_stat_all_tables               table  node  NULL  NULL
pg_catalog  pg_stat_archiver                 table  node  NULL  NULL
pg_catalog  pg_stat_bgwriter                 table  node  NULL  NULL
pg_catalog  pg_stat_database                 table  node  NULL  NULL
pg_catalog  pg_stat_database_conflicts       table  node  NULL  NULL
pg_catalog  pg_stat_gssapi                   table  node  NULL  NULL
pg_catalog  pg_stat_progress_analyze         table  node  NULL  NULL
pg_catalog  pg_stat_progress_basebackup      table  node  NULL  NULL
pg_catalog  pg_stat_progress_cluster         table  node  NULL  NULL
pg_catalog  pg_stat_progress_create_index    table  node  NULL  NULL
pg_catalog  pg_stat_progress_vacuum          table  node  NULL  NULL
pg_catalog  pg_stat_replication              table  node  NULL  NULL
pg_catalog  pg_stat_slru                     table  node  NULL  NULL
pg_catalog  pg_stat_ssl                      table  node  NULL  NULL
pg_catalog  pg_stat_subscription             table  node  NULL  NULL
pg_catalog  pg_stat_sys_indexes              table  node  NULL  NULL
pg_catalog  pg_stat_sys_tables               table  node  NULL  NULL
pg_catalog  pg_stat_user_functions           table  node  NULL  NULL
pg_catalog  pg_stat_user_indexes             table  node  NULL  NULL
pg_catalog  pg_stat_user_tables              table  node  NULL  NULL
pg_catalog  pg_stat_wal_receiver             table  node  NULL  NULL
pg_catalog  pg_stat_xact_all_tables          table  node  NULL  NULL
pg_catalog  pg_stat_xact_sys_tables          table  node  NULL  NULL
pg_catalog  pg_stat_xact_user_functions      table  node  NULL  NULL
pg_catalog  pg_stat_xact_user_tables         table  node  NULL  NULL
pg_catalog  pg_statio_all_indexes            table  node  NULL  NULL
pg_catalog  pg_statio_all_sequences          table  node  NULL  NULL
pg_catalog  pg_statio_all_tables             table  node  NULL  NULL
pg_catalog  pg_statio_sys_indexes            table  node  NULL  NULL
pg_catalog  pg_statio_sys_sequences          table  node  NULL  NULL
pg_catalog  pg_statio_sys_tables             table  node  NULL  NULL
pg_catalog  pg_statio_user_indexes           table  node  NULL  NULL
pg_catalog  pg_statio_user_sequences         table  node  NULL  NULL
pg_catalog  pg_statio_user_tables            table  node  NULL  NULL
pg_catalog  pg_statistic                     table  node  NULL  NULL
pg_catalog  pg_statistic_ext                 table  node  NULL  NULL
pg_catalog  pg_statistic_ext_data            table  node  NULL  NULL
pg_catalog  pg_stats                         table  node  NULL  NULL
pg_catalog  pg_stats_ext                     table  node  NULL  NULL
pg_catalog  pg_subscription                  table  node  NULL  NULL
pg_catalog  pg_subscription_rel              table  node  NULL  NULL
pg_catalog  pg_tables                        table  node  NULL  NULL
pg_catalog  pg_tablespace                    table  node  NULL  NULL
pg_catalog  pg_timezone_abbrevs              table  node  NULL  NULL
pg_catalog  pg_timezone_names                table  node  NULL  NULL
pg_catalog  pg_transform                     table  node  NULL  NULL
pg_catalog  pg_trigger                       table  node  NULL  NULL
pg_catalog  pg_ts_config                     table  node  NULL  NULL
pg_catalog  pg_ts_config_map                 table  node  NULL  NULL
pg_catalog  pg_ts_dict                       table  node  NULL  NULL
pg_catalog  pg_ts_parser                     table  node  NULL  NULL
pg_catalog  pg_ts_template                   table  node  NULL  NULL
pg_catalog  pg_type                          table  node  NULL  NULL
pg_catalog  pg_user                          table  node  NULL  NULL
pg_catalog  pg_user_mapping                  table  node  NULL  NULL
pg_catalog  pg_user_mappings                 table  node  NULL  NULL
pg_catalog  pg_views                         table  node  NULL  NULL

# Verify "pg_catalog" is a regular db name

statement ok
CREATE DATABASE other_db

statement ok
ALTER DATABASE other_db RENAME TO pg_catalog

statement error database "pg_catalog" already exists
CREATE DATABASE pg_catalog

statement ok
DROP DATABASE pg_catalog

# the following query checks that the planDataSource instantiated from
# a virtual table in the FROM clause is properly deallocated even when
# query preparation causes an error. #9853
query error unknown function
SELECT * FROM pg_catalog.pg_class c WHERE nonexistent_function()

# Verify pg_catalog handles reflection correctly.

query TTTTIT rowsort
SHOW TABLES FROM test.pg_catalog
----
pg_catalog  pg_aggregate                     table  node  NULL  NULL
pg_catalog  pg_am                            table  node  NULL  NULL
pg_catalog  pg_amop                          table  node  NULL  NULL
pg_catalog  pg_amproc                        table  node  NULL  NULL
pg_catalog  pg_attrdef                       table  node  NULL  NULL
pg_catalog  pg_attribute                     table  node  NULL  NULL
pg_catalog  pg_auth_members                  table  node  NULL  NULL
pg_catalog  pg_authid                        table  node  NULL  NULL
pg_catalog  pg_available_extension_versions  table  node  NULL  NULL
pg_catalog  pg_available_extensions          table  node  NULL  NULL
pg_catalog  pg_cast                          table  node  NULL  NULL
pg_catalog  pg_class                         table  node  NULL  NULL
pg_catalog  pg_collation                     table  node  NULL  NULL
pg_catalog  pg_config                        table  node  NULL  NULL
pg_catalog  pg_constraint                    table  node  NULL  NULL
pg_catalog  pg_conversion                    table  node  NULL  NULL
pg_catalog  pg_cursors                       table  node  NULL  NULL
pg_catalog  pg_database                      table  node  NULL  NULL
pg_catalog  pg_db_role_setting               table  node  NULL  NULL
pg_catalog  pg_default_acl                   table  node  NULL  NULL
pg_catalog  pg_depend                        table  node  NULL  NULL
pg_catalog  pg_description                   view   node  NULL  NULL
pg_catalog  pg_enum                          table  node  NULL  NULL
pg_catalog  pg_event_trigger                 table  node  NULL  NULL
pg_catalog  pg_extension                     table  node  NULL  NULL
pg_catalog  pg_file_settings                 table  node  NULL  NULL
pg_catalog  pg_foreign_data_wrapper          table  node  NULL  NULL
pg_catalog  pg_foreign_server                table  node  NULL  NULL
pg_catalog  pg_foreign_table                 table  node  NULL  NULL
pg_catalog  pg_group                         table  node  NULL  NULL
pg_catalog  pg_hba_file_rules                table  node  NULL  NULL
pg_catalog  pg_index                         table  node  NULL  NULL
pg_catalog  pg_indexes                       table  node  NULL  NULL
pg_catalog  pg_inherits                      table  node  NULL  NULL
pg_catalog  pg_init_privs                    table  node  NULL  NULL
pg_catalog  pg_language                      table  node  NULL  NULL
pg_catalog  pg_largeobject                   table  node  NULL  NULL
pg_catalog  pg_largeobject_metadata          table  node  NULL  NULL
pg_catalog  pg_locks                         table  node  NULL  NULL
pg_catalog  pg_matviews                      table  node  NULL  NULL
pg_catalog  pg_namespace                     table  node  NULL  NULL
pg_catalog  pg_opclass                       table  node  NULL  NULL
pg_catalog  pg_operator                      table  node  NULL  NULL
pg_catalog  pg_opfamily                      table  node  NULL  NULL
pg_catalog  pg_partitioned_table             table  node  NULL  NULL
pg_catalog  pg_policies                      table  node  NULL  NULL
pg_catalog  pg_policy                        table  node  NULL  NULL
pg_catalog  pg_prepared_statements           table  node  NULL  NULL
pg_catalog  pg_prepared_xacts                table  node  NULL  NULL
pg_catalog  pg_proc                          table  node  NULL  NULL
pg_catalog  pg_publication                   table  node  NULL  NULL
pg_catalog  pg_publication_rel               table  node  NULL  NULL
pg_catalog  pg_publication_tables            table  node  NULL  NULL
pg_catalog  pg_range                         table  node  NULL  NULL
pg_catalog  pg_replication_origin            table  node  NULL  NULL
pg_catalog  pg_replication_origin_status     table  node  NULL  NULL
pg_catalog  pg_replication_slots             table  node  NULL  NULL
pg_catalog  pg_rewrite                       table  node  NULL  NULL
pg_catalog  pg_roles                         table  node  NULL  NULL
pg_catalog  pg_rules                         table  node  NULL  NULL
pg_catalog  pg_seclabel                      table  node  NULL  NULL
pg_catalog  pg_seclabels                     table  node  NULL  NULL
pg_catalog  pg_sequence                      table  node  NULL  NULL
pg_catalog  pg_sequences                     table  node  NULL  NULL
pg_catalog  pg_settings                      table  node  NULL  NULL
pg_catalog  pg_shadow                        table  node  NULL  NULL
pg_catalog  pg_shdepend                      table  node  NULL  NULL
pg_catalog  pg_shdescription                 view   node  NULL  NULL
pg_catalog  pg_shmem_allocations             table  node  NULL  NULL
pg_catalog  pg_shseclabel                    table  node  NULL  NULL
pg_catalog  pg_stat_activity                 table  node  NULL  NULL
pg_catalog  pg_stat_all_indexes              table  node  NULL  NULL
pg_catalog  pg_stat_all_tables               table  node  NULL  NULL
pg_catalog  pg_stat_archiver                 table  node  NULL  NULL
pg_catalog  pg_stat_bgwriter                 table  node  NULL  NULL
pg_catalog  pg_stat_database                 table  node  NULL  NULL
pg_catalog  pg_stat_database_conflicts       table  node  NULL  NULL
pg_catalog  pg_stat_gssapi                   table  node  NULL  NULL
pg_catalog  pg_stat_progress_analyze         table  node  NULL  NULL
pg_catalog  pg_stat_progress_basebackup      table  node  NULL  NULL
pg_catalog  pg_stat_progress_cluster         table  node  NULL  NULL
pg_catalog  pg_stat_progress_create_index    table  node  NULL  NULL
pg_catalog  pg_stat_progress_vacuum          table  node  NULL  NULL
pg_catalog  pg_stat_replication              table  node  NULL  NULL
pg_catalog  pg_stat_slru                     table  node  NULL  NULL
pg_catalog  pg_stat_ssl                      table  node  NULL  NULL
pg_catalog  pg_stat_subscription             table  node  NULL  NULL
pg_catalog  pg_stat_sys_indexes              table  node  NULL  NULL
pg_catalog  pg_stat_sys_tables               table  node  NULL  NULL
pg_catalog  pg_stat_user_functions           table  node  NULL  NULL
pg_catalog  pg_stat_user_indexes             table  node  NULL  NULL
pg_catalog  pg_stat_user_tables              table  node  NULL  NULL
pg_catalog  pg_stat_wal_receiver             table  node  NULL  NULL
pg_catalog  pg_stat_xact_all_tables          table  node  NULL  NULL
pg_catalog  pg_stat_xact_sys_tables          table  node  NULL  NULL
pg_catalog  pg_stat_xact_user_functions      table  node  NULL  NULL
pg_catalog  pg_stat_xact_user_tables         table  node  NULL  NULL
pg_catalog  pg_statio_all_indexes            table  node  NULL  NULL
pg_catalog  pg_statio_all_sequences          table  node  NULL  NULL
pg_catalog  pg_statio_all_tables             table  node  NULL  NULL
pg_catalog  pg_statio_sys_indexes            table  node  NULL  NULL
pg_catalog  pg_statio_sys_sequences          table  node  NULL  NULL
pg_catalog  pg_statio_sys_tables             table  node  NULL  NULL
pg_catalog  pg_statio_user_indexes           table  node  NULL  NULL
pg_catalog  pg_statio_user_sequences         table  node  NULL  NULL
pg_catalog  pg_statio_user_tables            table  node  NULL  NULL
pg_catalog  pg_statistic                     table  node  NULL  NULL
pg_catalog  pg_statistic_ext                 table  node  NULL  NULL
pg_catalog  pg_statistic_ext_data            table  node  NULL  NULL
pg_catalog  pg_stats                         table  node  NULL  NULL
pg_catalog  pg_stats_ext                     table  node  NULL  NULL
pg_catalog  pg_subscription                  table  node  NULL  NULL
pg_catalog  pg_subscription_rel              table  node  NULL  NULL
pg_catalog  pg_tables                        table  node  NULL  NULL
pg_catalog  pg_tablespace                    table  node  NULL  NULL
pg_catalog  pg_timezone_abbrevs              table  node  NULL  NULL
pg_catalog  pg_timezone_names                table  node  NULL  NULL
pg_catalog  pg_transform                     table  node  NULL  NULL
pg_catalog  pg_trigger                       table  node  NULL  NULL
pg_catalog  pg_ts_config                     table  node  NULL  NULL
pg_catalog  pg_ts_config_map                 table  node  NULL  NULL
pg_catalog  pg_ts_dict                       table  node  NULL  NULL
pg_catalog  pg_ts_parser                     table  node  NULL  NULL
pg_catalog  pg_ts_template                   table  node  NULL  NULL
pg_catalog  pg_type                          table  node  NULL  NULL
pg_catalog  pg_user                          table  node  NULL  NULL
pg_catalog  pg_user_mapping                  table  node  NULL  NULL
pg_catalog  pg_user_mappings                 table  node  NULL  NULL
pg_catalog  pg_views                         table  node  NULL  NULL

query TT colnames
SHOW CREATE TABLE pg_catalog.pg_namespace
----
table_name               create_statement
pg_catalog.pg_namespace  CREATE TABLE pg_catalog.pg_namespace (
                           oid OID NULL,
                           nspname NAME NOT NULL,
                           nspowner OID NULL,
                           nspacl STRING[] NULL,
                           INDEX pg_namespace_oid_idx (oid ASC) STORING (nspname, nspowner, nspacl)
                         )

query TTBTTTB colnames,rowsort
SHOW COLUMNS FROM pg_catalog.pg_namespace
----
column_name  data_type  is_nullable  column_default  generation_expression  indices  is_hidden
oid          OID        true         NULL            ·                      {}       false
nspname      NAME       false        NULL            ·                      {}       false
nspowner     OID        true         NULL            ·                      {}       false
nspacl       STRING[]   true         NULL            ·                      {}       false

query TTBITTTBBBF colnames
SHOW INDEXES FROM pg_catalog.pg_namespace
----
table_name  index_name  non_unique  seq_in_index  column_name  definition  direction  storing  implicit  visible  visibility

query TTTTB colnames
SHOW CONSTRAINTS FROM pg_catalog.pg_namespace
----
table_name  constraint_name  constraint_type  details  validated

query TTTTTB colnames
SHOW GRANTS ON pg_catalog.pg_namespace
----
database_name  schema_name  table_name    grantee  privilege_type  is_grantable
test           pg_catalog   pg_namespace  public   SELECT          false


# Verify selecting from pg_catalog.

statement ok
CREATE DATABASE constraint_db

statement ok
CREATE TABLE constraint_db.t1 (
  p FLOAT PRIMARY KEY,
  a INT UNIQUE,
  b INT,
  c INT DEFAULT 12,
  d VARCHAR(5),
  e BIT(5),
  f DECIMAL(10,7),
  g INT AS (a * b) STORED,
  h CHAR(12)[],
  i VARCHAR(20)[],
  j "char",
  k VARCHAR(10) COLLATE sv,
  l INT AS (a * b) VIRTUAL,
  m INT GENERATED ALWAYS AS IDENTITY,
  n INT GENERATED BY DEFAULT AS IDENTITY,
  UNIQUE INDEX index_key(b, c)
)

statement ok
CREATE TABLE constraint_db.t2 (
    t1_ID INT,
    CONSTRAINT fk FOREIGN KEY (t1_ID) REFERENCES constraint_db.t1(a),
    INDEX (t1_ID)
)

statement ok
CREATE TABLE constraint_db.t3 (
    a INT,
    b INT CHECK (b > 11),
    c STRING DEFAULT 'FOO' CHECK (c != ''),
    CONSTRAINT fk FOREIGN KEY (a, b) REFERENCES constraint_db.t1(b, c),
    INDEX (a, b DESC) STORING (c)
)

statement ok
CREATE VIEW constraint_db.v1 AS SELECT p,a,b,c FROM constraint_db.t1

statement ok
SET experimental_enable_unique_without_index_constraints = true

statement ok
CREATE TABLE constraint_db.t4 (
    a INT UNIQUE WITHOUT INDEX,
    b FLOAT,
    c STRING,
    CONSTRAINT uwi_b_c UNIQUE WITHOUT INDEX (b, c),
    CONSTRAINT uwi_b_partial UNIQUE WITHOUT INDEX (b) WHERE c = 'foo'
)

statement ok
CREATE TABLE constraint_db.t5 (
    a INT REFERENCES constraint_db.t4(a) ON DELETE CASCADE,
    b FLOAT,
    c STRING,
    CONSTRAINT fk_b_c FOREIGN KEY (b, c) REFERENCES constraint_db.t4(b, c) MATCH FULL ON UPDATE RESTRICT
)

statement ok
CREATE TYPE constraint_db.mytype AS ENUM ('foo', 'bar', 'baz')

statement ok
CREATE TABLE constraint_db.t6 (
  a INT,
  b INT,
  c STRING,
  m constraint_db.mytype,
  INDEX ((a + b))
);
CREATE INDEX ON constraint_db.t6 (lower(c), (a + b));
CREATE UNIQUE INDEX ON constraint_db.t6 (lower(c));
CREATE INDEX ON constraint_db.t6 ((m = 'foo')) WHERE m = 'foo'

## pg_catalog.pg_namespace

query OTOT colnames,rowsort
SELECT * FROM pg_catalog.pg_namespace
----
oid         nspname             nspowner    nspacl
4294967295  crdb_internal       3233629770  NULL
4294967182  information_schema  3233629770  NULL
4294967095  pg_catalog          3233629770  NULL
4294966965  pg_extension        3233629770  NULL
105         public              1546506610  NULL

# Verify that we can still see the schemas even if we don't have any privilege
# on the current database.

statement ok
REVOKE ALL ON DATABASE test FROM public;
REVOKE ALL ON DATABASE test FROM testuser

user testuser

query OTOT colnames,rowsort
SELECT * FROM pg_catalog.pg_namespace
----
oid         nspname             nspowner    nspacl
4294967295  crdb_internal       3233629770  NULL
4294967182  information_schema  3233629770  NULL
4294967095  pg_catalog          3233629770  NULL
4294966965  pg_extension        3233629770  NULL
105         public              1546506610  NULL

user root

statement ok
GRANT CONNECT ON DATABASE test TO public

## pg_catalog.pg_database

query OTOITTBB colnames
SELECT oid, datname, datdba, encoding, datcollate, datctype, datistemplate, datallowconn
FROM pg_catalog.pg_database
ORDER BY oid
----
oid  datname        datdba      encoding  datcollate  datctype    datistemplate  datallowconn
1    system         3233629770  6         en_US.utf8  en_US.utf8  false          true
100  defaultdb      1546506610  6         en_US.utf8  en_US.utf8  false          true
102  postgres       1546506610  6         en_US.utf8  en_US.utf8  false          true
104  test           1546506610  6         en_US.utf8  en_US.utf8  false          true
108  constraint_db  1546506610  6         en_US.utf8  en_US.utf8  false          true

query OTIOIIOT colnames
SELECT oid, datname, datconnlimit, datlastsysoid, datfrozenxid, datminmxid, dattablespace, datacl
FROM pg_catalog.pg_database
ORDER BY oid
----
oid  datname        datconnlimit  datlastsysoid  datfrozenxid  datminmxid  dattablespace  datacl
1    system         -1            0              NULL          NULL        0              NULL
100  defaultdb      -1            0              NULL          NULL        0              NULL
102  postgres       -1            0              NULL          NULL        0              NULL
104  test           -1            0              NULL          NULL        0              NULL
108  constraint_db  -1            0              NULL          NULL        0              NULL

user testuser

# Should be globally visible
query OTIOIIOT colnames
SELECT oid, datname, datconnlimit, datlastsysoid, datfrozenxid, datminmxid, dattablespace, datacl
FROM pg_catalog.pg_database
ORDER BY oid LIMIT 1
----
oid  datname        datconnlimit  datlastsysoid  datfrozenxid  datminmxid  dattablespace  datacl
1    system         -1            0              NULL          NULL        0              NULL

user root

## pg_catalog.pg_tables

statement ok
SET DATABASE = constraint_db

query TTTTBBBB colnames,rowsort
SELECT * FROM constraint_db.pg_catalog.pg_tables WHERE schemaname = 'public'
----
schemaname  tablename  tableowner  tablespace  hasindexes  hasrules  hastriggers  rowsecurity
public      t1         root        NULL        true        false     false        false
public      t2         root        NULL        true        false     false        false
public      t3         root        NULL        true        false     false        false
public      t4         root        NULL        true        false     false        false
public      t5         root        NULL        true        false     false        false
public      t6         root        NULL        true        false     false        false

query TB colnames,rowsort
SELECT tablename, hasindexes FROM pg_catalog.pg_tables WHERE schemaname = 'information_schema' AND tablename LIKE '%table%'
----
tablename                     hasindexes
constraint_table_usage        false
foreign_table_options         false
foreign_tables                false
role_table_grants             false
table_constraints             false
table_constraints_extensions  false
table_privileges              false
tables                        false
tables_extensions             false
tablespaces                   false
tablespaces_extensions        false
view_table_usage              false

## pg_catalog.pg_tablespace

query OTOTT colnames
SELECT oid, spcname, spcowner, spcacl, spcoptions FROM pg_tablespace
----
oid  spcname     spcowner  spcacl  spcoptions
0    pg_default  NULL      NULL    NULL

## pg_catalog.pg_views

query TTTT colnames
SELECT * FROM pg_catalog.pg_views
----
schemaname  viewname  viewowner  definition
public      v1        root       SELECT p, a, b, c FROM constraint_db.public.t1

## pg_catalog.pg_matviews

statement ok
CREATE MATERIALIZED VIEW mv1 AS SELECT 1

query TTTTBBT colnames
SELECT * FROM pg_catalog.pg_matviews
----
schemaname  matviewname  matviewowner  tablespace  hasindexes  ispopulated  definition
public      mv1          root          NULL        false       true         SELECT 1

## pg_catalog.pg_class

query OTOOOOOOO colnames,rowsort
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  reloftype  relowner    relam       relfilenode  reltablespace
110         t1                 109           100110   0          1546506610  2631952481  0            0
3687884466  t1_pkey            109           0        0          1546506610  2631952481  0            0
3687884465  t1_a_key           109           0        0          1546506610  2631952481  0            0
3687884464  index_key          109           0        0          1546506610  2631952481  0            0
111         t1_m_seq           109           100111   0          1546506610  0           0            0
112         t1_n_seq           109           100112   0          1546506610  0           0            0
113         t2                 109           100113   0          1546506610  2631952481  0            0
2955071325  t2_pkey            109           0        0          1546506610  2631952481  0            0
2955071326  t2_t1_id_idx       109           0        0          1546506610  2631952481  0            0
114         t3                 109           100114   0          1546506610  2631952481  0            0
2695335054  t3_pkey            109           0        0          1546506610  2631952481  0            0
2695335053  t3_a_b_idx         109           0        0          1546506610  2631952481  0            0
115         v1                 109           100115   0          1546506610  0           0            0
116         t4                 109           100116   0          1546506610  2631952481  0            0
3214807592  t4_pkey            109           0        0          1546506610  2631952481  0            0
117         t5                 109           100117   0          1546506610  2631952481  0            0
1869730585  t5_pkey            109           0        0          1546506610  2631952481  0            0
120         t6                 109           100120   0          1546506610  2631952481  0            0
2129466852  t6_pkey            109           0        0          1546506610  2631952481  0            0
2129466855  t6_expr_idx        109           0        0          1546506610  2631952481  0            0
2129466854  t6_expr_expr1_idx  109           0        0          1546506610  2631952481  0            0
2129466848  t6_expr_key        109           0        0          1546506610  2631952481  0            0
2129466850  t6_expr_idx1       109           0        0          1546506610  2631952481  0            0
121         mv1                109           100121   0          1546506610  0           0            0
784389845   mv1_pkey           109           0        0          1546506610  2631952481  0            0

query TIRIOBBT colnames,rowsort
SELECT relname, relpages, reltuples, relallvisible, reltoastrelid, relhasindex, relisshared, relpersistence
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname            relpages  reltuples  relallvisible  reltoastrelid  relhasindex  relisshared  relpersistence
t1                 NULL      NULL       0              0              true         false        p
t1_pkey            NULL      NULL       0              0              false        false        p
t1_a_key           NULL      NULL       0              0              false        false        p
index_key          NULL      NULL       0              0              false        false        p
t1_m_seq           NULL      NULL       0              0              true         false        p
t1_n_seq           NULL      NULL       0              0              true         false        p
t2                 NULL      NULL       0              0              true         false        p
t2_pkey            NULL      NULL       0              0              false        false        p
t2_t1_id_idx       NULL      NULL       0              0              false        false        p
t3                 NULL      NULL       0              0              true         false        p
t3_pkey            NULL      NULL       0              0              false        false        p
t3_a_b_idx         NULL      NULL       0              0              false        false        p
v1                 NULL      NULL       0              0              false        false        p
t4                 NULL      NULL       0              0              true         false        p
t4_pkey            NULL      NULL       0              0              false        false        p
t5                 NULL      NULL       0              0              true         false        p
t5_pkey            NULL      NULL       0              0              false        false        p
t6                 NULL      NULL       0              0              true         false        p
t6_pkey            NULL      NULL       0              0              false        false        p
t6_expr_idx        NULL      NULL       0              0              false        false        p
t6_expr_expr1_idx  NULL      NULL       0              0              false        false        p
t6_expr_key        NULL      NULL       0              0              false        false        p
t6_expr_idx1       NULL      NULL       0              0              false        false        p
mv1                NULL      NULL       0              0              true         false        p
mv1_pkey           NULL      NULL       0              0              false        false        p

query TBTIIBB colnames,rowsort
SELECT relname, relistemp, relkind, relnatts, relchecks, relhasoids, relhaspkey
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname            relistemp  relkind  relnatts  relchecks  relhasoids  relhaspkey
t1                 false      r        15        0          false       true
t1_pkey            false      i        1         0          false       false
t1_a_key           false      i        1         0          false       false
index_key          false      i        2         0          false       false
t1_m_seq           false      S        1         0          false       true
t1_n_seq           false      S        1         0          false       true
t2                 false      r        2         0          false       true
t2_pkey            false      i        1         0          false       false
t2_t1_id_idx       false      i        1         0          false       false
t3                 false      r        4         2          false       true
t3_pkey            false      i        1         0          false       false
t3_a_b_idx         false      i        2         0          false       false
v1                 false      v        4         0          false       false
t4                 false      r        4         0          false       true
t4_pkey            false      i        1         0          false       false
t5                 false      r        4         0          false       true
t5_pkey            false      i        1         0          false       false
t6                 false      r        5         0          false       true
t6_pkey            false      i        1         0          false       false
t6_expr_idx        false      i        1         0          false       false
t6_expr_expr1_idx  false      i        2         0          false       false
t6_expr_key        false      i        1         0          false       false
t6_expr_idx1       false      i        1         0          false       false
mv1                false      m        2         0          false       true
mv1_pkey           false      i        1         0          false       false

query TBBBITTT colnames,rowsort
SELECT relname, relhasrules, relhastriggers, relhassubclass, relfrozenxid, relacl, reloptions, relreplident
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname            relhasrules  relhastriggers  relhassubclass  relfrozenxid  relacl  reloptions  relreplident
t1                 false        false           false           0             NULL    NULL        d
t1_pkey            false        false           false           0             NULL    NULL        n
t1_a_key           false        false           false           0             NULL    NULL        n
index_key          false        false           false           0             NULL    NULL        n
t1_m_seq           false        false           false           0             NULL    NULL        n
t1_n_seq           false        false           false           0             NULL    NULL        n
t2                 false        false           false           0             NULL    NULL        d
t2_pkey            false        false           false           0             NULL    NULL        n
t2_t1_id_idx       false        false           false           0             NULL    NULL        n
t3                 false        false           false           0             NULL    NULL        d
t3_pkey            false        false           false           0             NULL    NULL        n
t3_a_b_idx         false        false           false           0             NULL    NULL        n
v1                 false        false           false           0             NULL    NULL        n
t4                 false        false           false           0             NULL    NULL        d
t4_pkey            false        false           false           0             NULL    NULL        n
t5                 false        false           false           0             NULL    NULL        d
t5_pkey            false        false           false           0             NULL    NULL        n
t6                 false        false           false           0             NULL    NULL        d
t6_pkey            false        false           false           0             NULL    NULL        n
t6_expr_idx        false        false           false           0             NULL    NULL        n
t6_expr_expr1_idx  false        false           false           0             NULL    NULL        n
t6_expr_key        false        false           false           0             NULL    NULL        n
t6_expr_idx1       false        false           false           0             NULL    NULL        n
mv1                false        false           false           0             NULL    NULL        d
mv1_pkey           false        false           false           0             NULL    NULL        n

## pg_catalog.pg_attribute

query OTTOIIIII colnames,rowsort
SELECT attrelid, c.relname, attname, atttypid, attstattarget, attlen, attnum, attndims, attcacheoff
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
attrelid    relname            attname                       atttypid  attstattarget  attlen  attnum  attndims  attcacheoff
110         t1                 p                             701       0              8       1       0         -1
110         t1                 a                             20        0              8       2       0         -1
110         t1                 b                             20        0              8       3       0         -1
110         t1                 c                             20        0              8       4       0         -1
110         t1                 d                             1043      0              -1      5       0         -1
110         t1                 e                             1560      0              -1      6       0         -1
110         t1                 f                             1700      0              -1      7       0         -1
110         t1                 g                             20        0              8       8       0         -1
110         t1                 h                             1014      0              -1      9       0         -1
110         t1                 i                             1015      0              -1      10      0         -1
110         t1                 j                             18        0              1       11      0         -1
110         t1                 k                             1043      0              -1      12      0         -1
110         t1                 l                             20        0              8       13      0         -1
110         t1                 m                             20        0              8       14      0         -1
110         t1                 n                             20        0              8       15      0         -1
3687884466  t1_pkey            p                             701       0              8       1       0         -1
3687884465  t1_a_key           a                             20        0              8       1       0         -1
3687884464  index_key          b                             20        0              8       1       0         -1
3687884464  index_key          c                             20        0              8       2       0         -1
111         t1_m_seq           value                         20        0              8       1       0         -1
112         t1_n_seq           value                         20        0              8       1       0         -1
113         t2                 t1_id                         20        0              8       1       0         -1
113         t2                 rowid                         20        0              8       2       0         -1
2955071325  t2_pkey            rowid                         20        0              8       1       0         -1
2955071326  t2_t1_id_idx       t1_id                         20        0              8       1       0         -1
114         t3                 a                             20        0              8       1       0         -1
114         t3                 b                             20        0              8       2       0         -1
114         t3                 c                             25        0              -1      3       0         -1
114         t3                 rowid                         20        0              8       4       0         -1
2695335054  t3_pkey            rowid                         20        0              8       1       0         -1
2695335053  t3_a_b_idx         a                             20        0              8       1       0         -1
2695335053  t3_a_b_idx         b                             20        0              8       2       0         -1
2695335053  t3_a_b_idx         c                             25        0              -1      3       0         -1
115         v1                 p                             701       0              8       1       0         -1
115         v1                 a                             20        0              8       2       0         -1
115         v1                 b                             20        0              8       3       0         -1
115         v1                 c                             20        0              8       4       0         -1
116         t4                 a                             20        0              8       1       0         -1
116         t4                 b                             701       0              8       2       0         -1
116         t4                 c                             25        0              -1      3       0         -1
116         t4                 rowid                         20        0              8       4       0         -1
3214807592  t4_pkey            rowid                         20        0              8       1       0         -1
117         t5                 a                             20        0              8       1       0         -1
117         t5                 b                             701       0              8       2       0         -1
117         t5                 c                             25        0              -1      3       0         -1
117         t5                 rowid                         20        0              8       4       0         -1
1869730585  t5_pkey            rowid                         20        0              8       1       0         -1
120         t6                 a                             20        0              8       1       0         -1
120         t6                 b                             20        0              8       2       0         -1
120         t6                 c                             25        0              -1      3       0         -1
120         t6                 m                             100118    0              -1      4       0         -1
120         t6                 rowid                         20        0              8       6       0         -1
120         t6                 ........pg.dropped.5........  2283      0              -1      5       0         -1
120         t6                 ........pg.dropped.7........  2283      0              -1      7       0         -1
120         t6                 ........pg.dropped.8........  2283      0              -1      8       0         -1
2129466852  t6_pkey            rowid                         20        0              8       1       0         -1
2129466855  t6_expr_idx        crdb_internal_idx_expr        20        0              8       1       0         -1
2129466854  t6_expr_expr1_idx  crdb_internal_idx_expr_1      25        0              -1      1       0         -1
2129466854  t6_expr_expr1_idx  crdb_internal_idx_expr        20        0              8       2       0         -1
2129466848  t6_expr_key        crdb_internal_idx_expr_1      25        0              -1      1       0         -1
2129466850  t6_expr_idx1       crdb_internal_idx_expr_2      16        0              1       1       0         -1
121         mv1                ?column?                      20        0              8       1       0         -1
121         mv1                rowid                         20        0              8       2       0         -1
784389845   mv1_pkey           rowid                         20        0              8       1       0         -1

query TTIBTTBBTT colnames,rowsort
SELECT c.relname, attname, atttypmod, attbyval, attstorage, attalign, attnotnull, atthasdef, attidentity, attgenerated
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname            attname                       atttypmod  attbyval  attstorage  attalign  attnotnull  atthasdef  attidentity  attgenerated
t1                 p                             -1         NULL      NULL        NULL      true        false      ·            ·
t1                 a                             -1         NULL      NULL        NULL      false       false      ·            ·
t1                 b                             -1         NULL      NULL        NULL      false       false      ·            ·
t1                 c                             -1         NULL      NULL        NULL      false       true       ·            ·
t1                 d                             9          NULL      NULL        NULL      false       false      ·            ·
t1                 e                             5          NULL      NULL        NULL      false       false      ·            ·
t1                 f                             655371     NULL      NULL        NULL      false       false      ·            ·
t1                 g                             -1         NULL      NULL        NULL      false       true       ·            s
t1                 h                             16         NULL      NULL        NULL      false       false      ·            ·
t1                 i                             24         NULL      NULL        NULL      false       false      ·            ·
t1                 j                             -1         NULL      NULL        NULL      false       false      ·            ·
t1                 k                             14         NULL      NULL        NULL      false       false      ·            ·
t1                 l                             -1         NULL      NULL        NULL      false       true       ·            v
t1                 m                             -1         NULL      NULL        NULL      true        true       a            ·
t1                 n                             -1         NULL      NULL        NULL      true        true       d            ·
t1_pkey            p                             -1         NULL      NULL        NULL      true        false      ·            ·
t1_a_key           a                             -1         NULL      NULL        NULL      false       false      ·            ·
index_key          b                             -1         NULL      NULL        NULL      false       false      ·            ·
index_key          c                             -1         NULL      NULL        NULL      false       true       ·            ·
t1_m_seq           value                         -1         NULL      NULL        NULL      true        false      ·            ·
t1_n_seq           value                         -1         NULL      NULL        NULL      true        false      ·            ·
t2                 t1_id                         -1         NULL      NULL        NULL      false       false      ·            ·
t2                 rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t2_pkey            rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t2_t1_id_idx       t1_id                         -1         NULL      NULL        NULL      false       false      ·            ·
t3                 a                             -1         NULL      NULL        NULL      false       false      ·            ·
t3                 b                             -1         NULL      NULL        NULL      false       false      ·            ·
t3                 c                             -1         NULL      NULL        NULL      false       true       ·            ·
t3                 rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t3_pkey            rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t3_a_b_idx         a                             -1         NULL      NULL        NULL      false       false      ·            ·
t3_a_b_idx         b                             -1         NULL      NULL        NULL      false       false      ·            ·
t3_a_b_idx         c                             -1         NULL      NULL        NULL      false       true       ·            ·
v1                 p                             -1         NULL      NULL        NULL      false       false      ·            ·
v1                 a                             -1         NULL      NULL        NULL      false       false      ·            ·
v1                 b                             -1         NULL      NULL        NULL      false       false      ·            ·
v1                 c                             -1         NULL      NULL        NULL      false       false      ·            ·
t4                 a                             -1         NULL      NULL        NULL      false       false      ·            ·
t4                 b                             -1         NULL      NULL        NULL      false       false      ·            ·
t4                 c                             -1         NULL      NULL        NULL      false       false      ·            ·
t4                 rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t4_pkey            rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t5                 a                             -1         NULL      NULL        NULL      false       false      ·            ·
t5                 b                             -1         NULL      NULL        NULL      false       false      ·            ·
t5                 c                             -1         NULL      NULL        NULL      false       false      ·            ·
t5                 rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t5_pkey            rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t6                 a                             -1         NULL      NULL        NULL      false       false      ·            ·
t6                 b                             -1         NULL      NULL        NULL      false       false      ·            ·
t6                 c                             -1         NULL      NULL        NULL      false       false      ·            ·
t6                 m                             -1         NULL      NULL        NULL      false       false      ·            ·
t6                 rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t6                 ........pg.dropped.5........  -1         NULL      NULL        NULL      false       false      ·            ·
t6                 ........pg.dropped.7........  -1         NULL      NULL        NULL      false       false      ·            ·
t6                 ........pg.dropped.8........  -1         NULL      NULL        NULL      false       false      ·            ·
t6_pkey            rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
t6_expr_idx        crdb_internal_idx_expr        -1         NULL      NULL        NULL      false       true       ·            v
t6_expr_expr1_idx  crdb_internal_idx_expr_1      -1         NULL      NULL        NULL      false       true       ·            v
t6_expr_expr1_idx  crdb_internal_idx_expr        -1         NULL      NULL        NULL      false       true       ·            v
t6_expr_key        crdb_internal_idx_expr_1      -1         NULL      NULL        NULL      false       true       ·            v
t6_expr_idx1       crdb_internal_idx_expr_2      -1         NULL      NULL        NULL      false       true       ·            v
mv1                ?column?                      -1         NULL      NULL        NULL      false       false      ·            ·
mv1                rowid                         -1         NULL      NULL        NULL      true        true       ·            ·
mv1_pkey           rowid                         -1         NULL      NULL        NULL      true        true       ·            ·

query TTBBITTT colnames,rowsort
SELECT c.relname, attname, attisdropped, attislocal, attinhcount, attacl, attoptions, attfdwoptions
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname            attname                       attisdropped  attislocal  attinhcount  attacl  attoptions  attfdwoptions
t1                 p                             false         true        0            NULL    NULL        NULL
t1                 a                             false         true        0            NULL    NULL        NULL
t1                 b                             false         true        0            NULL    NULL        NULL
t1                 c                             false         true        0            NULL    NULL        NULL
t1                 d                             false         true        0            NULL    NULL        NULL
t1                 e                             false         true        0            NULL    NULL        NULL
t1                 f                             false         true        0            NULL    NULL        NULL
t1                 g                             false         true        0            NULL    NULL        NULL
t1                 h                             false         true        0            NULL    NULL        NULL
t1                 i                             false         true        0            NULL    NULL        NULL
t1                 j                             false         true        0            NULL    NULL        NULL
t1                 k                             false         true        0            NULL    NULL        NULL
t1                 l                             false         true        0            NULL    NULL        NULL
t1                 m                             false         true        0            NULL    NULL        NULL
t1                 n                             false         true        0            NULL    NULL        NULL
t1_pkey            p                             false         true        0            NULL    NULL        NULL
t1_a_key           a                             false         true        0            NULL    NULL        NULL
index_key          b                             false         true        0            NULL    NULL        NULL
index_key          c                             false         true        0            NULL    NULL        NULL
t1_m_seq           value                         false         true        0            NULL    NULL        NULL
t1_n_seq           value                         false         true        0            NULL    NULL        NULL
t2                 t1_id                         false         true        0            NULL    NULL        NULL
t2                 rowid                         false         true        0            NULL    NULL        NULL
t2_pkey            rowid                         false         true        0            NULL    NULL        NULL
t2_t1_id_idx       t1_id                         false         true        0            NULL    NULL        NULL
t3                 a                             false         true        0            NULL    NULL        NULL
t3                 b                             false         true        0            NULL    NULL        NULL
t3                 c                             false         true        0            NULL    NULL        NULL
t3                 rowid                         false         true        0            NULL    NULL        NULL
t3_pkey            rowid                         false         true        0            NULL    NULL        NULL
t3_a_b_idx         a                             false         true        0            NULL    NULL        NULL
t3_a_b_idx         b                             false         true        0            NULL    NULL        NULL
t3_a_b_idx         c                             false         true        0            NULL    NULL        NULL
v1                 p                             false         true        0            NULL    NULL        NULL
v1                 a                             false         true        0            NULL    NULL        NULL
v1                 b                             false         true        0            NULL    NULL        NULL
v1                 c                             false         true        0            NULL    NULL        NULL
t4                 a                             false         true        0            NULL    NULL        NULL
t4                 b                             false         true        0            NULL    NULL        NULL
t4                 c                             false         true        0            NULL    NULL        NULL
t4                 rowid                         false         true        0            NULL    NULL        NULL
t4_pkey            rowid                         false         true        0            NULL    NULL        NULL
t5                 a                             false         true        0            NULL    NULL        NULL
t5                 b                             false         true        0            NULL    NULL        NULL
t5                 c                             false         true        0            NULL    NULL        NULL
t5                 rowid                         false         true        0            NULL    NULL        NULL
t5_pkey            rowid                         false         true        0            NULL    NULL        NULL
t6                 a                             false         true        0            NULL    NULL        NULL
t6                 b                             false         true        0            NULL    NULL        NULL
t6                 c                             false         true        0            NULL    NULL        NULL
t6                 m                             false         true        0            NULL    NULL        NULL
t6                 rowid                         false         true        0            NULL    NULL        NULL
t6                 ........pg.dropped.5........  true          true        0            NULL    NULL        NULL
t6                 ........pg.dropped.7........  true          true        0            NULL    NULL        NULL
t6                 ........pg.dropped.8........  true          true        0            NULL    NULL        NULL
t6_pkey            rowid                         false         true        0            NULL    NULL        NULL
t6_expr_idx        crdb_internal_idx_expr        false         true        0            NULL    NULL        NULL
t6_expr_expr1_idx  crdb_internal_idx_expr_1      false         true        0            NULL    NULL        NULL
t6_expr_expr1_idx  crdb_internal_idx_expr        false         true        0            NULL    NULL        NULL
t6_expr_key        crdb_internal_idx_expr_1      false         true        0            NULL    NULL        NULL
t6_expr_idx1       crdb_internal_idx_expr_2      false         true        0            NULL    NULL        NULL
mv1                ?column?                      false         true        0            NULL    NULL        NULL
mv1                rowid                         false         true        0            NULL    NULL        NULL
mv1_pkey           rowid                         false         true        0            NULL    NULL        NULL

# Check relkind codes.
statement ok
CREATE DATABASE relkinds

statement ok
SET DATABASE = relkinds

statement ok
CREATE TABLE tbl_test (k int primary key, v int)

statement ok
CREATE INDEX tbl_test_v_idx ON tbl_test (v)

statement ok
CREATE VIEW view_test AS SELECT k, v FROM tbl_test ORDER BY v

statement ok
CREATE MATERIALIZED VIEW mv_test AS SELECT 1

statement ok
CREATE SEQUENCE seq_test

query TTT
SELECT relname, relkind, relreplident
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
ORDER BY relname
----
mv_test         m  d
mv_test_pkey    i  n
seq_test        S  n
tbl_test        r  d
tbl_test_pkey   i  n
tbl_test_v_idx  i  n
view_test       v  n

statement ok
DROP DATABASE relkinds

statement ok
SET DATABASE = constraint_db

# Select all columns with collations.
query TTTOT colnames,rowsort
SELECT c.relname, attname, t.typname, attcollation, k.collname
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN pg_catalog.pg_type t ON a.atttypid = t.oid
JOIN pg_catalog.pg_collation k ON a.attcollation = k.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname            attname                   typname   attcollation  collname
t1                 d                         varchar   3403232968    default
t6_expr_key        crdb_internal_idx_expr_1  text      3403232968    default
t6_expr_expr1_idx  crdb_internal_idx_expr_1  text      3403232968    default
t6                 c                         text      3403232968    default
t5                 c                         text      3403232968    default
t4                 c                         text      3403232968    default
t3_a_b_idx         c                         text      3403232968    default
t3                 c                         text      3403232968    default
t1                 j                         char      3403232968    default
t1                 i                         _varchar  3403232968    default
t1                 h                         _bpchar   3403232968    default
t1                 k                         varchar   999873346     sv


## pg_catalog.pg_am

query OTIIBBBBBBBBBBBOOOOOOOOOOOOOOOOOT colnames,rowsort
SELECT *
FROM pg_catalog.pg_am
----
oid         amname    amstrategies  amsupport  amcanorder  amcanorderbyop  amcanbackward  amcanunique  amcanmulticol  amoptionalkey  amsearcharray  amsearchnulls  amstorage  amclusterable  ampredlocks  amkeytype  aminsert  ambeginscan  amgettuple  amgetbitmap  amrescan  amendscan  ammarkpos  amrestrpos  ambuild  ambuildempty  ambulkdelete  amvacuumcleanup  amcanreturn  amcostestimate  amoptions  amhandler  amtype
2631952481  prefix    0             0          true        false           true           true         true           true           true           true           false      false          false        0          NULL      NULL         0           0            NULL      NULL       NULL       NULL        NULL     NULL          NULL          NULL             NULL         NULL            NULL       NULL       i
4004609370  inverted  0             0          false       false           false          false        false          false          false          true           false      false          false        0          NULL      NULL         0           0            NULL      NULL       NULL       NULL        NULL     NULL          NULL          NULL             NULL         NULL            NULL       NULL       i

## pg_catalog.pg_attrdef

query OTOITTT colnames
SELECT ad.oid, c.relname, adrelid, adnum, adbin, adsrc, pg_get_expr(ad.adbin, ad.adrelid)
FROM pg_catalog.pg_attrdef ad
JOIN pg_catalog.pg_class c ON ad.adrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public' ORDER BY ad.oid DESC
----
oid         relname  adrelid  adnum  adbin                                 adsrc                                 pg_get_expr
4171354239  t2       113      2      unique_rowid()                        unique_rowid()                        unique_rowid()
3086013501  t5       117      4      unique_rowid()                        unique_rowid()                        unique_rowid()
2306804703  t1       110      13     a * b                                 a * b                                 a * b
2306804701  t1       110      15     nextval('public.t1_n_seq'::REGCLASS)  nextval('public.t1_n_seq'::REGCLASS)  nextval('public.t1_n_seq'::REGCLASS)
2306804700  t1       110      14     nextval('public.t1_m_seq'::REGCLASS)  nextval('public.t1_m_seq'::REGCLASS)  nextval('public.t1_m_seq'::REGCLASS)
2306804698  t1       110      8      a * b                                 a * b                                 a * b
2306804694  t1       110      4      12                                    12                                    12
2000672759  mv1      121      2      unique_rowid()                        unique_rowid()                        unique_rowid()
1740936492  t4       116      4      unique_rowid()                        unique_rowid()                        unique_rowid()
1221463949  t3       114      3      'FOO'::STRING                         'FOO'::STRING                         'FOO'::STRING
1221463946  t3       114      4      unique_rowid()                        unique_rowid()                        unique_rowid()
655595756   t6       120      8      m = 'foo'::public.mytype              m = 'foo'::public.mytype              m = 'foo'::public.mytype
655595747   t6       120      7      lower(c)                              lower(c)                              lower(c)
655595746   t6       120      6      unique_rowid()                        unique_rowid()                        unique_rowid()
655595745   t6       120      5      a + b                                 a + b                                 a + b

## pg_catalog.pg_indexes

query OTTTT colnames,rowsort
SELECT crdb_oid, schemaname, tablename, indexname, tablespace
FROM pg_catalog.pg_indexes
WHERE schemaname = 'public'
----
crdb_oid    schemaname  tablename  indexname          tablespace
3687884466  public      t1         t1_pkey            NULL
3687884465  public      t1         t1_a_key           NULL
3687884464  public      t1         index_key          NULL
2342807459  public      t1_m_seq   primary            NULL
5181036     public      t1_n_seq   primary            NULL
2955071325  public      t2         t2_pkey            NULL
2955071326  public      t2         t2_t1_id_idx       NULL
2695335054  public      t3         t3_pkey            NULL
2695335053  public      t3         t3_a_b_idx         NULL
3214807592  public      t4         t4_pkey            NULL
1869730585  public      t5         t5_pkey            NULL
2129466852  public      t6         t6_pkey            NULL
2129466855  public      t6         t6_expr_idx        NULL
2129466854  public      t6         t6_expr_expr1_idx  NULL
2129466848  public      t6         t6_expr_key        NULL
2129466850  public      t6         t6_expr_idx1       NULL
784389845   public      mv1        mv1_pkey           NULL

query OTTT colnames
SELECT crdb_oid, tablename, indexname, indexdef
FROM pg_catalog.pg_indexes
WHERE schemaname = 'public'
ORDER BY tablename, indexname
----
crdb_oid    tablename  indexname          indexdef
784389845   mv1        mv1_pkey           CREATE UNIQUE INDEX mv1_pkey ON constraint_db.public.mv1 USING btree (rowid ASC)
3687884464  t1         index_key          CREATE UNIQUE INDEX index_key ON constraint_db.public.t1 USING btree (b ASC, c ASC)
3687884465  t1         t1_a_key           CREATE UNIQUE INDEX t1_a_key ON constraint_db.public.t1 USING btree (a ASC)
3687884466  t1         t1_pkey            CREATE UNIQUE INDEX t1_pkey ON constraint_db.public.t1 USING btree (p ASC)
2342807459  t1_m_seq   primary            CREATE INDEX "primary" ON constraint_db.public.t1_m_seq USING btree (value ASC)
5181036     t1_n_seq   primary            CREATE INDEX "primary" ON constraint_db.public.t1_n_seq USING btree (value ASC)
2955071325  t2         t2_pkey            CREATE UNIQUE INDEX t2_pkey ON constraint_db.public.t2 USING btree (rowid ASC)
2955071326  t2         t2_t1_id_idx       CREATE INDEX t2_t1_id_idx ON constraint_db.public.t2 USING btree (t1_id ASC)
2695335053  t3         t3_a_b_idx         CREATE INDEX t3_a_b_idx ON constraint_db.public.t3 USING btree (a ASC, b DESC) STORING (c)
2695335054  t3         t3_pkey            CREATE UNIQUE INDEX t3_pkey ON constraint_db.public.t3 USING btree (rowid ASC)
3214807592  t4         t4_pkey            CREATE UNIQUE INDEX t4_pkey ON constraint_db.public.t4 USING btree (rowid ASC)
1869730585  t5         t5_pkey            CREATE UNIQUE INDEX t5_pkey ON constraint_db.public.t5 USING btree (rowid ASC)
2129466854  t6         t6_expr_expr1_idx  CREATE INDEX t6_expr_expr1_idx ON constraint_db.public.t6 USING btree (lower(c) ASC, (a + b) ASC)
2129466855  t6         t6_expr_idx        CREATE INDEX t6_expr_idx ON constraint_db.public.t6 USING btree ((a + b) ASC)
2129466850  t6         t6_expr_idx1       CREATE INDEX t6_expr_idx1 ON constraint_db.public.t6 USING btree ((m = 'foo'::public.mytype) ASC) WHERE (m = 'foo'::public.mytype)
2129466848  t6         t6_expr_key        CREATE UNIQUE INDEX t6_expr_key ON constraint_db.public.t6 USING btree (lower(c) ASC)
2129466852  t6         t6_pkey            CREATE UNIQUE INDEX t6_pkey ON constraint_db.public.t6 USING btree (rowid ASC)

## pg_catalog.pg_index

query OOIBBBB colnames,rowsort
SELECT indexrelid, indrelid, indnatts, indisunique, indnullsnotdistinct, indisprimary, indisexclusion
FROM pg_catalog.pg_index
WHERE indnkeyatts = 2
----
indexrelid  indrelid  indnatts  indisunique  indnullsnotdistinct  indisprimary  indisexclusion
3687884464  110       2         true         false                false         false
2695335053  114       3         false        false                false         false
2129466854  120       2         false        false                false         false

query OBBBBB colnames,rowsort
SELECT indexrelid, indimmediate, indisclustered, indisvalid, indcheckxmin, indisready
FROM pg_catalog.pg_index
WHERE indnkeyatts = 2
----
indexrelid  indimmediate  indisclustered  indisvalid  indcheckxmin  indisready
3687884464  true          false           true        false         false
2695335053  false         false           true        false         false
2129466854  false         false           true        false         false

query OOBBTTTTTT colnames
SELECT indexrelid, indrelid, indislive, indisreplident, indkey, indcollation, indclass, indoption, indexprs, indpred
FROM pg_catalog.pg_index
WHERE indnkeyatts = 2
ORDER BY indexrelid DESC
----
indexrelid  indrelid  indislive  indisreplident  indkey  indcollation  indclass  indoption  indexprs                indpred
3687884464  110       true       false           3 4     0 0           0 0       2 2        NULL                    NULL
2695335053  114       true       false           1 2 3   0 0           0 0       2 1        NULL                    NULL
2129466854  120       true       false           0 0     3403232968 0  0 0       2 2        {(lower(c)),"(a + b)"}  NULL

# Index expression elements should have an indkey of 0 and be included in
# indexprs.
# TODO(#72241): The types for the 'foo' casts should be constraint_db.mytype,
# not public.mytype.
query TTTT colnames
SELECT c.relname, i.indkey, i.indexprs, i.indpred
FROM pg_catalog.pg_index i
JOIN pg_catalog.pg_class c ON i.indexrelid = c.oid
WHERE c.relname LIKE 't6_%'
ORDER BY 1
----
relname            indkey  indexprs                        indpred
t6_expr_expr1_idx  0 0     {(lower(c)),"(a + b)"}          NULL
t6_expr_idx        0       {"(a + b)"}                     NULL
t6_expr_idx1       0       {"(m = 'foo'::public.mytype)"}  m = 'foo'::public.mytype
t6_expr_key        0       {(lower(c))}                    NULL
t6_pkey            6       NULL                            NULL

statement ok
SET DATABASE = system

skipif config 3node-tenant-default-configs
query OOIBBBBBBBBBBBTTTTTTI colnames
SELECT *
FROM pg_catalog.pg_index
ORDER BY indexrelid
----
indexrelid  indrelid  indnatts  indisunique  indnullsnotdistinct  indisprimary  indisexclusion  indimmediate  indisclustered  indisvalid  indcheckxmin  indisready  indislive  indisreplident  indkey               indcollation               indclass       indoption      indexprs  indpred                                                                                                                       indnkeyatts
51576700    64        5         true         false                true          false           true          false           true        false         false       true       false           6 1 2 3 4            0 0 0 0 0                  0 0 0 0 0      2 2 2 2 2      NULL      NULL                                                                                                                          5
144368028   32        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
190763692   48        1         false        false                true          false           false         false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
311312971   71        3         true         false                true          false           true          false           true        false         false       true       false           1 2 3                0 0 3403232968             0 0 0          2 1 2          NULL      NULL                                                                                                                          3
404104296   39        2         true         false                true          false           true          false           true        false         false       true       false           3 1                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
450499960   55        1         true         false                false         false           true          false           true        false         false       true       false           2                    0                          0              2              NULL      NULL                                                                                                                          1
450499963   55        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
496895627   7         1         false        false                true          false           false         false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
543291288   23        1         false        false                false         false           false         false           true        false         false       true       false           1                    3403232968                 0              2              NULL      NULL                                                                                                                          1
543291289   23        1         false        false                false         false           false         false           true        false         false       true       false           2                    3403232968                 0              2              NULL      NULL                                                                                                                          1
543291291   23        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  3403232968 3403232968      0 0            2 2            NULL      NULL                                                                                                                          2
543291292   23        2         true         false                false         false           true          false           true        false         false       true       false           4 5                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
543291294   23        1         false        false                false         false           false         false           true        false         false       true       false           4                    0                          0              2              NULL      NULL                                                                                                                          1
543291295   23        1         false        false                false         false           false         false           true        false         false       true       false           5                    0                          0              2              NULL      NULL                                                                                                                          1
663840560   42        3         false        false                false         false           false         false           true        false         false       true       false           1 5 17               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
663840561   42        3         false        false                false         false           false         false           true        false         false       true       false           1 5 16               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
663840562   42        3         false        false                false         false           false         false           true        false         false       true       false           1 5 15               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
663840563   42        3         false        false                false         false           false         false           true        false         false       true       false           1 5 14               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
663840564   42        1         false        false                false         false           false         false           true        false         false       true       false           13                   0                          0              2              NULL      NULL                                                                                                                          1
663840565   42        2         false        false                false         false           false         false           true        false         false       true       false           2 3                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
663840566   42        7         true         false                true          false           true          false           true        false         false       true       false           11 1 2 3 4 5 6       0 0 0 0 0 3403232968 0     0 0 0 0 0 0 0  2 2 2 2 2 2 2  NULL      NULL                                                                                                                          7
663840574   42        3         false        false                false         false           false         false           true        false         false       true       false           1 5 19               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
663840575   42        3         false        false                false         false           false         false           true        false         false       true       false           1 5 18               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
710236230   58        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
803027558   26        3         true         false                true          false           true          false           true        false         false       true       false           1 2 3                0 0 3403232968             0 0 0          2 2 2          NULL      NULL                                                                                                                          3
923576837   41        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
969972501   57        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
969972502   57        1         true         false                false         false           true          false           true        false         false       true       false           2                    0                          0              2              NULL      NULL                                                                                                                          1
1016368165  9         1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
1062763829  25        4         true         false                true          false           true          false           true        false         false       true       false           1 2 3 4              0 0 3403232968 3403232968  0 0 0 0        2 2 2 2        NULL      NULL                                                                                                                          4
1183313104  44        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  0 3403232968               0 0            2 2            NULL      NULL                                                                                                                          2
1183313107  44        3         true         false                false         false           true          false           true        false         false       true       false           1 4 3                0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
1229708768  60        3         true         false                true          false           true          false           true        false         false       true       false           1 2 3                0 3403232968 0             0 0 0          2 2 2          NULL      NULL                                                                                                                          3
1276104432  12        2         true         false                true          false           true          false           true        false         false       true       false           1 6                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
1322500096  28        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
1396653700  67        1         false        false                false         false           false         false           true        false         false       true       false           4                    3403232968                 0              2              NULL      NULL                                                                                                                          1
1396653701  67        1         false        false                false         false           false         false           true        false         false       true       false           8                    0                          0              2              NULL      NULL                                                                                                                          1
1396653702  67        1         false        false                false         false           false         false           true        false         false       true       false           3                    3403232968                 0              2              NULL      NULL                                                                                                                          1
1396653703  67        1         false        false                false         false           false         false           true        false         false       true       false           5                    3403232968                 0              2              NULL      NULL                                                                                                                          1
1396653704  67        2         false        false                false         false           false         false           true        false         false       true       false           13 2                 0 0                        0 0            1 2            NULL      NULL                                                                                                                          2
1396653705  67        3         false        false                false         false           false         false           true        false         false       true       false           18 15 2              0 0 0                      0 0 0          2 1 2          NULL      NULL                                                                                                                          3
1396653706  67        2         false        false                false         false           false         false           true        false         false       true       false           6 2                  0 0                        0 0            1 2            NULL      NULL                                                                                                                          2
1396653707  67        2         false        false                false         false           false         false           true        false         false       true       false           7 2                  0 0                        0 0            1 2            NULL      NULL                                                                                                                          2
1396653708  67        2         false        false                false         false           false         false           true        false         false       true       false           9 2                  0 0                        0 0            1 2            NULL      NULL                                                                                                                          2
1396653709  67        2         false        false                false         false           false         false           true        false         false       true       false           10 2                 0 0                        0 0            1 2            NULL      NULL                                                                                                                          2
1396653711  67        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
1489445036  35        9         false        false                false         false           false         false           true        false         false       true       false           2 1 3 6 7 8 9 10 11  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
1489445039  35        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
1535840703  51        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
1582236367  3         1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
1628632026  19        1         false        false                false         false           false         false           true        false         false       true       false           6                    0                          0              2              NULL      NULL                                                                                                                          1
1628632027  19        1         false        false                false         false           false         false           true        false         false       true       false           7                    0                          0              2              NULL      NULL                                                                                                                          1
1628632028  19        1         false        false                false         false           false         false           true        false         false       true       false           5                    0                          0              2              NULL      NULL                                                                                                                          1
1628632029  19        1         false        false                false         false           false         false           true        false         false       true       false           4                    0                          0              2              NULL      NULL                                                                                                                          1
1628632031  19        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
1656389978  70        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
1795576970  54        3         true         false                true          false           true          false           true        false         false       true       false           1 2 3                0 3403232968 0             0 0 0          2 2 1          NULL      NULL                                                                                                                          3
1841972634  6         1         true         false                true          false           true          false           true        false         false       true       false           1                    3403232968                 0              2              NULL      NULL                                                                                                                          1
1916126249  69        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
2008917577  37        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
2008917578  37        1         false        false                false         false           false         false           true        false         false       true       false           5                    0                          0              2              NULL      NULL                                                                                                                          1
2055313241  53        1         true         false                true          false           true          false           true        false         false       true       false           1                    3403232968                 0              2              NULL      NULL                                                                                                                          1
2101708905  5         1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
2148104569  21        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  3403232968 3403232968      0 0            2 2            NULL      NULL                                                                                                                          2
2175862516  72        1         true         false                true          false           true          false           true        false         false       true       false           1                    3403232968                 0              2              NULL      NULL                                                                                                                          1
2268653844  40        4         true         false                true          false           true          false           true        false         false       true       false           1 2 3 4              0 0 0 0                    0 0 0 0        2 2 2 2        NULL      NULL                                                                                                                          4
2315049508  56        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
2315049511  56        1         false        false                false         false           false         false           true        false         false       true       false           2                    0                          0              2              NULL      NULL                                                                                                                          1
2361445172  8         1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
2361445174  8         1         false        false                false         false           false         false           true        false         false       true       false           6                    0                          0              2              NULL      NULL                                                                                                                          1
2361445175  8         1         true         false                false         false           true          false           true        false         false       true       false           4                    3403232968                 0              2              NULL      NULL                                                                                                                          1
2407840836  24        3         true         false                true          false           true          false           true        false         false       true       false           1 2 3                0 0 0                      0 0 0          2 2 2          NULL      NULL                                                                                                                          3
2528390115  47        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
2574785779  63        1         false        false                true          false           false         false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
2621181440  15        2         false        false                false         false           false         false           true        false         false       true       false           2 3                  3403232968 0               0 0            2 2            NULL      NULL                                                                                                                          2
2621181441  15        3         false        false                false         false           false         false           true        false         false       true       false           6 7 2                3403232968 0               0 0            2 2            NULL      NULL                                                                                                                          2
2621181443  15        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
2621181446  15        6         false        false                false         false           false         false           true        false         false       true       false           8 2 3 11 10 9        0 3403232968 0             0 0 0          2 2 2          NULL      status IN ('running'::STRING, 'reverting'::STRING, 'pending'::STRING, 'pause-requested'::STRING, 'cancel-requested'::STRING)  3
2621181447  15        1         false        false                false         false           false         false           true        false         false       true       false           12                   3403232968                 0              2              NULL      NULL                                                                                                                          1
2667577107  31        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
2741730714  66        3         false        false                false         false           false         false           true        false         false       true       false           29 10 11             0 0 0                      0 0 0          2 1 1          NULL      NULL                                                                                                                          3
2741730715  66        3         false        false                false         false           false         false           true        false         false       true       false           5 10 11              0 0 0                      0 0 0          2 1 1          NULL      NULL                                                                                                                          3
2741730716  66        3         false        false                false         false           false         false           true        false         false       true       false           3 10 11              0 0 0                      0 0 0          2 1 1          NULL      NULL                                                                                                                          3
2741730717  66        1         false        false                false         false           false         false           true        false         false       true       false           2                    0                          0              2              NULL      NULL                                                                                                                          1
2741730718  66        2         true         false                true          false           true          false           true        false         false       true       false           4 2                  3403232968 0               0 0            2 2            NULL      NULL                                                                                                                          2
2834522046  34        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
2880917710  50        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  0 3403232968               0 0            2 2            NULL      NULL                                                                                                                          2
3001466989  65        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
3001466990  65        1         false        false                false         false           false         false           true        false         false       true       false           2                    0                          0              2              NULL      NULL                                                                                                                          1
3001466991  65        3         false        false                false         false           false         false           true        false         false       true       false           23 6 7               0 0 0                      0 0 0          2 1 1          NULL      NULL                                                                                                                          3
3094258317  33        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  3403232968 3403232968      0 0            2 2            NULL      NULL                                                                                                                          2
3094258318  33        1         false        false                false         false           false         false           true        false         false       true       false           4                    0                          0              2              NULL      NULL                                                                                                                          1
3261203256  68        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
3353994584  36        1         true         false                true          false           true          false           true        false         false       true       false           1                    0                          0              2              NULL      NULL                                                                                                                          1
3400390248  52        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  3403232968 3403232968      0 0            2 2            NULL      NULL                                                                                                                          2
3400390250  52        4         true         false                false         false           true          false           true        false         false       true       false           2 1 3 4              3403232968 3403232968      0 0            2 2            NULL      NULL                                                                                                                          2
3400390251  52        4         true         false                false         false           true          false           true        false         false       true       false           2 5 3 4              3403232968 0               0 0            2 2            NULL      NULL                                                                                                                          2
3446785912  4         1         true         false                true          false           true          false           true        false         false       true       false           1                    3403232968                 0              2              NULL      NULL                                                                                                                          1
3446785915  4         1         true         false                false         false           true          false           true        false         false       true       false           4                    0                          0              2              NULL      NULL                                                                                                                          1
3493181576  20        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
3613730848  43        3         false        false                false         false           false         false           true        false         false       true       false           1 3 12               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
3613730849  43        3         false        false                false         false           false         false           true        false         false       true       false           1 3 13               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
3613730850  43        3         false        false                false         false           false         false           true        false         false       true       false           1 3 10               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
3613730851  43        3         false        false                false         false           false         false           true        false         false       true       false           1 3 11               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
3613730852  43        1         false        false                false         false           false         false           true        false         false       true       false           2                    0                          0              2              NULL      NULL                                                                                                                          1
3613730853  43        3         false        false                false         false           false         false           true        false         false       true       false           1 3 9                0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
3613730855  43        5         true         false                true          false           true          false           true        false         false       true       false           8 1 2 3 4            0 0 0 3403232968 0         0 0 0 0 0      2 2 2 2 2      NULL      NULL                                                                                                                          5
3613730862  43        3         false        false                false         false           false         false           true        false         false       true       false           1 3 14               0 3403232968 0             0 0 0          2 2 1          NULL      app_name NOT LIKE '$ internal%'::STRING                                                                                       3
3660126519  59        1         true         false                true          false           true          false           true        false         false       true       false           1                    3403232968                 0              2              NULL      NULL                                                                                                                          1
3706522181  11        4         true         false                true          false           true          false           true        false         false       true       false           5 1 2 4              0 0 0 0                    0 0 0 0        2 2 2 2        NULL      NULL                                                                                                                          4
3752917847  27        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
3873467121  46        2         true         false                true          false           true          false           true        false         false       true       false           6 1                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
3919862784  62        2         false        false                false         false           false         false           true        false         false       true       false           1 8                  0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
3919862785  62        1         false        false                false         false           false         false           true        false         false       true       false           2                    0                          0              2              NULL      NULL                                                                                                                          1
3919862786  62        3         true         false                true          false           true          false           true        false         false       true       false           1 2 3                0 0 3403232968             0 0 0          2 2 2          NULL      NULL                                                                                                                          3
3919862788  62        2         false        false                false         false           false         false           true        false         false       true       false           1 13                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
3919862789  62        2         false        false                false         false           false         false           true        false         false       true       false           1 12                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
3919862790  62        2         false        false                false         false           false         false           true        false         false       true       false           1 11                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
3919862791  62        2         false        false                false         false           false         false           true        false         false       true       false           1 9                  0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
3919862795  62        2         false        false                false         false           false         false           true        false         false       true       false           1 14                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
3966258450  14        1         true         false                true          false           true          false           true        false         false       true       false           1                    3403232968                 0              2              NULL      NULL                                                                                                                          1
4012654114  30        3         true         false                true          false           true          false           true        false         false       true       false           1 2 3                0 0 3403232968             0 0 0          2 2 2          NULL      NULL                                                                                                                          3
4133203393  45        2         true         false                true          false           true          false           true        false         false       true       false           1 2                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
4179599057  61        5         true         false                true          false           true          false           true        false         false       true       false           1 2 3 4 5            0 0 0 0 3403232968         0 0 0 0 0      2 2 2 2 2      NULL      NULL                                                                                                                          5
4179599058  61        2         false        false                false         false           false         false           true        false         false       true       false           2 3                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2
4179599059  61        2         false        false                false         false           false         false           true        false         false       true       false           1 11                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
4179599060  61        2         false        false                false         false           false         false           true        false         false       true       false           1 12                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
4179599061  61        2         false        false                false         false           false         false           true        false         false       true       false           1 14                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
4179599062  61        2         false        false                false         false           false         false           true        false         false       true       false           1 15                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
4179599063  61        2         false        false                false         false           false         false           true        false         false       true       false           1 16                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
4179599064  61        2         false        false                false         false           false         false           true        false         false       true       false           1 17                 0 0                        0 0            2 1            NULL      NULL                                                                                                                          2
4225994721  13        2         true         false                true          false           true          false           true        false         false       true       false           1 7                  0 0                        0 0            2 2            NULL      NULL                                                                                                                          2

# From #26504
skipif config 3node-tenant-default-configs
query OOI colnames
SELECT indexrelid,
       (information_schema._pg_expandarray(indclass)).x AS operator_argument_type_oid,
       (information_schema._pg_expandarray(indclass)).n AS operator_argument_position
FROM pg_index
ORDER BY indexrelid, operator_argument_position
----
indexrelid  operator_argument_type_oid  operator_argument_position
51576700    0                           1
51576700    0                           2
51576700    0                           3
51576700    0                           4
51576700    0                           5
144368028   0                           1
190763692   0                           1
311312971   0                           1
311312971   0                           2
311312971   0                           3
404104296   0                           1
404104296   0                           2
450499960   0                           1
450499963   0                           1
496895627   0                           1
543291288   0                           1
543291289   0                           1
543291291   0                           1
543291291   0                           2
543291292   0                           1
543291292   0                           2
543291294   0                           1
543291295   0                           1
663840560   0                           1
663840560   0                           2
663840560   0                           3
663840561   0                           1
663840561   0                           2
663840561   0                           3
663840562   0                           1
663840562   0                           2
663840562   0                           3
663840563   0                           1
663840563   0                           2
663840563   0                           3
663840564   0                           1
663840565   0                           1
663840565   0                           2
663840566   0                           1
663840566   0                           2
663840566   0                           3
663840566   0                           4
663840566   0                           5
663840566   0                           6
663840566   0                           7
663840574   0                           1
663840574   0                           2
663840574   0                           3
663840575   0                           1
663840575   0                           2
663840575   0                           3
710236230   0                           1
803027558   0                           1
803027558   0                           2
803027558   0                           3
923576837   0                           1
969972501   0                           1
969972502   0                           1
1016368165  0                           1
1062763829  0                           1
1062763829  0                           2
1062763829  0                           3
1062763829  0                           4
1183313104  0                           1
1183313104  0                           2
1183313107  0                           1
1183313107  0                           2
1229708768  0                           1
1229708768  0                           2
1229708768  0                           3
1276104432  0                           1
1276104432  0                           2
1322500096  0                           1
1396653700  0                           1
1396653701  0                           1
1396653702  0                           1
1396653703  0                           1
1396653704  0                           1
1396653704  0                           2
1396653705  0                           1
1396653705  0                           2
1396653705  0                           3
1396653706  0                           1
1396653706  0                           2
1396653707  0                           1
1396653707  0                           2
1396653708  0                           1
1396653708  0                           2
1396653709  0                           1
1396653709  0                           2
1396653711  0                           1
1396653711  0                           2
1489445036  0                           1
1489445036  0                           2
1489445039  0                           1
1535840703  0                           1
1582236367  0                           1
1628632026  0                           1
1628632027  0                           1
1628632028  0                           1
1628632029  0                           1
1628632031  0                           1
1656389978  0                           1
1656389978  0                           2
1795576970  0                           1
1795576970  0                           2
1795576970  0                           3
1841972634  0                           1
1916126249  0                           1
1916126249  0                           2
2008917577  0                           1
2008917578  0                           1
2055313241  0                           1
2101708905  0                           1
2148104569  0                           1
2148104569  0                           2
2175862516  0                           1
2268653844  0                           1
2268653844  0                           2
2268653844  0                           3
2268653844  0                           4
2315049508  0                           1
2315049511  0                           1
2361445172  0                           1
2361445174  0                           1
2361445175  0                           1
2407840836  0                           1
2407840836  0                           2
2407840836  0                           3
2528390115  0                           1
2574785779  0                           1
2621181440  0                           1
2621181440  0                           2
2621181441  0                           1
2621181441  0                           2
2621181443  0                           1
2621181446  0                           1
2621181446  0                           2
2621181446  0                           3
2621181447  0                           1
2667577107  0                           1
2741730714  0                           1
2741730714  0                           2
2741730714  0                           3
2741730715  0                           1
2741730715  0                           2
2741730715  0                           3
2741730716  0                           1
2741730716  0                           2
2741730716  0                           3
2741730717  0                           1
2741730718  0                           1
2741730718  0                           2
2834522046  0                           1
2880917710  0                           1
2880917710  0                           2
3001466989  0                           1
3001466990  0                           1
3001466991  0                           1
3001466991  0                           2
3001466991  0                           3
3094258317  0                           1
3094258317  0                           2
3094258318  0                           1
3261203256  0                           1
3261203256  0                           2
3353994584  0                           1
3400390248  0                           1
3400390248  0                           2
3400390250  0                           1
3400390250  0                           2
3400390251  0                           1
3400390251  0                           2
3446785912  0                           1
3446785915  0                           1
3493181576  0                           1
3493181576  0                           2
3613730848  0                           1
3613730848  0                           2
3613730848  0                           3
3613730849  0                           1
3613730849  0                           2
3613730849  0                           3
3613730850  0                           1
3613730850  0                           2
3613730850  0                           3
3613730851  0                           1
3613730851  0                           2
3613730851  0                           3
3613730852  0                           1
3613730853  0                           1
3613730853  0                           2
3613730853  0                           3
3613730855  0                           1
3613730855  0                           2
3613730855  0                           3
3613730855  0                           4
3613730855  0                           5
3613730862  0                           1
3613730862  0                           2
3613730862  0                           3
3660126519  0                           1
3706522181  0                           1
3706522181  0                           2
3706522181  0                           3
3706522181  0                           4
3752917847  0                           1
3752917847  0                           2
3873467121  0                           1
3873467121  0                           2
3919862784  0                           1
3919862784  0                           2
3919862785  0                           1
3919862786  0                           1
3919862786  0                           2
3919862786  0                           3
3919862788  0                           1
3919862788  0                           2
3919862789  0                           1
3919862789  0                           2
3919862790  0                           1
3919862790  0                           2
3919862791  0                           1
3919862791  0                           2
3919862795  0                           1
3919862795  0                           2
3966258450  0                           1
4012654114  0                           1
4012654114  0                           2
4012654114  0                           3
4133203393  0                           1
4133203393  0                           2
4179599057  0                           1
4179599057  0                           2
4179599057  0                           3
4179599057  0                           4
4179599057  0                           5
4179599058  0                           1
4179599058  0                           2
4179599059  0                           1
4179599059  0                           2
4179599060  0                           1
4179599060  0                           2
4179599061  0                           1
4179599061  0                           2
4179599062  0                           1
4179599062  0                           2
4179599063  0                           1
4179599063  0                           2
4179599064  0                           1
4179599064  0                           2
4225994721  0                           1
4225994721  0                           2

## pg_catalog.pg_collation

statement ok
SET DATABASE = constraint_db

query OTOOITTTTT colnames
SELECT * FROM pg_collation
WHERE collname='en-US'
----
oid         collname  collnamespace  collowner  collencoding  collcollate  collctype  collprovider  collversion  collisdeterministic
3903121477  en-US     4294967095     NULL       6             NULL         NULL       NULL          NULL         NULL

user testuser

# Should be globally visible
query OT colnames
SELECT oid, collname FROM pg_collation
WHERE collname='en-US'
----
oid         collname
3903121477  en-US

user root

## pg_catalog.pg_constraint
##
## These order of this virtual table is non-deterministic, so all queries must
## explicitly add an ORDER BY clause oor use rowsort.

query TOTT colnames,rowsort
SELECT conname, connamespace, contype, replace(condef, ' ', '_') as condef
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public'
----
conname        connamespace  contype  condef
t1_pkey        109           p        PRIMARY_KEY_(p_ASC)
t1_a_key       109           u        UNIQUE_(a_ASC)
index_key      109           u        UNIQUE_(b_ASC,_c_ASC)
primary        109           p        PRIMARY_KEY_(value_ASC)
primary        109           p        PRIMARY_KEY_(value_ASC)
t2_pkey        109           p        PRIMARY_KEY_(rowid_ASC)
fk             109           f        FOREIGN_KEY_(t1_id)_REFERENCES_t1(a)
t3_pkey        109           p        PRIMARY_KEY_(rowid_ASC)
check_b        109           c        CHECK_((b_>_11))
check_c        109           c        CHECK_((c_!=_''::STRING))
fk             109           f        FOREIGN_KEY_(a,_b)_REFERENCES_t1(b,_c)
t4_pkey        109           p        PRIMARY_KEY_(rowid_ASC)
unique_a       109           u        UNIQUE_WITHOUT_INDEX_(a)
uwi_b_c        109           u        UNIQUE_WITHOUT_INDEX_(b,_c)
uwi_b_partial  109           u        UNIQUE_WITHOUT_INDEX_(b)_WHERE_(c_=_'foo'::STRING)
t5_pkey        109           p        PRIMARY_KEY_(rowid_ASC)
fk_b_c         109           f        FOREIGN_KEY_(b,_c)_REFERENCES_t4(b,_c)_MATCH_FULL_ON_UPDATE_RESTRICT
t5_a_fkey      109           f        FOREIGN_KEY_(a)_REFERENCES_t4(a)_ON_DELETE_CASCADE
t6_pkey        109           p        PRIMARY_KEY_(rowid_ASC)
t6_expr_key    109           u        UNIQUE_(lower(c)_ASC)
mv1_pkey       109           p        PRIMARY_KEY_(rowid_ASC)

query TTBBBOOO colnames,rowsort
SELECT conname, contype, condeferrable, condeferred, convalidated, conrelid, contypid, conindid
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public'
----
conname        contype  condeferrable  condeferred  convalidated  conrelid  contypid  conindid
t1_pkey        p        false          false        true          110       0         3687884466
t1_a_key       u        false          false        true          110       0         3687884465
index_key      u        false          false        true          110       0         3687884464
primary        p        false          false        true          111       0         2342807459
primary        p        false          false        true          112       0         5181036
t2_pkey        p        false          false        true          113       0         2955071325
fk             f        false          false        true          113       0         3687884465
t3_pkey        p        false          false        true          114       0         2695335054
check_b        c        false          false        true          114       0         0
check_c        c        false          false        true          114       0         0
fk             f        false          false        true          114       0         3687884464
t4_pkey        p        false          false        true          116       0         3214807592
unique_a       u        false          false        true          116       0         0
uwi_b_c        u        false          false        true          116       0         0
uwi_b_partial  u        false          false        true          116       0         0
t5_pkey        p        false          false        true          117       0         1869730585
fk_b_c         f        false          false        true          117       0         0
t5_a_fkey      f        false          false        true          117       0         0
t6_pkey        p        false          false        true          120       0         2129466852
t6_expr_key    u        false          false        true          120       0         2129466848
mv1_pkey       p        false          false        true          121       0         784389845

query T
SELECT conname
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype NOT IN ('c', 'f', 'p', 'u')
ORDER BY con.oid
----

query TOTTT colnames,rowsort
SELECT conname, confrelid, confupdtype, confdeltype, confmatchtype
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype IN ('c', 'p', 'u')
----
conname        confrelid  confupdtype  confdeltype  confmatchtype
t1_pkey        0          NULL         NULL         NULL
t1_a_key       0          NULL         NULL         NULL
index_key      0          NULL         NULL         NULL
primary        0          NULL         NULL         NULL
primary        0          NULL         NULL         NULL
t2_pkey        0          NULL         NULL         NULL
t3_pkey        0          NULL         NULL         NULL
check_b        0          NULL         NULL         NULL
check_c        0          NULL         NULL         NULL
t4_pkey        0          NULL         NULL         NULL
unique_a       0          NULL         NULL         NULL
uwi_b_c        0          NULL         NULL         NULL
uwi_b_partial  0          NULL         NULL         NULL
t5_pkey        0          NULL         NULL         NULL
t6_pkey        0          NULL         NULL         NULL
t6_expr_key    0          NULL         NULL         NULL
mv1_pkey       0          NULL         NULL         NULL

query TOTTT colnames,rowsort
SELECT conname, confrelid, confupdtype, confdeltype, confmatchtype
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype = 'f'
ORDER BY con.oid
----
conname    confrelid  confupdtype  confdeltype  confmatchtype
fk_b_c     116        r            a            f
fk         110        a            a            s
t5_a_fkey  116        a            c            s
fk         110        a            a            s

query TBIBT colnames,rowsort
SELECT conname, conislocal, coninhcount, connoinherit, conkey
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public'
----
conname        conislocal  coninhcount  connoinherit  conkey
t1_pkey        true        0            true          {1}
t1_a_key       true        0            true          {2}
index_key      true        0            true          {3,4}
primary        true        0            true          {1}
primary        true        0            true          {1}
t2_pkey        true        0            true          {2}
fk             true        0            true          {1}
t3_pkey        true        0            true          {4}
check_b        true        0            true          {2}
check_c        true        0            true          {3}
fk             true        0            true          {1,2}
t4_pkey        true        0            true          {4}
unique_a       true        0            true          NULL
uwi_b_c        true        0            true          NULL
uwi_b_partial  true        0            true          NULL
t5_pkey        true        0            true          {4}
fk_b_c         true        0            true          {2,3}
t5_a_fkey      true        0            true          {1}
t6_pkey        true        0            true          {6}
t6_expr_key    true        0            true          {7}
mv1_pkey       true        0            true          {2}

query TTTTTTTTT colnames
SELECT conname, confkey, conpfeqop, conppeqop, conffeqop, conexclop, conbin, consrc, pg_get_constraintdef(con.oid) as condef
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype IN ('c', 'p', 'u')
ORDER BY conname
----
conname        confkey  conpfeqop  conppeqop  conffeqop  conexclop  conbin             consrc             condef
check_b        NULL     NULL       NULL       NULL       NULL       (b > 11)           (b > 11)           CHECK ((b > 11))
check_c        NULL     NULL       NULL       NULL       NULL       (c != ''::STRING)  (c != ''::STRING)  CHECK ((c != ''::STRING))
index_key      NULL     NULL       NULL       NULL       NULL       NULL               NULL               UNIQUE (b ASC, c ASC)
mv1_pkey       NULL     NULL       NULL       NULL       NULL       NULL               NULL               PRIMARY KEY (rowid ASC)
primary        NULL     NULL       NULL       NULL       NULL       NULL               NULL               PRIMARY KEY (value ASC)
primary        NULL     NULL       NULL       NULL       NULL       NULL               NULL               PRIMARY KEY (value ASC)
t1_a_key       NULL     NULL       NULL       NULL       NULL       NULL               NULL               UNIQUE (a ASC)
t1_pkey        NULL     NULL       NULL       NULL       NULL       NULL               NULL               PRIMARY KEY (p ASC)
t2_pkey        NULL     NULL       NULL       NULL       NULL       NULL               NULL               PRIMARY KEY (rowid ASC)
t3_pkey        NULL     NULL       NULL       NULL       NULL       NULL               NULL               PRIMARY KEY (rowid ASC)
t4_pkey        NULL     NULL       NULL       NULL       NULL       NULL               NULL               PRIMARY KEY (rowid ASC)
t5_pkey        NULL     NULL       NULL       NULL       NULL       NULL               NULL               PRIMARY KEY (rowid ASC)
t6_expr_key    NULL     NULL       NULL       NULL       NULL       NULL               NULL               UNIQUE (lower(c) ASC)
t6_pkey        NULL     NULL       NULL       NULL       NULL       NULL               NULL               PRIMARY KEY (rowid ASC)
unique_a       NULL     NULL       NULL       NULL       NULL       NULL               NULL               UNIQUE WITHOUT INDEX (a)
uwi_b_c        NULL     NULL       NULL       NULL       NULL       NULL               NULL               UNIQUE WITHOUT INDEX (b, c)
uwi_b_partial  NULL     NULL       NULL       NULL       NULL       NULL               NULL               UNIQUE WITHOUT INDEX (b) WHERE (c = 'foo'::STRING)

query TTTTTTTT colnames,rowsort
SELECT conname, confkey, conpfeqop, conppeqop, conffeqop, conexclop, conbin, consrc
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype = 'f'
ORDER BY con.oid
----
conname    confkey  conpfeqop  conppeqop  conffeqop  conexclop  conbin  consrc
fk_b_c     {2,3}    NULL       NULL       NULL       NULL       NULL    NULL
fk         {3,4}    NULL       NULL       NULL       NULL       NULL    NULL
t5_a_fkey  {1}      NULL       NULL       NULL       NULL       NULL    NULL
fk         {2}      NULL       NULL       NULL       NULL       NULL    NULL

## pg_catalog.pg_depend

query OOIOOIT colnames
SELECT classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype
FROM pg_catalog.pg_depend
ORDER BY objid, refobjid, refobjsubid
----
classid     objid       objsubid  refclassid  refobjid    refobjsubid  deptype
4294967083  111         0         4294967083  110         14           a
4294967083  112         0         4294967083  110         15           a
4294967037  842401391   0         4294967083  110         1            n
4294967037  842401391   0         4294967083  110         2            n
4294967037  842401391   0         4294967083  110         3            n
4294967037  842401391   0         4294967083  110         4            n
4294967080  1179276562  0         4294967083  3687884464  0            n
4294967080  3935750373  0         4294967083  3687884465  0            n
4294967080  4072017905  0         4294967083  0           0            n
4294967080  4170826110  0         4294967083  0           0            n

statement ok
CREATE TABLE t_with_pk_seq (a INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, b INT);

# This query is used by activerecord to find primary keys backed by a sequence.
query TTT colnames
SELECT attr.attname, nsp.nspname, seq.relname
FROM pg_class      seq,
     pg_attribute  attr,
     pg_depend     dep,
     pg_constraint cons,
     pg_namespace  nsp
WHERE seq.oid           = dep.objid
  AND seq.relkind       = 'S'
  AND attr.attrelid     = dep.refobjid
  AND attr.attnum       = dep.refobjsubid
  AND attr.attrelid     = cons.conrelid
  AND attr.attnum       = cons.conkey[1]
  AND seq.relnamespace  = nsp.oid
  AND cons.contype      = 'p'
  AND dep.classid       = 'pg_class'::regclass
  AND dep.refobjid      = 't_with_pk_seq'::regclass
----
attname  nspname  relname
a        public   t_with_pk_seq_a_seq

# Some entries in pg_depend are dependency links from the pg_constraint system
# table to the pg_class system table. Other entries are links to pg_class when it is
# a table-view dependency.

query OOTT colnames,rowsort
SELECT DISTINCT classid, refclassid, cla.relname AS tablename, refcla.relname AS reftablename
FROM pg_catalog.pg_depend
JOIN pg_class cla ON classid=cla.oid
JOIN pg_class refcla ON refclassid=refcla.oid
----
classid     refclassid  tablename      reftablename
4294967037  4294967083  pg_rewrite     pg_class
4294967083  4294967083  pg_class       pg_class
4294967080  4294967083  pg_constraint  pg_class

# Some entries in pg_depend are foreign key constraints that reference an index
# in pg_class. Other entries are table-view dependencies

query TT colnames
SELECT relname, relkind
FROM pg_depend
JOIN pg_class ON refobjid=pg_class.oid
ORDER BY relname
----
relname        relkind
index_key      i
t1             r
t1             r
t1             r
t1             r
t1             r
t1             r
t1_a_key       i
t_with_pk_seq  r


# Some entries in pg_depend are linked to a foreign key constraint whose
# supporting index is the referenced object id. Other entries are table-view dependencies

query T colnames
SELECT DISTINCT pg_constraint.contype
FROM pg_depend
JOIN pg_constraint ON objid=pg_constraint.oid AND refobjid=pg_constraint.conindid
----
contype
f

statement ok
CREATE TABLE source_table(a INT PRIMARY KEY, b INT, c INT);
CREATE VIEW depend_view AS SELECT b, c FROM source_table;
CREATE VIEW view_dependingon_view AS SELECT b, c FROM depend_view;

query TTTTTT colnames
SELECT
     depend_cat_class.relname depend_catalog,
	   source_cat_class.relname source_catalog,
	   source_class.relname source,
	   depend_class.relname depend,
	   pg_attribute.attname column_name,
	   pg_depend.deptype
  FROM pg_depend
  JOIN pg_rewrite ON pg_rewrite.oid = pg_depend.objid
  JOIN pg_class depend_class ON depend_class.oid = pg_rewrite.ev_class
  JOIN pg_class source_class ON pg_depend.refobjid = source_class.oid
  JOIN pg_class depend_cat_class ON pg_depend.classid = depend_cat_class.oid
  JOIN pg_class source_cat_class ON pg_depend.refclassid = source_cat_class.oid
  JOIN pg_attribute ON pg_depend.refobjid    = pg_attribute.attrelid
                   AND pg_depend.refobjsubid = pg_attribute.attnum
  WHERE source_class.relname IN ('source_table', 'depend_view')
  ORDER BY 3, 4, 5
----
depend_catalog  source_catalog  source        depend                 column_name  deptype
pg_rewrite      pg_class        depend_view   view_dependingon_view  b            n
pg_rewrite      pg_class        depend_view   view_dependingon_view  c            n
pg_rewrite      pg_class        source_table  depend_view            b            n
pg_rewrite      pg_class        source_table  depend_view            c            n

# Testing pg_rewrite
query OTOTTBTT colnames
SELECT * FROM pg_rewrite WHERE ev_class IN (
  SELECT oid FROM pg_class WHERE relname IN ('depend_view', 'view_dependingon_view')
) ORDER BY oid
----
oid         rulename  ev_class  ev_type  ev_enabled  is_instead  ev_qual  ev_action
2159720243  _RETURN   131       1        NULL        true        NULL     NULL
3504797253  _RETURN   132       1        NULL        true        NULL     NULL

## pg_catalog.pg_enum
statement ok
CREATE TYPE newtype1 AS ENUM ('v1', 'v2');
CREATE TYPE newtype2 AS ENUM ('v3', 'v4')

query OORT colnames,rowsort
SELECT * FROM pg_enum
----
oid         enumtypid  enumsortorder  enumlabel
3341603527  100118     0              foo
3341603335  100118     1              bar
3341603399  100118     2              baz
2553055434  100133     0              v1
2553055242  100133     1              v2
2519500068  100135     0              v3
2519500260  100135     1              v4

## pg_catalog.pg_type

query OTOOIBT colnames
SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type
WHERE oid < 4194967002 -- exclude implicit types for virtual tables
ORDER BY oid
----
oid     typname                typnamespace  typowner    typlen  typbyval  typtype
16      bool                   4294967095    NULL        1       true      b
17      bytea                  4294967095    NULL        -1      false     b
18      char                   4294967095    NULL        1       true      b
19      name                   4294967095    NULL        -1      false     b
20      int8                   4294967095    NULL        8       true      b
21      int2                   4294967095    NULL        2       true      b
22      int2vector             4294967095    NULL        -1      false     b
23      int4                   4294967095    NULL        4       true      b
24      regproc                4294967095    NULL        4       true      b
25      text                   4294967095    NULL        -1      false     b
26      oid                    4294967095    NULL        4       true      b
30      oidvector              4294967095    NULL        -1      false     b
700     float4                 4294967095    NULL        4       true      b
701     float8                 4294967095    NULL        8       true      b
705     unknown                4294967095    NULL        0       true      b
869     inet                   4294967095    NULL        24      true      b
1000    _bool                  4294967095    NULL        -1      false     b
1001    _bytea                 4294967095    NULL        -1      false     b
1002    _char                  4294967095    NULL        -1      false     b
1003    _name                  4294967095    NULL        -1      false     b
1005    _int2                  4294967095    NULL        -1      false     b
1006    _int2vector            4294967095    NULL        -1      false     b
1007    _int4                  4294967095    NULL        -1      false     b
1008    _regproc               4294967095    NULL        -1      false     b
1009    _text                  4294967095    NULL        -1      false     b
1013    _oidvector             4294967095    NULL        -1      false     b
1014    _bpchar                4294967095    NULL        -1      false     b
1015    _varchar               4294967095    NULL        -1      false     b
1016    _int8                  4294967095    NULL        -1      false     b
1021    _float4                4294967095    NULL        -1      false     b
1022    _float8                4294967095    NULL        -1      false     b
1028    _oid                   4294967095    NULL        -1      false     b
1041    _inet                  4294967095    NULL        -1      false     b
1042    bpchar                 4294967095    NULL        -1      false     b
1043    varchar                4294967095    NULL        -1      false     b
1082    date                   4294967095    NULL        4       true      b
1083    time                   4294967095    NULL        8       true      b
1114    timestamp              4294967095    NULL        8       true      b
1115    _timestamp             4294967095    NULL        -1      false     b
1182    _date                  4294967095    NULL        -1      false     b
1183    _time                  4294967095    NULL        -1      false     b
1184    timestamptz            4294967095    NULL        8       true      b
1185    _timestamptz           4294967095    NULL        -1      false     b
1186    interval               4294967095    NULL        24      true      b
1187    _interval              4294967095    NULL        -1      false     b
1231    _numeric               4294967095    NULL        -1      false     b
1266    timetz                 4294967095    NULL        12      true      b
1270    _timetz                4294967095    NULL        -1      false     b
1560    bit                    4294967095    NULL        -1      false     b
1561    _bit                   4294967095    NULL        -1      false     b
1562    varbit                 4294967095    NULL        -1      false     b
1563    _varbit                4294967095    NULL        -1      false     b
1700    numeric                4294967095    NULL        -1      false     b
1790    refcursor              4294967095    NULL        -1      false     b
2201    _refcursor             4294967095    NULL        -1      false     b
2202    regprocedure           4294967095    NULL        4       true      b
2205    regclass               4294967095    NULL        4       true      b
2206    regtype                4294967095    NULL        4       true      b
2207    _regprocedure          4294967095    NULL        -1      false     b
2210    _regclass              4294967095    NULL        -1      false     b
2211    _regtype               4294967095    NULL        -1      false     b
2249    record                 4294967095    NULL        0       true      p
2277    anyarray               4294967095    NULL        -1      false     p
2278    void                   4294967095    NULL        0       true      p
2279    trigger                4294967095    NULL        4       true      p
2283    anyelement             4294967095    NULL        -1      false     p
2287    _record                4294967095    NULL        -1      false     b
2950    uuid                   4294967095    NULL        16      true      b
2951    _uuid                  4294967095    NULL        -1      false     b
3220    pg_lsn                 4294967095    NULL        8       true      b
3221    _pg_lsn                4294967095    NULL        -1      false     b
3614    tsvector               4294967095    NULL        -1      false     b
3615    tsquery                4294967095    NULL        -1      false     b
3643    _tsvector              4294967095    NULL        -1      false     b
3645    _tsquery               4294967095    NULL        -1      false     b
3802    jsonb                  4294967095    NULL        -1      false     b
3807    _jsonb                 4294967095    NULL        -1      false     b
4089    regnamespace           4294967095    NULL        4       true      b
4090    _regnamespace          4294967095    NULL        -1      false     b
4096    regrole                4294967095    NULL        4       true      b
4097    _regrole               4294967095    NULL        -1      false     b
90000   geometry               4294967095    NULL        -1      false     b
90001   _geometry              4294967095    NULL        -1      false     b
90002   geography              4294967095    NULL        -1      false     b
90003   _geography             4294967095    NULL        -1      false     b
90004   box2d                  4294967095    NULL        32      true      b
90005   _box2d                 4294967095    NULL        -1      false     b
90006   vector                 4294967095    NULL        -1      false     b
90007   _vector                4294967095    NULL        -1      false     b
100110  t1                     109           1546506610  -1      false     c
100111  t1_m_seq               109           1546506610  -1      false     c
100112  t1_n_seq               109           1546506610  -1      false     c
100113  t2                     109           1546506610  -1      false     c
100114  t3                     109           1546506610  -1      false     c
100115  v1                     109           1546506610  -1      false     c
100116  t4                     109           1546506610  -1      false     c
100117  t5                     109           1546506610  -1      false     c
100118  mytype                 109           1546506610  -1      false     e
100119  _mytype                109           1546506610  -1      false     b
100120  t6                     109           1546506610  -1      false     c
100121  mv1                    109           1546506610  -1      false     c
100128  t_with_pk_seq          109           1546506610  -1      false     c
100129  t_with_pk_seq_a_seq    109           1546506610  -1      false     c
100130  source_table           109           1546506610  -1      false     c
100131  depend_view            109           1546506610  -1      false     c
100132  view_dependingon_view  109           1546506610  -1      false     c
100133  newtype1               109           1546506610  -1      false     e
100134  _newtype1              109           1546506610  -1      false     b
100135  newtype2               109           1546506610  -1      false     e
100136  _newtype2              109           1546506610  -1      false     b

query OTTBBTOOO colnames
SELECT oid, typname, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray
FROM pg_catalog.pg_type
WHERE oid < 4194967002 -- exclude implicit types for virtual tables
ORDER BY oid
----
oid     typname                typcategory  typispreferred  typisdefined  typdelim  typrelid  typelem  typarray
16      bool                   B            false           true          ,         0         0        1000
17      bytea                  U            false           true          ,         0         0        1001
18      char                   S            false           true          ,         0         0        1002
19      name                   S            false           true          ,         0         0        1003
20      int8                   N            false           true          ,         0         0        1016
21      int2                   N            false           true          ,         0         0        1005
22      int2vector             A            false           true          ,         0         21       1006
23      int4                   N            false           true          ,         0         0        1007
24      regproc                N            false           true          ,         0         0        1008
25      text                   S            false           true          ,         0         0        1009
26      oid                    N            false           true          ,         0         0        1028
30      oidvector              A            false           true          ,         0         26       1013
700     float4                 N            false           true          ,         0         0        1021
701     float8                 N            false           true          ,         0         0        1022
705     unknown                X            false           true          ,         0         0        0
869     inet                   I            false           true          ,         0         0        1041
1000    _bool                  A            false           true          ,         0         16       0
1001    _bytea                 A            false           true          ,         0         17       0
1002    _char                  A            false           true          ,         0         18       0
1003    _name                  A            false           true          ,         0         19       0
1005    _int2                  A            false           true          ,         0         21       0
1006    _int2vector            A            false           true          ,         0         22       0
1007    _int4                  A            false           true          ,         0         23       0
1008    _regproc               A            false           true          ,         0         24       0
1009    _text                  A            false           true          ,         0         25       0
1013    _oidvector             A            false           true          ,         0         30       0
1014    _bpchar                A            false           true          ,         0         1042     0
1015    _varchar               A            false           true          ,         0         1043     0
1016    _int8                  A            false           true          ,         0         20       0
1021    _float4                A            false           true          ,         0         700      0
1022    _float8                A            false           true          ,         0         701      0
1028    _oid                   A            false           true          ,         0         26       0
1041    _inet                  A            false           true          ,         0         869      0
1042    bpchar                 S            false           true          ,         0         0        1014
1043    varchar                S            false           true          ,         0         0        1015
1082    date                   D            false           true          ,         0         0        1182
1083    time                   D            false           true          ,         0         0        1183
1114    timestamp              D            false           true          ,         0         0        1115
1115    _timestamp             A            false           true          ,         0         1114     0
1182    _date                  A            false           true          ,         0         1082     0
1183    _time                  A            false           true          ,         0         1083     0
1184    timestamptz            D            false           true          ,         0         0        1185
1185    _timestamptz           A            false           true          ,         0         1184     0
1186    interval               T            false           true          ,         0         0        1187
1187    _interval              A            false           true          ,         0         1186     0
1231    _numeric               A            false           true          ,         0         1700     0
1266    timetz                 D            false           true          ,         0         0        1270
1270    _timetz                A            false           true          ,         0         1266     0
1560    bit                    V            false           true          ,         0         0        1561
1561    _bit                   A            false           true          ,         0         1560     0
1562    varbit                 V            false           true          ,         0         0        1563
1563    _varbit                A            false           true          ,         0         1562     0
1700    numeric                N            false           true          ,         0         0        1231
1790    refcursor              U            false           true          ,         0         0        2201
2201    _refcursor             A            false           true          ,         0         1790     0
2202    regprocedure           N            false           true          ,         0         0        2207
2205    regclass               N            false           true          ,         0         0        2210
2206    regtype                N            false           true          ,         0         0        2211
2207    _regprocedure          A            false           true          ,         0         2202     0
2210    _regclass              A            false           true          ,         0         2205     0
2211    _regtype               A            false           true          ,         0         2206     0
2249    record                 P            false           true          ,         0         0        2287
2277    anyarray               P            false           true          ,         0         0        0
2278    void                   P            false           true          ,         0         0        0
2279    trigger                P            false           true          ,         0         0        0
2283    anyelement             P            false           true          ,         0         0        2277
2287    _record                A            false           true          ,         0         2249     0
2950    uuid                   U            false           true          ,         0         0        2951
2951    _uuid                  A            false           true          ,         0         2950     0
3220    pg_lsn                 U            false           true          ,         0         0        3221
3221    _pg_lsn                A            false           true          ,         0         3220     0
3614    tsvector               U            false           true          ,         0         0        3643
3615    tsquery                U            false           true          ,         0         0        3645
3643    _tsvector              A            false           true          ,         0         3614     0
3645    _tsquery               A            false           true          ,         0         3615     0
3802    jsonb                  U            false           true          ,         0         0        3807
3807    _jsonb                 A            false           true          ,         0         3802     0
4089    regnamespace           N            false           true          ,         0         0        4090
4090    _regnamespace          A            false           true          ,         0         4089     0
4096    regrole                N            false           true          ,         0         0        4097
4097    _regrole               A            false           true          ,         0         4096     0
90000   geometry               U            false           true          :         0         0        90001
90001   _geometry              A            false           true          :         0         90000    0
90002   geography              U            false           true          :         0         0        90003
90003   _geography             A            false           true          :         0         90002    0
90004   box2d                  U            false           true          ,         0         0        90005
90005   _box2d                 A            false           true          ,         0         90004    0
90006   vector                 U            false           true          ,         0         0        90007
90007   _vector                A            false           true          ,         0         90006    0
100110  t1                     C            false           true          ,         110       0        0
100111  t1_m_seq               C            false           true          ,         111       0        0
100112  t1_n_seq               C            false           true          ,         112       0        0
100113  t2                     C            false           true          ,         113       0        0
100114  t3                     C            false           true          ,         114       0        0
100115  v1                     C            false           true          ,         115       0        0
100116  t4                     C            false           true          ,         116       0        0
100117  t5                     C            false           true          ,         117       0        0
100118  mytype                 E            false           true          ,         0         0        100119
100119  _mytype                A            false           true          ,         0         100118   0
100120  t6                     C            false           true          ,         120       0        0
100121  mv1                    C            false           true          ,         121       0        0
100128  t_with_pk_seq          C            false           true          ,         128       0        0
100129  t_with_pk_seq_a_seq    C            false           true          ,         129       0        0
100130  source_table           C            false           true          ,         130       0        0
100131  depend_view            C            false           true          ,         131       0        0
100132  view_dependingon_view  C            false           true          ,         132       0        0
100133  newtype1               E            false           true          ,         0         0        100134
100134  _newtype1              A            false           true          ,         0         100133   0
100135  newtype2               E            false           true          ,         0         0        100136
100136  _newtype2              A            false           true          ,         0         100135   0

query OTOOOOOOO colnames
SELECT oid, typname, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze
FROM pg_catalog.pg_type
WHERE oid < 4194967002 -- exclude implicit types for virtual tables
ORDER BY oid
----
oid     typname                typinput        typoutput        typreceive        typsend           typmodin  typmodout  typanalyze
16      bool                   boolin          boolout          boolrecv          boolsend          0         0          0
17      bytea                  byteain         byteaout         bytearecv         byteasend         0         0          0
18      char                   charin          charout          charrecv          charsend          0         0          0
19      name                   namein          nameout          namerecv          namesend          0         0          0
20      int8                   int8in          int8out          int8recv          int8send          0         0          0
21      int2                   int2in          int2out          int2recv          int2send          0         0          0
22      int2vector             int2vectorin    int2vectorout    int2vectorrecv    int2vectorsend    0         0          0
23      int4                   int4in          int4out          int4recv          int4send          0         0          0
24      regproc                regprocin       regprocout       regprocrecv       regprocsend       0         0          0
25      text                   textin          textout          textrecv          textsend          0         0          0
26      oid                    oidin           oidout           oidrecv           oidsend           0         0          0
30      oidvector              oidvectorin     oidvectorout     oidvectorrecv     oidvectorsend     0         0          0
700     float4                 float4in        float4out        float4recv        float4send        0         0          0
701     float8                 float8in        float8out        float8recv        float8send        0         0          0
705     unknown                unknownin       unknownout       unknownrecv       unknownsend       0         0          0
869     inet                   inetin          inetout          inetrecv          inetsend          0         0          0
1000    _bool                  array_in        array_out        array_recv        array_send        0         0          0
1001    _bytea                 array_in        array_out        array_recv        array_send        0         0          0
1002    _char                  array_in        array_out        array_recv        array_send        0         0          0
1003    _name                  array_in        array_out        array_recv        array_send        0         0          0
1005    _int2                  array_in        array_out        array_recv        array_send        0         0          0
1006    _int2vector            array_in        array_out        array_recv        array_send        0         0          0
1007    _int4                  array_in        array_out        array_recv        array_send        0         0          0
1008    _regproc               array_in        array_out        array_recv        array_send        0         0          0
1009    _text                  array_in        array_out        array_recv        array_send        0         0          0
1013    _oidvector             array_in        array_out        array_recv        array_send        0         0          0
1014    _bpchar                array_in        array_out        array_recv        array_send        0         0          0
1015    _varchar               array_in        array_out        array_recv        array_send        0         0          0
1016    _int8                  array_in        array_out        array_recv        array_send        0         0          0
1021    _float4                array_in        array_out        array_recv        array_send        0         0          0
1022    _float8                array_in        array_out        array_recv        array_send        0         0          0
1028    _oid                   array_in        array_out        array_recv        array_send        0         0          0
1041    _inet                  array_in        array_out        array_recv        array_send        0         0          0
1042    bpchar                 bpcharin        bpcharout        bpcharrecv        bpcharsend        0         0          0
1043    varchar                varcharin       varcharout       varcharrecv       varcharsend       0         0          0
1082    date                   date_in         date_out         date_recv         date_send         0         0          0
1083    time                   time_in         time_out         time_recv         time_send         0         0          0
1114    timestamp              timestamp_in    timestamp_out    timestamp_recv    timestamp_send    0         0          0
1115    _timestamp             array_in        array_out        array_recv        array_send        0         0          0
1182    _date                  array_in        array_out        array_recv        array_send        0         0          0
1183    _time                  array_in        array_out        array_recv        array_send        0         0          0
1184    timestamptz            timestamptz_in  timestamptz_out  timestamptz_recv  timestamptz_send  0         0          0
1185    _timestamptz           array_in        array_out        array_recv        array_send        0         0          0
1186    interval               interval_in     interval_out     interval_recv     interval_send     0         0          0
1187    _interval              array_in        array_out        array_recv        array_send        0         0          0
1231    _numeric               array_in        array_out        array_recv        array_send        0         0          0
1266    timetz                 timetz_in       timetz_out       timetz_recv       timetz_send       0         0          0
1270    _timetz                array_in        array_out        array_recv        array_send        0         0          0
1560    bit                    bit_in          bit_out          bit_recv          bit_send          0         0          0
1561    _bit                   array_in        array_out        array_recv        array_send        0         0          0
1562    varbit                 varbit_in       varbit_out       varbit_recv       varbit_send       0         0          0
1563    _varbit                array_in        array_out        array_recv        array_send        0         0          0
1700    numeric                numeric_in      numeric_out      numeric_recv      numeric_send      0         0          0
1790    refcursor              refcursorin     refcursorout     refcursorrecv     refcursorsend     0         0          0
2201    _refcursor             array_in        array_out        array_recv        array_send        0         0          0
2202    regprocedure           regprocedurein  regprocedureout  regprocedurerecv  regproceduresend  0         0          0
2205    regclass               regclassin      regclassout      regclassrecv      regclasssend      0         0          0
2206    regtype                regtypein       regtypeout       regtyperecv       regtypesend       0         0          0
2207    _regprocedure          array_in        array_out        array_recv        array_send        0         0          0
2210    _regclass              array_in        array_out        array_recv        array_send        0         0          0
2211    _regtype               array_in        array_out        array_recv        array_send        0         0          0
2249    record                 record_in       record_out       record_recv       record_send       0         0          0
2277    anyarray               anyarray_in     anyarray_out     anyarray_recv     anyarray_send     0         0          0
2278    void                   voidin          voidout          voidrecv          voidsend          0         0          0
2279    trigger                -               -                -                 -                 0         0          0
2283    anyelement             anyelement_in   anyelement_out   anyelement_recv   anyelement_send   0         0          0
2287    _record                array_in        array_out        array_recv        array_send        0         0          0
2950    uuid                   uuid_in         uuid_out         uuid_recv         uuid_send         0         0          0
2951    _uuid                  array_in        array_out        array_recv        array_send        0         0          0
3220    pg_lsn                 pg_lsnin        pg_lsnout        pg_lsnrecv        pg_lsnsend        0         0          0
3221    _pg_lsn                array_in        array_out        array_recv        array_send        0         0          0
3614    tsvector               tsvectorin      tsvectorout      tsvectorrecv      tsvectorsend      0         0          0
3615    tsquery                tsqueryin       tsqueryout       tsqueryrecv       tsquerysend       0         0          0
3643    _tsvector              array_in        array_out        array_recv        array_send        0         0          0
3645    _tsquery               array_in        array_out        array_recv        array_send        0         0          0
3802    jsonb                  jsonb_in        jsonb_out        jsonb_recv        jsonb_send        0         0          0
3807    _jsonb                 array_in        array_out        array_recv        array_send        0         0          0
4089    regnamespace           regnamespacein  regnamespaceout  regnamespacerecv  regnamespacesend  0         0          0
4090    _regnamespace          array_in        array_out        array_recv        array_send        0         0          0
4096    regrole                regrolein       regroleout       regrolerecv       regrolesend       0         0          0
4097    _regrole               array_in        array_out        array_recv        array_send        0         0          0
90000   geometry               geometry_in     geometry_out     geometry_recv     geometry_send     0         0          0
90001   _geometry              array_in        array_out        array_recv        array_send        0         0          0
90002   geography              geography_in    geography_out    geography_recv    geography_send    0         0          0
90003   _geography             array_in        array_out        array_recv        array_send        0         0          0
90004   box2d                  box2d_in        box2d_out        box2d_recv        box2d_send        0         0          0
90005   _box2d                 array_in        array_out        array_recv        array_send        0         0          0
90006   vector                 vectorin        vectorout        vectorrecv        vectorsend        0         0          0
90007   _vector                array_in        array_out        array_recv        array_send        0         0          0
100110  t1                     record_in       record_out       record_recv       record_send       0         0          0
100111  t1_m_seq               record_in       record_out       record_recv       record_send       0         0          0
100112  t1_n_seq               record_in       record_out       record_recv       record_send       0         0          0
100113  t2                     record_in       record_out       record_recv       record_send       0         0          0
100114  t3                     record_in       record_out       record_recv       record_send       0         0          0
100115  v1                     record_in       record_out       record_recv       record_send       0         0          0
100116  t4                     record_in       record_out       record_recv       record_send       0         0          0
100117  t5                     record_in       record_out       record_recv       record_send       0         0          0
100118  mytype                 enum_in         enum_out         enum_recv         enum_send         0         0          0
100119  _mytype                array_in        array_out        array_recv        array_send        0         0          0
100120  t6                     record_in       record_out       record_recv       record_send       0         0          0
100121  mv1                    record_in       record_out       record_recv       record_send       0         0          0
100128  t_with_pk_seq          record_in       record_out       record_recv       record_send       0         0          0
100129  t_with_pk_seq_a_seq    record_in       record_out       record_recv       record_send       0         0          0
100130  source_table           record_in       record_out       record_recv       record_send       0         0          0
100131  depend_view            record_in       record_out       record_recv       record_send       0         0          0
100132  view_dependingon_view  record_in       record_out       record_recv       record_send       0         0          0
100133  newtype1               enum_in         enum_out         enum_recv         enum_send         0         0          0
100134  _newtype1              array_in        array_out        array_recv        array_send        0         0          0
100135  newtype2               enum_in         enum_out         enum_recv         enum_send         0         0          0
100136  _newtype2              array_in        array_out        array_recv        array_send        0         0          0

query OTTTBOI colnames
SELECT oid, typname, typalign, typstorage, typnotnull, typbasetype, typtypmod
FROM pg_catalog.pg_type
WHERE oid < 4194967002 -- exclude implicit types for virtual tables
ORDER BY oid
----
oid     typname                typalign  typstorage  typnotnull  typbasetype  typtypmod
16      bool                   NULL      NULL        false       0            -1
17      bytea                  NULL      NULL        false       0            -1
18      char                   NULL      NULL        false       0            -1
19      name                   NULL      NULL        false       0            -1
20      int8                   NULL      NULL        false       0            -1
21      int2                   NULL      NULL        false       0            -1
22      int2vector             NULL      NULL        false       0            -1
23      int4                   NULL      NULL        false       0            -1
24      regproc                NULL      NULL        false       0            -1
25      text                   NULL      NULL        false       0            -1
26      oid                    NULL      NULL        false       0            -1
30      oidvector              NULL      NULL        false       0            -1
700     float4                 NULL      NULL        false       0            -1
701     float8                 NULL      NULL        false       0            -1
705     unknown                NULL      NULL        false       0            -1
869     inet                   NULL      NULL        false       0            -1
1000    _bool                  NULL      NULL        false       0            -1
1001    _bytea                 NULL      NULL        false       0            -1
1002    _char                  NULL      NULL        false       0            -1
1003    _name                  NULL      NULL        false       0            -1
1005    _int2                  NULL      NULL        false       0            -1
1006    _int2vector            NULL      NULL        false       0            -1
1007    _int4                  NULL      NULL        false       0            -1
1008    _regproc               NULL      NULL        false       0            -1
1009    _text                  NULL      NULL        false       0            -1
1013    _oidvector             NULL      NULL        false       0            -1
1014    _bpchar                NULL      NULL        false       0            -1
1015    _varchar               NULL      NULL        false       0            -1
1016    _int8                  NULL      NULL        false       0            -1
1021    _float4                NULL      NULL        false       0            -1
1022    _float8                NULL      NULL        false       0            -1
1028    _oid                   NULL      NULL        false       0            -1
1041    _inet                  NULL      NULL        false       0            -1
1042    bpchar                 NULL      NULL        false       0            -1
1043    varchar                NULL      NULL        false       0            -1
1082    date                   NULL      NULL        false       0            -1
1083    time                   NULL      NULL        false       0            -1
1114    timestamp              NULL      NULL        false       0            -1
1115    _timestamp             NULL      NULL        false       0            -1
1182    _date                  NULL      NULL        false       0            -1
1183    _time                  NULL      NULL        false       0            -1
1184    timestamptz            NULL      NULL        false       0            -1
1185    _timestamptz           NULL      NULL        false       0            -1
1186    interval               NULL      NULL        false       0            -1
1187    _interval              NULL      NULL        false       0            -1
1231    _numeric               NULL      NULL        false       0            -1
1266    timetz                 NULL      NULL        false       0            -1
1270    _timetz                NULL      NULL        false       0            -1
1560    bit                    NULL      NULL        false       0            -1
1561    _bit                   NULL      NULL        false       0            -1
1562    varbit                 NULL      NULL        false       0            -1
1563    _varbit                NULL      NULL        false       0            -1
1700    numeric                NULL      NULL        false       0            -1
1790    refcursor              NULL      NULL        false       0            -1
2201    _refcursor             NULL      NULL        false       0            -1
2202    regprocedure           NULL      NULL        false       0            -1
2205    regclass               NULL      NULL        false       0            -1
2206    regtype                NULL      NULL        false       0            -1
2207    _regprocedure          NULL      NULL        false       0            -1
2210    _regclass              NULL      NULL        false       0            -1
2211    _regtype               NULL      NULL        false       0            -1
2249    record                 NULL      NULL        false       0            -1
2277    anyarray               NULL      NULL        false       0            -1
2278    void                   NULL      NULL        false       0            -1
2279    trigger                NULL      NULL        false       0            -1
2283    anyelement             NULL      NULL        false       0            -1
2287    _record                NULL      NULL        false       0            -1
2950    uuid                   NULL      NULL        false       0            -1
2951    _uuid                  NULL      NULL        false       0            -1
3220    pg_lsn                 NULL      NULL        false       0            -1
3221    _pg_lsn                NULL      NULL        false       0            -1
3614    tsvector               NULL      NULL        false       0            -1
3615    tsquery                NULL      NULL        false       0            -1
3643    _tsvector              NULL      NULL        false       0            -1
3645    _tsquery               NULL      NULL        false       0            -1
3802    jsonb                  NULL      NULL        false       0            -1
3807    _jsonb                 NULL      NULL        false       0            -1
4089    regnamespace           NULL      NULL        false       0            -1
4090    _regnamespace          NULL      NULL        false       0            -1
4096    regrole                NULL      NULL        false       0            -1
4097    _regrole               NULL      NULL        false       0            -1
90000   geometry               NULL      NULL        false       0            -1
90001   _geometry              NULL      NULL        false       0            -1
90002   geography              NULL      NULL        false       0            -1
90003   _geography             NULL      NULL        false       0            -1
90004   box2d                  NULL      NULL        false       0            -1
90005   _box2d                 NULL      NULL        false       0            -1
90006   vector                 NULL      NULL        false       0            -1
90007   _vector                NULL      NULL        false       0            -1
100110  t1                     NULL      NULL        false       0            -1
100111  t1_m_seq               NULL      NULL        false       0            -1
100112  t1_n_seq               NULL      NULL        false       0            -1
100113  t2                     NULL      NULL        false       0            -1
100114  t3                     NULL      NULL        false       0            -1
100115  v1                     NULL      NULL        false       0            -1
100116  t4                     NULL      NULL        false       0            -1
100117  t5                     NULL      NULL        false       0            -1
100118  mytype                 NULL      NULL        false       0            -1
100119  _mytype                NULL      NULL        false       0            -1
100120  t6                     NULL      NULL        false       0            -1
100121  mv1                    NULL      NULL        false       0            -1
100128  t_with_pk_seq          NULL      NULL        false       0            -1
100129  t_with_pk_seq_a_seq    NULL      NULL        false       0            -1
100130  source_table           NULL      NULL        false       0            -1
100131  depend_view            NULL      NULL        false       0            -1
100132  view_dependingon_view  NULL      NULL        false       0            -1
100133  newtype1               NULL      NULL        false       0            -1
100134  _newtype1              NULL      NULL        false       0            -1
100135  newtype2               NULL      NULL        false       0            -1
100136  _newtype2              NULL      NULL        false       0            -1

query OTIOTTT colnames
SELECT oid, typname, typndims, typcollation, typdefaultbin, typdefault, typacl
FROM pg_catalog.pg_type
WHERE oid < 4194967002 -- exclude implicit types for virtual tables
ORDER BY oid
----
oid     typname                typndims  typcollation  typdefaultbin  typdefault  typacl
16      bool                   0         0             NULL           NULL        NULL
17      bytea                  0         0             NULL           NULL        NULL
18      char                   0         3403232968    NULL           NULL        NULL
19      name                   0         3403232968    NULL           NULL        NULL
20      int8                   0         0             NULL           NULL        NULL
21      int2                   0         0             NULL           NULL        NULL
22      int2vector             0         0             NULL           NULL        NULL
23      int4                   0         0             NULL           NULL        NULL
24      regproc                0         0             NULL           NULL        NULL
25      text                   0         3403232968    NULL           NULL        NULL
26      oid                    0         0             NULL           NULL        NULL
30      oidvector              0         0             NULL           NULL        NULL
700     float4                 0         0             NULL           NULL        NULL
701     float8                 0         0             NULL           NULL        NULL
705     unknown                0         0             NULL           NULL        NULL
869     inet                   0         0             NULL           NULL        NULL
1000    _bool                  0         0             NULL           NULL        NULL
1001    _bytea                 0         0             NULL           NULL        NULL
1002    _char                  0         3403232968    NULL           NULL        NULL
1003    _name                  0         3403232968    NULL           NULL        NULL
1005    _int2                  0         0             NULL           NULL        NULL
1006    _int2vector            0         0             NULL           NULL        NULL
1007    _int4                  0         0             NULL           NULL        NULL
1008    _regproc               0         0             NULL           NULL        NULL
1009    _text                  0         3403232968    NULL           NULL        NULL
1013    _oidvector             0         0             NULL           NULL        NULL
1014    _bpchar                0         3403232968    NULL           NULL        NULL
1015    _varchar               0         3403232968    NULL           NULL        NULL
1016    _int8                  0         0             NULL           NULL        NULL
1021    _float4                0         0             NULL           NULL        NULL
1022    _float8                0         0             NULL           NULL        NULL
1028    _oid                   0         0             NULL           NULL        NULL
1041    _inet                  0         0             NULL           NULL        NULL
1042    bpchar                 0         3403232968    NULL           NULL        NULL
1043    varchar                0         3403232968    NULL           NULL        NULL
1082    date                   0         0             NULL           NULL        NULL
1083    time                   0         0             NULL           NULL        NULL
1114    timestamp              0         0             NULL           NULL        NULL
1115    _timestamp             0         0             NULL           NULL        NULL
1182    _date                  0         0             NULL           NULL        NULL
1183    _time                  0         0             NULL           NULL        NULL
1184    timestamptz            0         0             NULL           NULL        NULL
1185    _timestamptz           0         0             NULL           NULL        NULL
1186    interval               0         0             NULL           NULL        NULL
1187    _interval              0         0             NULL           NULL        NULL
1231    _numeric               0         0             NULL           NULL        NULL
1266    timetz                 0         0             NULL           NULL        NULL
1270    _timetz                0         0             NULL           NULL        NULL
1560    bit                    0         0             NULL           NULL        NULL
1561    _bit                   0         0             NULL           NULL        NULL
1562    varbit                 0         0             NULL           NULL        NULL
1563    _varbit                0         0             NULL           NULL        NULL
1700    numeric                0         0             NULL           NULL        NULL
1790    refcursor              0         0             NULL           NULL        NULL
2201    _refcursor             0         0             NULL           NULL        NULL
2202    regprocedure           0         0             NULL           NULL        NULL
2205    regclass               0         0             NULL           NULL        NULL
2206    regtype                0         0             NULL           NULL        NULL
2207    _regprocedure          0         0             NULL           NULL        NULL
2210    _regclass              0         0             NULL           NULL        NULL
2211    _regtype               0         0             NULL           NULL        NULL
2249    record                 0         0             NULL           NULL        NULL
2277    anyarray               0         3403232968    NULL           NULL        NULL
2278    void                   0         0             NULL           NULL        NULL
2279    trigger                0         0             NULL           NULL        NULL
2283    anyelement             0         0             NULL           NULL        NULL
2287    _record                0         0             NULL           NULL        NULL
2950    uuid                   0         0             NULL           NULL        NULL
2951    _uuid                  0         0             NULL           NULL        NULL
3220    pg_lsn                 0         0             NULL           NULL        NULL
3221    _pg_lsn                0         0             NULL           NULL        NULL
3614    tsvector               0         0             NULL           NULL        NULL
3615    tsquery                0         0             NULL           NULL        NULL
3643    _tsvector              0         0             NULL           NULL        NULL
3645    _tsquery               0         0             NULL           NULL        NULL
3802    jsonb                  0         0             NULL           NULL        NULL
3807    _jsonb                 0         0             NULL           NULL        NULL
4089    regnamespace           0         0             NULL           NULL        NULL
4090    _regnamespace          0         0             NULL           NULL        NULL
4096    regrole                0         0             NULL           NULL        NULL
4097    _regrole               0         0             NULL           NULL        NULL
90000   geometry               0         0             NULL           NULL        NULL
90001   _geometry              0         0             NULL           NULL        NULL
90002   geography              0         0             NULL           NULL        NULL
90003   _geography             0         0             NULL           NULL        NULL
90004   box2d                  0         0             NULL           NULL        NULL
90005   _box2d                 0         0             NULL           NULL        NULL
90006   vector                 0         0             NULL           NULL        NULL
90007   _vector                0         0             NULL           NULL        NULL
100110  t1                     0         0             NULL           NULL        NULL
100111  t1_m_seq               0         0             NULL           NULL        NULL
100112  t1_n_seq               0         0             NULL           NULL        NULL
100113  t2                     0         0             NULL           NULL        NULL
100114  t3                     0         0             NULL           NULL        NULL
100115  v1                     0         0             NULL           NULL        NULL
100116  t4                     0         0             NULL           NULL        NULL
100117  t5                     0         0             NULL           NULL        NULL
100118  mytype                 0         0             NULL           NULL        NULL
100119  _mytype                0         0             NULL           NULL        NULL
100120  t6                     0         0             NULL           NULL        NULL
100121  mv1                    0         0             NULL           NULL        NULL
100128  t_with_pk_seq          0         0             NULL           NULL        NULL
100129  t_with_pk_seq_a_seq    0         0             NULL           NULL        NULL
100130  source_table           0         0             NULL           NULL        NULL
100131  depend_view            0         0             NULL           NULL        NULL
100132  view_dependingon_view  0         0             NULL           NULL        NULL
100133  newtype1               0         0             NULL           NULL        NULL
100134  _newtype1              0         0             NULL           NULL        NULL
100135  newtype2               0         0             NULL           NULL        NULL
100136  _newtype2              0         0             NULL           NULL        NULL

user testuser

# Should be globally visible
query OTOIBT colnames
SELECT oid, typname, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type WHERE typname = 'uuid'
ORDER BY oid
----
oid    typname  typowner  typlen  typbyval  typtype
2950   uuid     NULL      16      true      b

user root

query OTOOIBT colnames
SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type
WHERE oid = 1000
----
oid   typname  typnamespace  typowner  typlen  typbyval  typtype
1000  _bool    4294967095    NULL      -1      false     b

query OTOOIBT colnames
SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type
WHERE typname = 'newtype1'
----
oid     typname   typnamespace  typowner    typlen  typbyval  typtype
100133  newtype1  109           1546506610  -1      false     e

query OTOOIBT colnames
SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type
WHERE oid = 1
----
oid     typname        typnamespace  typowner  typlen  typbyval  typtype

query OTOOIBT colnames
SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type
WHERE oid = 9999999
----
oid     typname        typnamespace  typowner  typlen  typbyval  typtype

query OTOOIBT colnames
SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type
WHERE typname = 'source_table'
----
oid     typname       typnamespace  typowner    typlen  typbyval  typtype
100130  source_table  109           1546506610  -1      false     c

let $sourceid
SELECT oid
FROM pg_catalog.pg_type
WHERE typname = 'source_table'

## Exercise the virtual index on pg_type.oid.
query OTOOIBT colnames
SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type
WHERE oid = $sourceid
----
oid     typname       typnamespace  typowner    typlen  typbyval  typtype
100130  source_table  109           1546506610  -1      false     c

let $vtableSourceId
SELECT oid
FROM pg_catalog.pg_type
WHERE typname = 'pg_proc'

# Verify that the index on pg_type works for virtual tables OIDs.
query OTOOIBT colnames
SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type
WHERE oid = $vtableSourceId
----
oid         typname  typnamespace  typowner    typlen  typbyval  typtype
4294967045  pg_proc  4294967095    3233629770  -1      false     c

## pg_catalog.pg_proc

query TOTOOTTO colnames,rowsort
SELECT proname, pronamespace, nspname, proowner, prolang, procost, prorows, provariadic
FROM pg_catalog.pg_proc p
JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE proname='substring'
----
proname    pronamespace  nspname     proowner  prolang  procost  prorows  provariadic
substring  4294967095    pg_catalog  NULL      12       NULL     NULL     0
substring  4294967095    pg_catalog  NULL      12       NULL     NULL     0
substring  4294967095    pg_catalog  NULL      12       NULL     NULL     0
substring  4294967095    pg_catalog  NULL      12       NULL     NULL     0
substring  4294967095    pg_catalog  NULL      12       NULL     NULL     0
substring  4294967095    pg_catalog  NULL      12       NULL     NULL     0
substring  4294967095    pg_catalog  NULL      12       NULL     NULL     0
substring  4294967095    pg_catalog  NULL      12       NULL     NULL     0

query TTBB colnames,rowsort
SELECT proname, prokind, prosecdef, proleakproof
FROM pg_catalog.pg_proc
WHERE proname='substring'
----
proname    prokind  prosecdef  proleakproof
substring  f        false      false
substring  f        false      false
substring  f        false      false
substring  f        false      false
substring  f        false      false
substring  f        false      false
substring  f        false      false
substring  f        false      false

query TBBTT colnames,rowsort
SELECT proname, proisstrict, proretset, provolatile, proparallel
FROM pg_catalog.pg_proc
WHERE proname='substring'
----
proname    proisstrict  proretset  provolatile  proparallel
substring  true         false      i            NULL
substring  true         false      i            NULL
substring  true         false      i            NULL
substring  true         false      i            NULL
substring  true         false      i            NULL
substring  true         false      i            NULL
substring  true         false      i            NULL
substring  true         false      i            NULL

# Verify that proretset is true for set-returning functions.
query OTBT
SELECT oid, proname, proretset, prorettype FROM pg_catalog.pg_proc
WHERE proname IN (
  'jsonb_object_keys', 'generate_series', 'generate_subscripts',
  'json_populate_recordset', 'unnest', 'json_each'
) ORDER BY 1
----
317  generate_series          true  20
318  generate_series          true  20
319  generate_series          true  1114
320  generate_series          true  1184
326  unnest                   true  2283
327  unnest                   true  2283
330  generate_subscripts      true  20
331  generate_subscripts      true  20
332  generate_subscripts      true  20
338  jsonb_object_keys        true  25
339  json_each                true  2283
345  json_populate_recordset  true  2283

query TIIOTTTT colnames
SELECT proname, pronargs, pronargdefaults, prorettype, proargtypes, proallargtypes, proargmodes, proargdefaults
FROM pg_catalog.pg_proc
WHERE proname='substring'
ORDER BY proargtypes
----
proname    pronargs  pronargdefaults  prorettype  proargtypes  proallargtypes  proargmodes  proargdefaults
substring  2         0                17          17 20        NULL            NULL         NULL
substring  3         0                17          17 20 20     NULL            NULL         NULL
substring  2         0                25          25 20        NULL            NULL         NULL
substring  3         0                25          25 20 20     NULL            NULL         NULL
substring  2         0                25          25 25        NULL            NULL         NULL
substring  3         0                25          25 25 25     NULL            NULL         NULL
substring  2         0                1562        1562 20      NULL            NULL         NULL
substring  3         0                1562        1562 20 20   NULL            NULL         NULL

query TTTTTT colnames,rowsort
SELECT proname, protrftypes, prosrc, probin, proconfig, proacl
FROM pg_catalog.pg_proc
WHERE proname='substring'
----
proname    protrftypes  prosrc     probin  proconfig  proacl
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL

query TTOTOT colnames
SELECT proname, prosrc, pronamespace, nspname, prorettype, proargtypes
FROM pg_catalog.pg_proc p
JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid
WHERE proname='pb_to_json'
ORDER BY p.oid
----
proname     prosrc      pronamespace  nspname        prorettype  proargtypes
pb_to_json  pb_to_json  4294967295    crdb_internal  3802        25 17
pb_to_json  pb_to_json  4294967295    crdb_internal  3802        25 17 16
pb_to_json  pb_to_json  4294967295    crdb_internal  3802        25 17 16 16

query TTOTOT colnames
SELECT proname, prosrc, pronamespace, nspname, prorettype, proargtypes
FROM pg_catalog.pg_proc p
JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid
WHERE proname='_pg_char_max_length'
ORDER BY p.oid
----
proname              prosrc               pronamespace  nspname             prorettype  proargtypes
_pg_char_max_length  _pg_char_max_length  4294967182    information_schema  20          26 23

query TOIOTTB colnames
SELECT proname, provariadic, pronargs, prorettype, proargtypes, proargmodes, proisstrict
FROM pg_catalog.pg_proc
WHERE proname='least'
----
proname  provariadic  pronargs  prorettype  proargtypes  proargmodes  proisstrict
least    2283         1         2283        2283         {v}          false

query TOIOTTB colnames
SELECT proname, provariadic, pronargs, prorettype, proargtypes, proargmodes, proisstrict
FROM pg_catalog.pg_proc
WHERE proname='json_extract_path'
----
proname            provariadic  pronargs  prorettype  proargtypes  proargmodes  proisstrict
json_extract_path  25           2         3802        3802 25      {i,v}        true

query TOIOTTB colnames
SELECT proname, provariadic, pronargs, prorettype, proargtypes, proargmodes, proisstrict
FROM pg_catalog.pg_proc
WHERE proname='json_extract_path_text'
----
proname                 provariadic  pronargs  prorettype  proargtypes  proargmodes  proisstrict
json_extract_path_text  25           2         25          3802 25      {i,v}        true

user testuser

# Should be globally visible
query TOIOTT colnames
SELECT proname, provariadic, pronargs, prorettype, proargtypes, proargmodes
FROM pg_catalog.pg_proc
WHERE proname='json_extract_path'
----
proname            provariadic  pronargs  prorettype  proargtypes  proargmodes
json_extract_path  25           2         3802        3802 25      {i,v}

user root

statement ok
CREATE PROCEDURE pro() LANGUAGE SQL AS 'SELECT 1'

query TT rowsort
SELECT DISTINCT proname, prokind FROM pg_catalog.pg_proc
WHERE proname IN ('lag', 'abs', 'max', 'pro')
----
abs  f
lag  w
max  a
pro  p

statement ok
DROP PROCEDURE pro

## pg_catalog.pg_range
query IIIIII colnames
SELECT * from pg_catalog.pg_range
----
rngtypid  rngsubtype  rngcollation  rngsubopc  rngcanonical  rngsubdiff

## pg_catalog.pg_roles

query OTBBBBBBB colnames
SELECT oid, rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcatupdate, rolcanlogin, rolreplication
FROM pg_catalog.pg_roles
ORDER BY rolname
----
oid         rolname   rolsuper  rolinherit  rolcreaterole  rolcreatedb  rolcatupdate  rolcanlogin  rolreplication
2310524507  admin     true      true        true           true         false         true         false
3233629770  node      true      true        true           true         false         false        false
1546506610  root      true      true        true           true         false         true         false
2264919399  testuser  false     true        false          false        false         true         false

query OTITTBT colnames
SELECT oid, rolname, rolconnlimit, rolpassword, rolvaliduntil, rolbypassrls, rolconfig
FROM pg_catalog.pg_roles
ORDER BY rolname
----
oid         rolname   rolconnlimit  rolpassword  rolvaliduntil  rolbypassrls  rolconfig
2310524507  admin     -1            ********     NULL           false         NULL
3233629770  node      -1            ********     NULL           false         NULL
1546506610  root      -1            ********     NULL           false         NULL
2264919399  testuser  -1            ********     NULL           false         NULL

# Regression test for https://github.com/cockroachdb/cockroach/issues/136230.
# Reading from pg_roles should never read any data that is not in the role
# membership cache. We simulate a stale cache by inserting a user directly into
# system.users.
statement ok
INSERT INTO system.users (username, user_id) VALUES ('non_cached_user', 12345)

query T
SELECT rolname
FROM pg_catalog.pg_roles
ORDER BY rolname
----
admin
node
root
testuser

statement ok
DELETE FROM system.users WHERE username = 'non_cached_user'

## pg_catalog.pg_auth_members

query OOOB colnames
SELECT roleid, member, grantor, admin_option
FROM pg_catalog.pg_auth_members
----
roleid      member      grantor  admin_option
2310524507  1546506610  NULL     true

## pg_catalog.pg_user

query TOBBBBTTT colnames
SELECT usename, usesysid, usecreatedb, usesuper, userepl, usebypassrls, passwd, valuntil, useconfig
FROM pg_catalog.pg_user
ORDER BY usename
----
usename   usesysid    usecreatedb  usesuper  userepl  usebypassrls  passwd    valuntil  useconfig
node      3233629770  true         true      false    false         ********  NULL      NULL
root      1546506610  true         true      false    false         ********  NULL      NULL
testuser  2264919399  false        false     false    false         ********  NULL      NULL

## pg_catalog.pg_description

statement ok
CREATE TABLE testtable(x INT, INDEX testtable_x_idx(x));
COMMENT ON TABLE testtable IS 'mycomment1';
COMMENT ON COLUMN testtable.x IS 'mycomment2';
COMMENT ON INDEX testtable_x_idx IS 'mycomment3';
CREATE SCHEMA testschema; COMMENT ON SCHEMA testschema IS 'mycomment4';

query TOOIT colnames
SELECT c.relname, d.objoid, d.classoid, d.objsubid, regexp_replace(description, e'\n.*', '') AS description
  FROM pg_catalog.pg_description d
JOIN pg_catalog.pg_class c ON d.classoid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid AND n.nspname = 'pg_catalog'
WHERE
   (c.relname = 'pg_proc' AND d.objoid IN (SELECT oid FROM pg_catalog.pg_proc WHERE proname = 'abs'))
OR (c.relname = 'pg_class' AND d.objoid IN (SELECT oid FROM pg_catalog.pg_class WHERE relname IN ('pg_user', 'testtable')))
OR (c.relname = 'pg_class' AND d.objoid IN (SELECT oid FROM pg_catalog.pg_class WHERE relname IN ('pg_user', 'testtable', 'testtable_x_idx')))
OR (c.relname = 'pg_namespace' AND d.objoid IN (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = 'testschema'))
ORDER BY d.objoid, description
----
relname       objoid      classoid    objsubid  description
pg_class      138         4294967083  0         mycomment1
pg_class      138         4294967083  1         mycomment2
pg_namespace  139         4294967054  0         mycomment4
pg_proc       738         4294967045  0         Calculates the absolute value of `val`.
pg_proc       739         4294967045  0         Calculates the absolute value of `val`.
pg_proc       740         4294967045  0         Calculates the absolute value of `val`.
pg_class      385466581   4294967083  0         mycomment3
pg_class      4294966967  4294967083  0         database users

## pg_catalog.pg_shdescription

statement ok
COMMENT ON DATABASE defaultdb IS 'mydbcomment'

query OOT colnames
SELECT objoid, classoid, description FROM pg_catalog.pg_shdescription
----
objoid  classoid    description
100     4294967077  mydbcomment

## pg_catalog.pg_event_trigger

query TTOOTTT colnames
SELECT * FROM pg_catalog.pg_event_trigger
----
evtname  evtevent  evtowner  evtfoid  evtenabled  evttags  oid

## pg_catalog.pg_extension
query OTOOBTTT colnames
SELECT * FROM pg_catalog.pg_extension
----
oid  extname  extowner  extnamespace  extrelocatable  extversion  extconfig  extcondition

## pg_catalog.pg_stat_activity

query OTIOTTTTITTTTTTTIITTT colnames
SELECT * FROM pg_catalog.pg_stat_activity
----
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  backend_type  leader_pid

query TTBTTTB colnames,rowsort
SHOW COLUMNS FROM pg_catalog.pg_stat_activity
----
column_name       data_type    is_nullable  column_default  generation_expression  indices  is_hidden
datid             OID          true         NULL            ·                      {}       false
datname           NAME         true         NULL            ·                      {}       false
pid               INT8         true         NULL            ·                      {}       false
usesysid          OID          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
client_port       INT8         true         NULL            ·                      {}       false
backend_start     TIMESTAMPTZ  true         NULL            ·                      {}       false
xact_start        TIMESTAMPTZ  true         NULL            ·                      {}       false
query_start       TIMESTAMPTZ  true         NULL            ·                      {}       false
state_change      TIMESTAMPTZ  true         NULL            ·                      {}       false
wait_event_type   STRING       true         NULL            ·                      {}       false
wait_event        STRING       true         NULL            ·                      {}       false
state             STRING       true         NULL            ·                      {}       false
backend_xid       INT8         true         NULL            ·                      {}       false
backend_xmin      INT8         true         NULL            ·                      {}       false
query             STRING       true         NULL            ·                      {}       false
backend_type      STRING       true         NULL            ·                      {}       false
leader_pid        INT4         true         NULL            ·                      {}       false


## pg_catalog.pg_settings

statement ok
SET DATABASE = test

# We filter here because 'optimizer' will be different depending on which
# configuration this logic test is running in, and session ID will vary.
skipif config 3node-tenant-default-configs
query TTTTTT colnames
SELECT
  name, setting, category, short_desc, extra_desc, vartype
FROM
  pg_catalog.pg_settings
WHERE
  name NOT IN ('optimizer', 'crdb_version', 'session_id', 'distsql_workmem', 'copy_fast_path_enabled', 'direct_columnar_scans_enabled', 'multiple_active_portals_enabled')
ORDER BY name
----
name                                                       setting             category  short_desc  extra_desc  vartype
allow_ordinal_column_references                            off                 NULL      NULL        NULL        string
allow_role_memberships_to_change_during_transaction        off                 NULL      NULL        NULL        string
alter_primary_region_super_region_override                 off                 NULL      NULL        NULL        string
always_distribute_full_scans                               off                 NULL      NULL        NULL        string
application_name                                           ·                   NULL      NULL        NULL        string
authentication_method                                      cert-password       NULL      NULL        NULL        string
autocommit_before_ddl                                      off                 NULL      NULL        NULL        string
avoid_buffering                                            off                 NULL      NULL        NULL        string
avoid_full_table_scans_in_mutations                        on                  NULL      NULL        NULL        string
backslash_quote                                            safe_encoding       NULL      NULL        NULL        string
bypass_pcr_reader_catalog_aost                             off                 NULL      NULL        NULL        string
bytea_output                                               hex                 NULL      NULL        NULL        string
check_function_bodies                                      on                  NULL      NULL        NULL        string
client_encoding                                            UTF8                NULL      NULL        NULL        string
client_min_messages                                        notice              NULL      NULL        NULL        string
close_cursors_at_commit                                    on                  NULL      NULL        NULL        string
copy_from_atomic_enabled                                   on                  NULL      NULL        NULL        string
copy_from_retries_enabled                                  on                  NULL      NULL        NULL        string
copy_num_retries_per_batch                                 5                   NULL      NULL        NULL        string
copy_transaction_quality_of_service                        background          NULL      NULL        NULL        string
copy_write_pipelining_enabled                              off                 NULL      NULL        NULL        string
cost_scans_with_default_col_size                           off                 NULL      NULL        NULL        string
database                                                   test                NULL      NULL        NULL        string
datestyle                                                  ISO, MDY            NULL      NULL        NULL        string
deadlock_timeout                                           0                   NULL      NULL        NULL        string
declare_cursor_statement_timeout_enabled                   on                  NULL      NULL        NULL        string
default_int_size                                           8                   NULL      NULL        NULL        string
default_table_access_method                                heap                NULL      NULL        NULL        string
default_tablespace                                         ·                   NULL      NULL        NULL        string
default_text_search_config                                 pg_catalog.english  NULL      NULL        NULL        string
default_transaction_isolation                              serializable        NULL      NULL        NULL        string
default_transaction_priority                               normal              NULL      NULL        NULL        string
default_transaction_quality_of_service                     regular             NULL      NULL        NULL        string
default_transaction_read_only                              off                 NULL      NULL        NULL        string
default_transaction_use_follower_reads                     off                 NULL      NULL        NULL        string
default_with_oids                                          off                 NULL      NULL        NULL        string
descriptor_validation                                      on                  NULL      NULL        NULL        string
disable_changefeed_replication                             off                 NULL      NULL        NULL        string
disable_hoist_projection_in_join_limitation                off                 NULL      NULL        NULL        string
disable_partially_distributed_plans                        off                 NULL      NULL        NULL        string
disable_plan_gists                                         off                 NULL      NULL        NULL        string
disable_vec_union_eager_cancellation                       off                 NULL      NULL        NULL        string
disallow_full_table_scans                                  off                 NULL      NULL        NULL        string
distribute_group_by_row_count_threshold                    1000                NULL      NULL        NULL        string
distribute_join_row_count_threshold                        1000                NULL      NULL        NULL        string
distribute_scan_row_count_threshold                        10000               NULL      NULL        NULL        string
distribute_sort_row_count_threshold                        1000                NULL      NULL        NULL        string
distsql                                                    off                 NULL      NULL        NULL        string
distsql_plan_gateway_bias                                  2                   NULL      NULL        NULL        string
enable_auto_rehoming                                       off                 NULL      NULL        NULL        string
enable_create_stats_using_extremes                         on                  NULL      NULL        NULL        string
enable_create_stats_using_extremes_bool_enum               off                 NULL      NULL        NULL        string
enable_durable_locking_for_serializable                    off                 NULL      NULL        NULL        string
enable_experimental_alter_column_type_general              off                 NULL      NULL        NULL        string
enable_implicit_fk_locking_for_serializable                off                 NULL      NULL        NULL        string
enable_implicit_select_for_update                          on                  NULL      NULL        NULL        string
enable_implicit_transaction_for_batch_statements           on                  NULL      NULL        NULL        string
enable_insert_fast_path                                    on                  NULL      NULL        NULL        string
enable_multiple_modifications_of_table                     off                 NULL      NULL        NULL        string
enable_multiregion_placement_policy                        off                 NULL      NULL        NULL        string
enable_seqscan                                             on                  NULL      NULL        NULL        string
enable_shared_locking_for_serializable                     off                 NULL      NULL        NULL        string
enable_super_regions                                       off                 NULL      NULL        NULL        string
enable_zigzag_join                                         off                 NULL      NULL        NULL        string
enforce_home_region                                        off                 NULL      NULL        NULL        string
enforce_home_region_follower_reads_enabled                 off                 NULL      NULL        NULL        string
escape_string_warning                                      on                  NULL      NULL        NULL        string
expect_and_ignore_not_visible_columns_in_copy              off                 NULL      NULL        NULL        string
experimental_enable_implicit_column_partitioning           off                 NULL      NULL        NULL        string
experimental_enable_temp_tables                            off                 NULL      NULL        NULL        string
experimental_enable_unique_without_index_constraints       on                  NULL      NULL        NULL        string
experimental_hash_group_join_enabled                       off                 NULL      NULL        NULL        string
extra_float_digits                                         1                   NULL      NULL        NULL        string
force_savepoint_restart                                    off                 NULL      NULL        NULL        string
foreign_key_cascades_limit                                 10000               NULL      NULL        NULL        string
idle_in_transaction_session_timeout                        0                   NULL      NULL        NULL        string
idle_session_timeout                                       0                   NULL      NULL        NULL        string
index_join_streamer_batch_size                             8.0 MiB             NULL      NULL        NULL        string
index_recommendations_enabled                              off                 NULL      NULL        NULL        string
inject_retry_errors_enabled                                off                 NULL      NULL        NULL        string
inject_retry_errors_on_commit_enabled                      off                 NULL      NULL        NULL        string
integer_datetimes                                          on                  NULL      NULL        NULL        string
intervalstyle                                              postgres            NULL      NULL        NULL        string
is_superuser                                               on                  NULL      NULL        NULL        string
join_reader_index_join_strategy_batch_size                 4.0 MiB             NULL      NULL        NULL        string
join_reader_no_ordering_strategy_batch_size                2.0 MiB             NULL      NULL        NULL        string
join_reader_ordering_strategy_batch_size                   100 KiB             NULL      NULL        NULL        string
large_full_scan_rows                                       0                   NULL      NULL        NULL        string
lc_collate                                                 C.UTF-8             NULL      NULL        NULL        string
lc_ctype                                                   C.UTF-8             NULL      NULL        NULL        string
lc_messages                                                C.UTF-8             NULL      NULL        NULL        string
lc_monetary                                                C.UTF-8             NULL      NULL        NULL        string
lc_numeric                                                 C.UTF-8             NULL      NULL        NULL        string
lc_time                                                    C.UTF-8             NULL      NULL        NULL        string
legacy_varchar_typing                                      off                 NULL      NULL        NULL        string
locality                                                   region=test,dc=dc1  NULL      NULL        NULL        string
locality_optimized_partitioned_index_scan                  on                  NULL      NULL        NULL        string
lock_timeout                                               0                   NULL      NULL        NULL        string
log_timezone                                               UTC                 NULL      NULL        NULL        string
max_connections                                            -1                  NULL      NULL        NULL        string
max_identifier_length                                      128                 NULL      NULL        NULL        string
max_index_keys                                             32                  NULL      NULL        NULL        string
max_prepared_transactions                                  2147483647          NULL      NULL        NULL        string
max_retries_for_read_committed                             10                  NULL      NULL        NULL        string
node_id                                                    1                   NULL      NULL        NULL        string
null_ordered_last                                          off                 NULL      NULL        NULL        string
on_update_rehome_row_enabled                               on                  NULL      NULL        NULL        string
opt_split_scan_limit                                       2048                NULL      NULL        NULL        string
optimizer_always_use_histograms                            on                  NULL      NULL        NULL        string
optimizer_hoist_uncorrelated_equality_subqueries           on                  NULL      NULL        NULL        string
optimizer_merge_joins_enabled                              on                  NULL      NULL        NULL        string
optimizer_prove_implication_with_virtual_computed_columns  on                  NULL      NULL        NULL        string
optimizer_push_limit_into_project_filtered_scan            on                  NULL      NULL        NULL        string
optimizer_push_offset_into_index_join                      on                  NULL      NULL        NULL        string
optimizer_use_conditional_hoist_fix                        on                  NULL      NULL        NULL        string
optimizer_use_forecasts                                    on                  NULL      NULL        NULL        string
optimizer_use_histograms                                   on                  NULL      NULL        NULL        string
optimizer_use_improved_computed_column_filters_derivation  on                  NULL      NULL        NULL        string
optimizer_use_improved_disjunction_stats                   on                  NULL      NULL        NULL        string
optimizer_use_improved_distinct_on_limit_hint_costing      on                  NULL      NULL        NULL        string
optimizer_use_improved_join_elimination                    on                  NULL      NULL        NULL        string
optimizer_use_improved_multi_column_selectivity_estimate   on                  NULL      NULL        NULL        string
optimizer_use_improved_split_disjunction_for_joins         on                  NULL      NULL        NULL        string
optimizer_use_improved_trigram_similarity_selectivity      on                  NULL      NULL        NULL        string
optimizer_use_improved_zigzag_join_costing                 on                  NULL      NULL        NULL        string
optimizer_use_limit_ordering_for_streaming_group_by        on                  NULL      NULL        NULL        string
optimizer_use_lock_op_for_serializable                     off                 NULL      NULL        NULL        string
optimizer_use_merged_partial_statistics                    off                 NULL      NULL        NULL        string
optimizer_use_multicol_stats                               on                  NULL      NULL        NULL        string
optimizer_use_not_visible_indexes                          off                 NULL      NULL        NULL        string
optimizer_use_polymorphic_parameter_fix                    on                  NULL      NULL        NULL        string
optimizer_use_provided_ordering_fix                        on                  NULL      NULL        NULL        string
optimizer_use_trigram_similarity_optimization              on                  NULL      NULL        NULL        string
optimizer_use_virtual_computed_column_stats                on                  NULL      NULL        NULL        string
override_multi_region_zone_config                          off                 NULL      NULL        NULL        string
parallelize_multi_key_lookup_joins_enabled                 off                 NULL      NULL        NULL        string
password_encryption                                        scram-sha-256       NULL      NULL        NULL        string
pg_trgm.similarity_threshold                               0.3                 NULL      NULL        NULL        string
plan_cache_mode                                            auto                NULL      NULL        NULL        string
plpgsql_use_strict_into                                    off                 NULL      NULL        NULL        string
prefer_lookup_joins_for_fks                                off                 NULL      NULL        NULL        string
prepared_statements_cache_size                             0 B                 NULL      NULL        NULL        string
propagate_input_ordering                                   off                 NULL      NULL        NULL        string
recursion_depth_limit                                      1000                NULL      NULL        NULL        string
reorder_joins_limit                                        8                   NULL      NULL        NULL        string
require_explicit_primary_keys                              off                 NULL      NULL        NULL        string
results_buffer_size                                        524288              NULL      NULL        NULL        string
role                                                       none                NULL      NULL        NULL        string
row_security                                               off                 NULL      NULL        NULL        string
search_path                                                "$user", public     NULL      NULL        NULL        string
serial_normalization                                       rowid               NULL      NULL        NULL        string
server_encoding                                            UTF8                NULL      NULL        NULL        string
server_version                                             13.0.0              NULL      NULL        NULL        string
server_version_num                                         130000              NULL      NULL        NULL        string
show_primary_key_constraint_on_not_visible_columns         on                  NULL      NULL        NULL        string
sql_safe_updates                                           off                 NULL      NULL        NULL        string
ssl                                                        on                  NULL      NULL        NULL        string
standard_conforming_strings                                on                  NULL      NULL        NULL        string
statement_timeout                                          0                   NULL      NULL        NULL        string
streamer_always_maintain_ordering                          off                 NULL      NULL        NULL        string
streamer_enabled                                           on                  NULL      NULL        NULL        string
streamer_head_of_line_only_fraction                        0.8                 NULL      NULL        NULL        string
streamer_in_order_eager_memory_usage_fraction              0.5                 NULL      NULL        NULL        string
streamer_out_of_order_eager_memory_usage_fraction          0.8                 NULL      NULL        NULL        string
strict_ddl_atomicity                                       off                 NULL      NULL        NULL        string
stub_catalog_tables                                        on                  NULL      NULL        NULL        string
synchronize_seqscans                                       on                  NULL      NULL        NULL        string
synchronous_commit                                         on                  NULL      NULL        NULL        string
system_identity                                            root                NULL      NULL        NULL        string
testing_optimizer_cost_perturbation                        0                   NULL      NULL        NULL        string
testing_optimizer_disable_rule_probability                 0                   NULL      NULL        NULL        string
testing_optimizer_inject_panics                            off                 NULL      NULL        NULL        string
testing_optimizer_random_seed                              0                   NULL      NULL        NULL        string
testing_vectorize_inject_panics                            off                 NULL      NULL        NULL        string
timezone                                                   UTC                 NULL      NULL        NULL        string
tracing                                                    off                 NULL      NULL        NULL        string
transaction_isolation                                      serializable        NULL      NULL        NULL        string
transaction_priority                                       normal              NULL      NULL        NULL        string
transaction_read_only                                      off                 NULL      NULL        NULL        string
transaction_rows_read_err                                  0                   NULL      NULL        NULL        string
transaction_rows_read_log                                  0                   NULL      NULL        NULL        string
transaction_rows_written_err                               0                   NULL      NULL        NULL        string
transaction_rows_written_log                               0                   NULL      NULL        NULL        string
transaction_status                                         NoTxn               NULL      NULL        NULL        string
transaction_timeout                                        0                   NULL      NULL        NULL        string
troubleshooting_mode                                       off                 NULL      NULL        NULL        string
unbounded_parallel_scans                                   off                 NULL      NULL        NULL        string
unconstrained_non_covering_index_scan_enabled              off                 NULL      NULL        NULL        string
unsafe_allow_triggers_modifying_cascades                   off                 NULL      NULL        NULL        string
use_declarative_schema_changer                             on                  NULL      NULL        NULL        string
variable_inequality_lookup_join_enabled                    on                  NULL      NULL        NULL        string
vectorize                                                  on                  NULL      NULL        NULL        string
xmloption                                                  content             NULL      NULL        NULL        string

skipif config 3node-tenant-default-configs
query TTTTTTT colnames
SELECT
  name, setting, unit, context, enumvals, boot_val, reset_val
FROM
  pg_catalog.pg_settings
WHERE
  name NOT IN ('optimizer', 'crdb_version', 'session_id', 'distsql_workmem', 'copy_fast_path_enabled', 'direct_columnar_scans_enabled', 'multiple_active_portals_enabled')
ORDER BY name
----
name                                                       setting             unit  context  enumvals  boot_val            reset_val
allow_ordinal_column_references                            off                 NULL  user     NULL      off                 off
allow_role_memberships_to_change_during_transaction        off                 NULL  user     NULL      off                 off
alter_primary_region_super_region_override                 off                 NULL  user     NULL      off                 off
always_distribute_full_scans                               off                 NULL  user     NULL      off                 off
application_name                                           ·                   NULL  user     NULL      ·                   ·
authentication_method                                      cert-password       NULL  user     NULL      cert-password       cert-password
autocommit_before_ddl                                      off                 NULL  user     NULL      off                 off
avoid_buffering                                            off                 NULL  user     NULL      off                 off
avoid_full_table_scans_in_mutations                        on                  NULL  user     NULL      on                  on
backslash_quote                                            safe_encoding       NULL  user     NULL      safe_encoding       safe_encoding
bypass_pcr_reader_catalog_aost                             off                 NULL  user     NULL      off                 off
bytea_output                                               hex                 NULL  user     NULL      hex                 hex
check_function_bodies                                      on                  NULL  user     NULL      on                  on
client_encoding                                            UTF8                NULL  user     NULL      UTF8                UTF8
client_min_messages                                        notice              NULL  user     NULL      notice              notice
close_cursors_at_commit                                    on                  NULL  user     NULL      on                  on
copy_from_atomic_enabled                                   on                  NULL  user     NULL      on                  on
copy_from_retries_enabled                                  on                  NULL  user     NULL      on                  on
copy_num_retries_per_batch                                 5                   NULL  user     NULL      5                   5
copy_transaction_quality_of_service                        background          NULL  user     NULL      background          background
copy_write_pipelining_enabled                              off                 NULL  user     NULL      off                 off
cost_scans_with_default_col_size                           off                 NULL  user     NULL      off                 off
database                                                   test                NULL  user     NULL      ·                   test
datestyle                                                  ISO, MDY            NULL  user     NULL      ISO, MDY            ISO, MDY
deadlock_timeout                                           0                   NULL  user     NULL      0s                  0s
declare_cursor_statement_timeout_enabled                   on                  NULL  user     NULL      on                  on
default_int_size                                           8                   NULL  user     NULL      8                   8
default_table_access_method                                heap                NULL  user     NULL      heap                heap
default_tablespace                                         ·                   NULL  user     NULL      ·                   ·
default_text_search_config                                 pg_catalog.english  NULL  user     NULL      pg_catalog.english  pg_catalog.english
default_transaction_isolation                              serializable        NULL  user     NULL      serializable        serializable
default_transaction_priority                               normal              NULL  user     NULL      normal              normal
default_transaction_quality_of_service                     regular             NULL  user     NULL      regular             regular
default_transaction_read_only                              off                 NULL  user     NULL      off                 off
default_transaction_use_follower_reads                     off                 NULL  user     NULL      off                 off
default_with_oids                                          off                 NULL  user     NULL      off                 off
descriptor_validation                                      on                  NULL  user     NULL      on                  on
disable_changefeed_replication                             off                 NULL  user     NULL      off                 off
disable_hoist_projection_in_join_limitation                off                 NULL  user     NULL      off                 off
disable_partially_distributed_plans                        off                 NULL  user     NULL      off                 off
disable_plan_gists                                         off                 NULL  user     NULL      off                 off
disable_vec_union_eager_cancellation                       off                 NULL  user     NULL      off                 off
disallow_full_table_scans                                  off                 NULL  user     NULL      off                 off
distribute_group_by_row_count_threshold                    1000                NULL  user     NULL      1000                1000
distribute_join_row_count_threshold                        1000                NULL  user     NULL      1000                1000
distribute_scan_row_count_threshold                        10000               NULL  user     NULL      10000               10000
distribute_sort_row_count_threshold                        1000                NULL  user     NULL      1000                1000
distsql                                                    off                 NULL  user     NULL      off                 off
distsql_plan_gateway_bias                                  2                   NULL  user     NULL      2                   2
enable_auto_rehoming                                       off                 NULL  user     NULL      off                 off
enable_create_stats_using_extremes                         on                  NULL  user     NULL      on                  on
enable_create_stats_using_extremes_bool_enum               off                 NULL  user     NULL      off                 off
enable_durable_locking_for_serializable                    off                 NULL  user     NULL      off                 off
enable_experimental_alter_column_type_general              off                 NULL  user     NULL      off                 off
enable_implicit_fk_locking_for_serializable                off                 NULL  user     NULL      off                 off
enable_implicit_select_for_update                          on                  NULL  user     NULL      on                  on
enable_implicit_transaction_for_batch_statements           on                  NULL  user     NULL      on                  on
enable_insert_fast_path                                    on                  NULL  user     NULL      on                  on
enable_multiple_modifications_of_table                     off                 NULL  user     NULL      off                 off
enable_multiregion_placement_policy                        off                 NULL  user     NULL      off                 off
enable_seqscan                                             on                  NULL  user     NULL      on                  on
enable_shared_locking_for_serializable                     off                 NULL  user     NULL      off                 off
enable_super_regions                                       off                 NULL  user     NULL      off                 off
enable_zigzag_join                                         off                 NULL  user     NULL      off                 off
enforce_home_region                                        off                 NULL  user     NULL      off                 off
enforce_home_region_follower_reads_enabled                 off                 NULL  user     NULL      off                 off
escape_string_warning                                      on                  NULL  user     NULL      on                  on
expect_and_ignore_not_visible_columns_in_copy              off                 NULL  user     NULL      off                 off
experimental_enable_implicit_column_partitioning           off                 NULL  user     NULL      off                 off
experimental_enable_temp_tables                            off                 NULL  user     NULL      off                 off
experimental_enable_unique_without_index_constraints       on                  NULL  user     NULL      off                 off
experimental_hash_group_join_enabled                       off                 NULL  user     NULL      off                 off
extra_float_digits                                         1                   NULL  user     NULL      1                   1
force_savepoint_restart                                    off                 NULL  user     NULL      off                 off
foreign_key_cascades_limit                                 10000               NULL  user     NULL      10000               10000
idle_in_transaction_session_timeout                        0                   NULL  user     NULL      0s                  0s
idle_session_timeout                                       0                   NULL  user     NULL      0s                  0s
index_join_streamer_batch_size                             8.0 MiB             NULL  user     NULL      8.0 MiB             8.0 MiB
index_recommendations_enabled                              off                 NULL  user     NULL      on                  false
inject_retry_errors_enabled                                off                 NULL  user     NULL      off                 off
inject_retry_errors_on_commit_enabled                      off                 NULL  user     NULL      off                 off
integer_datetimes                                          on                  NULL  user     NULL      on                  on
intervalstyle                                              postgres            NULL  user     NULL      postgres            postgres
is_superuser                                               on                  NULL  user     NULL      on                  on
join_reader_index_join_strategy_batch_size                 4.0 MiB             NULL  user     NULL      4.0 MiB             4.0 MiB
join_reader_no_ordering_strategy_batch_size                2.0 MiB             NULL  user     NULL      2.0 MiB             2.0 MiB
join_reader_ordering_strategy_batch_size                   100 KiB             NULL  user     NULL      100 KiB             100 KiB
large_full_scan_rows                                       0                   NULL  user     NULL      0                   0
lc_collate                                                 C.UTF-8             NULL  user     NULL      C.UTF-8             C.UTF-8
lc_ctype                                                   C.UTF-8             NULL  user     NULL      C.UTF-8             C.UTF-8
lc_messages                                                C.UTF-8             NULL  user     NULL      C.UTF-8             C.UTF-8
lc_monetary                                                C.UTF-8             NULL  user     NULL      C.UTF-8             C.UTF-8
lc_numeric                                                 C.UTF-8             NULL  user     NULL      C.UTF-8             C.UTF-8
lc_time                                                    C.UTF-8             NULL  user     NULL      C.UTF-8             C.UTF-8
legacy_varchar_typing                                      off                 NULL  user     NULL      off                 off
locality                                                   region=test,dc=dc1  NULL  user     NULL      region=test,dc=dc1  region=test,dc=dc1
locality_optimized_partitioned_index_scan                  on                  NULL  user     NULL      on                  on
lock_timeout                                               0                   NULL  user     NULL      0s                  0s
log_timezone                                               UTC                 NULL  user     NULL      UTC                 UTC
max_connections                                            -1                  NULL  user     NULL      -1                  -1
max_identifier_length                                      128                 NULL  user     NULL      128                 128
max_index_keys                                             32                  NULL  user     NULL      32                  32
max_prepared_transactions                                  2147483647          NULL  user     NULL      2147483647          2147483647
max_retries_for_read_committed                             10                  NULL  user     NULL      10                  10
node_id                                                    1                   NULL  user     NULL      1                   1
null_ordered_last                                          off                 NULL  user     NULL      off                 off
on_update_rehome_row_enabled                               on                  NULL  user     NULL      on                  on
opt_split_scan_limit                                       2048                NULL  user     NULL      2048                2048
optimizer_always_use_histograms                            on                  NULL  user     NULL      on                  on
optimizer_hoist_uncorrelated_equality_subqueries           on                  NULL  user     NULL      on                  on
optimizer_merge_joins_enabled                              on                  NULL  user     NULL      on                  on
optimizer_prove_implication_with_virtual_computed_columns  on                  NULL  user     NULL      on                  on
optimizer_push_limit_into_project_filtered_scan            on                  NULL  user     NULL      on                  on
optimizer_push_offset_into_index_join                      on                  NULL  user     NULL      on                  on
optimizer_use_conditional_hoist_fix                        on                  NULL  user     NULL      on                  on
optimizer_use_forecasts                                    on                  NULL  user     NULL      on                  on
optimizer_use_histograms                                   on                  NULL  user     NULL      on                  on
optimizer_use_improved_computed_column_filters_derivation  on                  NULL  user     NULL      on                  on
optimizer_use_improved_disjunction_stats                   on                  NULL  user     NULL      on                  on
optimizer_use_improved_distinct_on_limit_hint_costing      on                  NULL  user     NULL      on                  on
optimizer_use_improved_join_elimination                    on                  NULL  user     NULL      on                  on
optimizer_use_improved_multi_column_selectivity_estimate   on                  NULL  user     NULL      on                  on
optimizer_use_improved_split_disjunction_for_joins         on                  NULL  user     NULL      on                  on
optimizer_use_improved_trigram_similarity_selectivity      on                  NULL  user     NULL      on                  on
optimizer_use_improved_zigzag_join_costing                 on                  NULL  user     NULL      on                  on
optimizer_use_limit_ordering_for_streaming_group_by        on                  NULL  user     NULL      on                  on
optimizer_use_lock_op_for_serializable                     off                 NULL  user     NULL      off                 off
optimizer_use_merged_partial_statistics                    off                 NULL  user     NULL      off                 off
optimizer_use_multicol_stats                               on                  NULL  user     NULL      on                  on
optimizer_use_not_visible_indexes                          off                 NULL  user     NULL      off                 off
optimizer_use_polymorphic_parameter_fix                    on                  NULL  user     NULL      on                  on
optimizer_use_provided_ordering_fix                        on                  NULL  user     NULL      on                  on
optimizer_use_trigram_similarity_optimization              on                  NULL  user     NULL      on                  on
optimizer_use_virtual_computed_column_stats                on                  NULL  user     NULL      on                  on
override_multi_region_zone_config                          off                 NULL  user     NULL      off                 off
parallelize_multi_key_lookup_joins_enabled                 off                 NULL  user     NULL      off                 off
password_encryption                                        scram-sha-256       NULL  user     NULL      scram-sha-256       scram-sha-256
pg_trgm.similarity_threshold                               0.3                 NULL  user     NULL      0.3                 0.3
plan_cache_mode                                            auto                NULL  user     NULL      auto                auto
plpgsql_use_strict_into                                    off                 NULL  user     NULL      off                 off
prefer_lookup_joins_for_fks                                off                 NULL  user     NULL      off                 off
prepared_statements_cache_size                             0 B                 NULL  user     NULL      0 B                 0 B
propagate_input_ordering                                   off                 NULL  user     NULL      off                 off
recursion_depth_limit                                      1000                NULL  user     NULL      1000                1000
reorder_joins_limit                                        8                   NULL  user     NULL      8                   8
require_explicit_primary_keys                              off                 NULL  user     NULL      off                 off
results_buffer_size                                        524288              NULL  user     NULL      524288              524288
role                                                       none                NULL  user     NULL      none                none
row_security                                               off                 NULL  user     NULL      off                 off
search_path                                                "$user", public     NULL  user     NULL      "$user", public     "$user", public
serial_normalization                                       rowid               NULL  user     NULL      rowid               rowid
server_encoding                                            UTF8                NULL  user     NULL      UTF8                UTF8
server_version                                             13.0.0              NULL  user     NULL      13.0.0              13.0.0
server_version_num                                         130000              NULL  user     NULL      130000              130000
show_primary_key_constraint_on_not_visible_columns         on                  NULL  user     NULL      on                  on
sql_safe_updates                                           off                 NULL  user     NULL      off                 off
ssl                                                        on                  NULL  user     NULL      on                  on
standard_conforming_strings                                on                  NULL  user     NULL      on                  on
statement_timeout                                          0                   NULL  user     NULL      0s                  0s
streamer_always_maintain_ordering                          off                 NULL  user     NULL      off                 off
streamer_enabled                                           on                  NULL  user     NULL      on                  on
streamer_head_of_line_only_fraction                        0.8                 NULL  user     NULL      0.8                 0.8
streamer_in_order_eager_memory_usage_fraction              0.5                 NULL  user     NULL      0.5                 0.5
streamer_out_of_order_eager_memory_usage_fraction          0.8                 NULL  user     NULL      0.8                 0.8
strict_ddl_atomicity                                       off                 NULL  user     NULL      off                 off
stub_catalog_tables                                        on                  NULL  user     NULL      on                  on
synchronize_seqscans                                       on                  NULL  user     NULL      on                  on
synchronous_commit                                         on                  NULL  user     NULL      on                  on
system_identity                                            root                NULL  user     NULL      root                root
testing_optimizer_cost_perturbation                        0                   NULL  user     NULL      0                   0
testing_optimizer_disable_rule_probability                 0                   NULL  user     NULL      0                   0
testing_optimizer_inject_panics                            off                 NULL  user     NULL      off                 off
testing_optimizer_random_seed                              0                   NULL  user     NULL      0                   0
testing_vectorize_inject_panics                            off                 NULL  user     NULL      off                 off
timezone                                                   UTC                 NULL  user     NULL      UTC                 UTC
tracing                                                    off                 NULL  user     NULL      off                 off
transaction_isolation                                      serializable        NULL  user     NULL      serializable        serializable
transaction_priority                                       normal              NULL  user     NULL      normal              normal
transaction_read_only                                      off                 NULL  user     NULL      off                 off
transaction_rows_read_err                                  0                   NULL  user     NULL      0                   0
transaction_rows_read_log                                  0                   NULL  user     NULL      0                   0
transaction_rows_written_err                               0                   NULL  user     NULL      0                   0
transaction_rows_written_log                               0                   NULL  user     NULL      0                   0
transaction_status                                         NoTxn               NULL  user     NULL      NoTxn               NoTxn
transaction_timeout                                        0                   NULL  user     NULL      0s                  0s
troubleshooting_mode                                       off                 NULL  user     NULL      off                 off
unbounded_parallel_scans                                   off                 NULL  user     NULL      off                 off
unconstrained_non_covering_index_scan_enabled              off                 NULL  user     NULL      off                 off
unsafe_allow_triggers_modifying_cascades                   off                 NULL  user     NULL      off                 off
use_declarative_schema_changer                             on                  NULL  user     NULL      on                  on
variable_inequality_lookup_join_enabled                    on                  NULL  user     NULL      on                  on
vectorize                                                  on                  NULL  user     NULL      on                  on
xmloption                                                  content             NULL  user     NULL      content             content

query TTTTTT colnames,rowsort
SELECT name, source, min_val, max_val, sourcefile, sourceline FROM pg_catalog.pg_settings
----
name                                                       source  min_val  max_val  sourcefile  sourceline
allow_ordinal_column_references                            NULL    NULL     NULL     NULL        NULL
allow_role_memberships_to_change_during_transaction        NULL    NULL     NULL     NULL        NULL
alter_primary_region_super_region_override                 NULL    NULL     NULL     NULL        NULL
always_distribute_full_scans                               NULL    NULL     NULL     NULL        NULL
application_name                                           NULL    NULL     NULL     NULL        NULL
authentication_method                                      NULL    NULL     NULL     NULL        NULL
autocommit_before_ddl                                      NULL    NULL     NULL     NULL        NULL
avoid_buffering                                            NULL    NULL     NULL     NULL        NULL
avoid_full_table_scans_in_mutations                        NULL    NULL     NULL     NULL        NULL
backslash_quote                                            NULL    NULL     NULL     NULL        NULL
bypass_pcr_reader_catalog_aost                             NULL    NULL     NULL     NULL        NULL
bytea_output                                               NULL    NULL     NULL     NULL        NULL
check_function_bodies                                      NULL    NULL     NULL     NULL        NULL
client_encoding                                            NULL    NULL     NULL     NULL        NULL
client_min_messages                                        NULL    NULL     NULL     NULL        NULL
close_cursors_at_commit                                    NULL    NULL     NULL     NULL        NULL
copy_fast_path_enabled                                     NULL    NULL     NULL     NULL        NULL
copy_from_atomic_enabled                                   NULL    NULL     NULL     NULL        NULL
copy_from_retries_enabled                                  NULL    NULL     NULL     NULL        NULL
copy_num_retries_per_batch                                 NULL    NULL     NULL     NULL        NULL
copy_transaction_quality_of_service                        NULL    NULL     NULL     NULL        NULL
copy_write_pipelining_enabled                              NULL    NULL     NULL     NULL        NULL
cost_scans_with_default_col_size                           NULL    NULL     NULL     NULL        NULL
crdb_version                                               NULL    NULL     NULL     NULL        NULL
database                                                   NULL    NULL     NULL     NULL        NULL
datestyle                                                  NULL    NULL     NULL     NULL        NULL
deadlock_timeout                                           NULL    NULL     NULL     NULL        NULL
declare_cursor_statement_timeout_enabled                   NULL    NULL     NULL     NULL        NULL
default_int_size                                           NULL    NULL     NULL     NULL        NULL
default_table_access_method                                NULL    NULL     NULL     NULL        NULL
default_tablespace                                         NULL    NULL     NULL     NULL        NULL
default_text_search_config                                 NULL    NULL     NULL     NULL        NULL
default_transaction_isolation                              NULL    NULL     NULL     NULL        NULL
default_transaction_priority                               NULL    NULL     NULL     NULL        NULL
default_transaction_quality_of_service                     NULL    NULL     NULL     NULL        NULL
default_transaction_read_only                              NULL    NULL     NULL     NULL        NULL
default_transaction_use_follower_reads                     NULL    NULL     NULL     NULL        NULL
default_with_oids                                          NULL    NULL     NULL     NULL        NULL
descriptor_validation                                      NULL    NULL     NULL     NULL        NULL
direct_columnar_scans_enabled                              NULL    NULL     NULL     NULL        NULL
disable_changefeed_replication                             NULL    NULL     NULL     NULL        NULL
disable_hoist_projection_in_join_limitation                NULL    NULL     NULL     NULL        NULL
disable_partially_distributed_plans                        NULL    NULL     NULL     NULL        NULL
disable_plan_gists                                         NULL    NULL     NULL     NULL        NULL
disable_vec_union_eager_cancellation                       NULL    NULL     NULL     NULL        NULL
disallow_full_table_scans                                  NULL    NULL     NULL     NULL        NULL
distribute_group_by_row_count_threshold                    NULL    NULL     NULL     NULL        NULL
distribute_join_row_count_threshold                        NULL    NULL     NULL     NULL        NULL
distribute_scan_row_count_threshold                        NULL    NULL     NULL     NULL        NULL
distribute_sort_row_count_threshold                        NULL    NULL     NULL     NULL        NULL
distsql                                                    NULL    NULL     NULL     NULL        NULL
distsql_plan_gateway_bias                                  NULL    NULL     NULL     NULL        NULL
distsql_workmem                                            NULL    NULL     NULL     NULL        NULL
enable_auto_rehoming                                       NULL    NULL     NULL     NULL        NULL
enable_create_stats_using_extremes                         NULL    NULL     NULL     NULL        NULL
enable_create_stats_using_extremes_bool_enum               NULL    NULL     NULL     NULL        NULL
enable_durable_locking_for_serializable                    NULL    NULL     NULL     NULL        NULL
enable_experimental_alter_column_type_general              NULL    NULL     NULL     NULL        NULL
enable_implicit_fk_locking_for_serializable                NULL    NULL     NULL     NULL        NULL
enable_implicit_select_for_update                          NULL    NULL     NULL     NULL        NULL
enable_implicit_transaction_for_batch_statements           NULL    NULL     NULL     NULL        NULL
enable_insert_fast_path                                    NULL    NULL     NULL     NULL        NULL
enable_multiple_modifications_of_table                     NULL    NULL     NULL     NULL        NULL
enable_multiregion_placement_policy                        NULL    NULL     NULL     NULL        NULL
enable_seqscan                                             NULL    NULL     NULL     NULL        NULL
enable_shared_locking_for_serializable                     NULL    NULL     NULL     NULL        NULL
enable_super_regions                                       NULL    NULL     NULL     NULL        NULL
enable_zigzag_join                                         NULL    NULL     NULL     NULL        NULL
enforce_home_region                                        NULL    NULL     NULL     NULL        NULL
enforce_home_region_follower_reads_enabled                 NULL    NULL     NULL     NULL        NULL
escape_string_warning                                      NULL    NULL     NULL     NULL        NULL
expect_and_ignore_not_visible_columns_in_copy              NULL    NULL     NULL     NULL        NULL
experimental_enable_implicit_column_partitioning           NULL    NULL     NULL     NULL        NULL
experimental_enable_temp_tables                            NULL    NULL     NULL     NULL        NULL
experimental_enable_unique_without_index_constraints       NULL    NULL     NULL     NULL        NULL
experimental_hash_group_join_enabled                       NULL    NULL     NULL     NULL        NULL
extra_float_digits                                         NULL    NULL     NULL     NULL        NULL
force_savepoint_restart                                    NULL    NULL     NULL     NULL        NULL
foreign_key_cascades_limit                                 NULL    NULL     NULL     NULL        NULL
idle_in_transaction_session_timeout                        NULL    NULL     NULL     NULL        NULL
idle_session_timeout                                       NULL    NULL     NULL     NULL        NULL
index_join_streamer_batch_size                             NULL    NULL     NULL     NULL        NULL
index_recommendations_enabled                              NULL    NULL     NULL     NULL        NULL
inject_retry_errors_enabled                                NULL    NULL     NULL     NULL        NULL
inject_retry_errors_on_commit_enabled                      NULL    NULL     NULL     NULL        NULL
integer_datetimes                                          NULL    NULL     NULL     NULL        NULL
intervalstyle                                              NULL    NULL     NULL     NULL        NULL
is_superuser                                               NULL    NULL     NULL     NULL        NULL
join_reader_index_join_strategy_batch_size                 NULL    NULL     NULL     NULL        NULL
join_reader_no_ordering_strategy_batch_size                NULL    NULL     NULL     NULL        NULL
join_reader_ordering_strategy_batch_size                   NULL    NULL     NULL     NULL        NULL
large_full_scan_rows                                       NULL    NULL     NULL     NULL        NULL
lc_collate                                                 NULL    NULL     NULL     NULL        NULL
lc_ctype                                                   NULL    NULL     NULL     NULL        NULL
lc_messages                                                NULL    NULL     NULL     NULL        NULL
lc_monetary                                                NULL    NULL     NULL     NULL        NULL
lc_numeric                                                 NULL    NULL     NULL     NULL        NULL
lc_time                                                    NULL    NULL     NULL     NULL        NULL
legacy_varchar_typing                                      NULL    NULL     NULL     NULL        NULL
locality                                                   NULL    NULL     NULL     NULL        NULL
locality_optimized_partitioned_index_scan                  NULL    NULL     NULL     NULL        NULL
lock_timeout                                               NULL    NULL     NULL     NULL        NULL
log_timezone                                               NULL    NULL     NULL     NULL        NULL
max_connections                                            NULL    NULL     NULL     NULL        NULL
max_identifier_length                                      NULL    NULL     NULL     NULL        NULL
max_index_keys                                             NULL    NULL     NULL     NULL        NULL
max_prepared_transactions                                  NULL    NULL     NULL     NULL        NULL
max_retries_for_read_committed                             NULL    NULL     NULL     NULL        NULL
multiple_active_portals_enabled                            NULL    NULL     NULL     NULL        NULL
node_id                                                    NULL    NULL     NULL     NULL        NULL
null_ordered_last                                          NULL    NULL     NULL     NULL        NULL
on_update_rehome_row_enabled                               NULL    NULL     NULL     NULL        NULL
opt_split_scan_limit                                       NULL    NULL     NULL     NULL        NULL
optimizer                                                  NULL    NULL     NULL     NULL        NULL
optimizer_always_use_histograms                            NULL    NULL     NULL     NULL        NULL
optimizer_hoist_uncorrelated_equality_subqueries           NULL    NULL     NULL     NULL        NULL
optimizer_merge_joins_enabled                              NULL    NULL     NULL     NULL        NULL
optimizer_prove_implication_with_virtual_computed_columns  NULL    NULL     NULL     NULL        NULL
optimizer_push_limit_into_project_filtered_scan            NULL    NULL     NULL     NULL        NULL
optimizer_push_offset_into_index_join                      NULL    NULL     NULL     NULL        NULL
optimizer_use_conditional_hoist_fix                        NULL    NULL     NULL     NULL        NULL
optimizer_use_forecasts                                    NULL    NULL     NULL     NULL        NULL
optimizer_use_histograms                                   NULL    NULL     NULL     NULL        NULL
optimizer_use_improved_computed_column_filters_derivation  NULL    NULL     NULL     NULL        NULL
optimizer_use_improved_disjunction_stats                   NULL    NULL     NULL     NULL        NULL
optimizer_use_improved_distinct_on_limit_hint_costing      NULL    NULL     NULL     NULL        NULL
optimizer_use_improved_join_elimination                    NULL    NULL     NULL     NULL        NULL
optimizer_use_improved_multi_column_selectivity_estimate   NULL    NULL     NULL     NULL        NULL
optimizer_use_improved_split_disjunction_for_joins         NULL    NULL     NULL     NULL        NULL
optimizer_use_improved_trigram_similarity_selectivity      NULL    NULL     NULL     NULL        NULL
optimizer_use_improved_zigzag_join_costing                 NULL    NULL     NULL     NULL        NULL
optimizer_use_limit_ordering_for_streaming_group_by        NULL    NULL     NULL     NULL        NULL
optimizer_use_lock_op_for_serializable                     NULL    NULL     NULL     NULL        NULL
optimizer_use_merged_partial_statistics                    NULL    NULL     NULL     NULL        NULL
optimizer_use_multicol_stats                               NULL    NULL     NULL     NULL        NULL
optimizer_use_not_visible_indexes                          NULL    NULL     NULL     NULL        NULL
optimizer_use_polymorphic_parameter_fix                    NULL    NULL     NULL     NULL        NULL
optimizer_use_provided_ordering_fix                        NULL    NULL     NULL     NULL        NULL
optimizer_use_trigram_similarity_optimization              NULL    NULL     NULL     NULL        NULL
optimizer_use_virtual_computed_column_stats                NULL    NULL     NULL     NULL        NULL
override_multi_region_zone_config                          NULL    NULL     NULL     NULL        NULL
parallelize_multi_key_lookup_joins_enabled                 NULL    NULL     NULL     NULL        NULL
password_encryption                                        NULL    NULL     NULL     NULL        NULL
pg_trgm.similarity_threshold                               NULL    NULL     NULL     NULL        NULL
plan_cache_mode                                            NULL    NULL     NULL     NULL        NULL
plpgsql_use_strict_into                                    NULL    NULL     NULL     NULL        NULL
prefer_lookup_joins_for_fks                                NULL    NULL     NULL     NULL        NULL
prepared_statements_cache_size                             NULL    NULL     NULL     NULL        NULL
propagate_input_ordering                                   NULL    NULL     NULL     NULL        NULL
recursion_depth_limit                                      NULL    NULL     NULL     NULL        NULL
reorder_joins_limit                                        NULL    NULL     NULL     NULL        NULL
require_explicit_primary_keys                              NULL    NULL     NULL     NULL        NULL
results_buffer_size                                        NULL    NULL     NULL     NULL        NULL
role                                                       NULL    NULL     NULL     NULL        NULL
row_security                                               NULL    NULL     NULL     NULL        NULL
search_path                                                NULL    NULL     NULL     NULL        NULL
serial_normalization                                       NULL    NULL     NULL     NULL        NULL
server_encoding                                            NULL    NULL     NULL     NULL        NULL
server_version                                             NULL    NULL     NULL     NULL        NULL
server_version_num                                         NULL    NULL     NULL     NULL        NULL
session_id                                                 NULL    NULL     NULL     NULL        NULL
show_primary_key_constraint_on_not_visible_columns         NULL    NULL     NULL     NULL        NULL
sql_safe_updates                                           NULL    NULL     NULL     NULL        NULL
ssl                                                        NULL    NULL     NULL     NULL        NULL
standard_conforming_strings                                NULL    NULL     NULL     NULL        NULL
statement_timeout                                          NULL    NULL     NULL     NULL        NULL
streamer_always_maintain_ordering                          NULL    NULL     NULL     NULL        NULL
streamer_enabled                                           NULL    NULL     NULL     NULL        NULL
streamer_head_of_line_only_fraction                        NULL    NULL     NULL     NULL        NULL
streamer_in_order_eager_memory_usage_fraction              NULL    NULL     NULL     NULL        NULL
streamer_out_of_order_eager_memory_usage_fraction          NULL    NULL     NULL     NULL        NULL
strict_ddl_atomicity                                       NULL    NULL     NULL     NULL        NULL
stub_catalog_tables                                        NULL    NULL     NULL     NULL        NULL
synchronize_seqscans                                       NULL    NULL     NULL     NULL        NULL
synchronous_commit                                         NULL    NULL     NULL     NULL        NULL
system_identity                                            NULL    NULL     NULL     NULL        NULL
testing_optimizer_cost_perturbation                        NULL    NULL     NULL     NULL        NULL
testing_optimizer_disable_rule_probability                 NULL    NULL     NULL     NULL        NULL
testing_optimizer_inject_panics                            NULL    NULL     NULL     NULL        NULL
testing_optimizer_random_seed                              NULL    NULL     NULL     NULL        NULL
testing_vectorize_inject_panics                            NULL    NULL     NULL     NULL        NULL
timezone                                                   NULL    NULL     NULL     NULL        NULL
tracing                                                    NULL    NULL     NULL     NULL        NULL
transaction_isolation                                      NULL    NULL     NULL     NULL        NULL
transaction_priority                                       NULL    NULL     NULL     NULL        NULL
transaction_read_only                                      NULL    NULL     NULL     NULL        NULL
transaction_rows_read_err                                  NULL    NULL     NULL     NULL        NULL
transaction_rows_read_log                                  NULL    NULL     NULL     NULL        NULL
transaction_rows_written_err                               NULL    NULL     NULL     NULL        NULL
transaction_rows_written_log                               NULL    NULL     NULL     NULL        NULL
transaction_status                                         NULL    NULL     NULL     NULL        NULL
transaction_timeout                                        NULL    NULL     NULL     NULL        NULL
troubleshooting_mode                                       NULL    NULL     NULL     NULL        NULL
unbounded_parallel_scans                                   NULL    NULL     NULL     NULL        NULL
unconstrained_non_covering_index_scan_enabled              NULL    NULL     NULL     NULL        NULL
unsafe_allow_triggers_modifying_cascades                   NULL    NULL     NULL     NULL        NULL
use_declarative_schema_changer                             NULL    NULL     NULL     NULL        NULL
variable_inequality_lookup_join_enabled                    NULL    NULL     NULL     NULL        NULL
vectorize                                                  NULL    NULL     NULL     NULL        NULL
xmloption                                                  NULL    NULL     NULL     NULL        NULL

# pg_catalog.pg_sequence

statement ok
CREATE DATABASE seq

query OOIIIIIB
SELECT * FROM pg_catalog.pg_sequence
----

statement ok
CREATE SEQUENCE foo

statement ok
CREATE SEQUENCE bar MAXVALUE 10 MINVALUE 5 START 6 INCREMENT 2

query OOIIIIIB colnames,rowsort
SELECT * FROM pg_catalog.pg_sequence
----
seqrelid  seqtypid  seqstart  seqincrement  seqmax               seqmin  seqcache  seqcycle
142       20        1         1             9223372036854775807  1       1         false
143       20        6         2             10                   5       1         false

statement ok
DROP DATABASE seq

statement ok
SET database = constraint_db

# Verify sequences can't be seen from another database.
query OOIIIIIB rowsort
SELECT * FROM pg_catalog.pg_sequence
----
111  20  1  1  9223372036854775807  1  1  false
112  20  1  1  9223372036854775807  1  1  false
129  20  1  1  9223372036854775807  1  1  false

## pg_catalog.pg_operator

query OTOOTBBOOOOOOOO colnames
SELECT * FROM pg_catalog.pg_operator where oprname='+' and oprleft='float8'::regtype
----
oid       oprname  oprnamespace  oprowner  oprkind  oprcanmerge  oprcanhash  oprleft  oprright  oprresult  oprcom  oprnegate  oprcode  oprrest  oprjoin
74817020  +        4294967095    NULL      b        false        false       701      701       701        NULL    NULL       NULL     NULL     NULL

# Verify proper functionality of system information functions.

query TT
SELECT pg_catalog.pg_get_expr('1', 0), pg_catalog.pg_get_expr('1', 0::OID)
----
1  1

query T
SELECT pg_catalog.pg_get_expr('1', 0, true)
----
1

statement ok
SET DATABASE = constraint_db

query OTT
SELECT def.oid, c.relname, pg_catalog.pg_get_expr(def.adbin, def.adrelid)
FROM pg_catalog.pg_attrdef def
JOIN pg_catalog.pg_class c ON def.adrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public' ORDER BY def.oid DESC
----
4171354239  t2             unique_rowid()
3113771444  testtable      unique_rowid()
3086013501  t5             unique_rowid()
2594298909  t_with_pk_seq  nextval('public.t_with_pk_seq_a_seq'::REGCLASS)
2306804703  t1             a * b
2306804701  t1             nextval('public.t1_n_seq'::REGCLASS)
2306804700  t1             nextval('public.t1_m_seq'::REGCLASS)
2306804698  t1             a * b
2306804694  t1             12
2000672759  mv1            unique_rowid()
1740936492  t4             unique_rowid()
1221463949  t3             'FOO'::STRING
1221463946  t3             unique_rowid()
655595756   t6             m = 'foo'::public.mytype
655595747   t6             lower(c)
655595746   t6             unique_rowid()
655595745   t6             a + b

# Verify that a set database shows tables from that database for a non-root
# user, when that user has permissions.

statement ok
GRANT ALL ON constraint_db.* TO testuser

user testuser

statement ok
SET DATABASE = 'constraint_db'

query I
SELECT count(*) FROM pg_catalog.pg_tables WHERE schemaname='public'
----
9

user root

# Verify that an unset database shows tables across databases.
# But only those items visible to this user are reported.
# (Tests below show that root sees more).

statement ok
SET DATABASE = ''

query error cannot access virtual schema in anonymous database
SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public' ORDER BY 1

query error cannot access virtual schema in anonymous database
SELECT viewname FROM pg_catalog.pg_views WHERE schemaname='public' ORDER BY 1

query error cannot access virtual schema in anonymous database
SELECT relname FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE nspname='public'

query error cannot access virtual schema in anonymous database
SELECT conname FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public'

query error cannot access virtual schema in anonymous database
SELECT count(*) FROM pg_catalog.pg_depend

statement ok
SET DATABASE = test

## #13567
## regproc columns display as text but can still be joined against oid columns
query OTO
SELECT p.oid, p.proname, t.typinput
FROM pg_proc p
JOIN pg_type t ON t.typinput = p.oid
WHERE t.typname = '_int4'
----
2013  array_in  array_in

## #16285
## int2vectors should be 0-indexed
query I
SELECT count(*) FROM pg_catalog.pg_index WHERE indkey[0] IS NULL;
----
0

## Ensure no two builtins have the same oid.
query TI
WITH r AS (
  SELECT oid, c FROM (SELECT oid, count(*) as c FROM pg_catalog.pg_proc GROUP BY oid) WHERE c > 1
)
SELECT proname, l.oid::int AS id
FROM pg_catalog.pg_proc l
JOIN r on l.oid = r.oid
ORDER BY id
----

## Ensure no builtin has zero oid.
query T
SELECT proname FROM pg_catalog.pg_proc WHERE oid = 0
----

## Ensure that unnest works with oid wrapper arrays

query O rowsort
SELECT unnest((SELECT proargtypes FROM pg_proc WHERE proname='split_part'));
----
25
25
20

subtest pg_catalog.pg_prepare_statement

statement ok
CREATE TABLE types(a timestamptz, b integer)

statement ok
PREPARE test_insert_statement (integer, timestamptz) AS INSERT INTO types VALUES ($2, $1)

statement ok
PREPARE test_select_statement AS SELECT * FROM types

query TTTB
select name, statement, parameter_types, from_sql from pg_prepared_statements ORDER BY 1, 2
----
test_insert_statement  PREPARE test_insert_statement (int, timestamptz) AS INSERT INTO types VALUES ($2, $1)  {bigint,"'timestamp with time zone'"}  true
test_select_statement  PREPARE test_select_statement AS SELECT * FROM types                                   {}                                     true

subtest pg_catalog.pg_prepare_statement,with_possible_mismatch_num_types

statement ok
PREPARE args_test_many(int, int) as select $1

statement ok
PREPARE args_test_few(int) as select $1, $2::int

statement ok
DROP TABLE IF EXISTS t_prepare;

statement ok
CREATE TABLE t_prepare (x int, y varchar(10), z int2);

statement ok
PREPARE args_deduce_type(int, int, int, int) AS INSERT INTO t_prepare VALUES ($1, $2, $3);

statement ok
PREPARE args_deduce_type_1(int) AS SELECT $1::int, $2::varchar(10), $3::varchar(20);

query TTTB
SELECT name, statement, parameter_types, from_sql FROM pg_prepared_statements WHERE name LIKE 'args_%' ORDER BY 1,2
----
args_deduce_type    PREPARE args_deduce_type (int, varchar, int, int) AS INSERT INTO t_prepare VALUES ($1, $2, $3)           {bigint,"'character varying'",bigint,bigint}          true
args_deduce_type_1  PREPARE args_deduce_type_1 (int, varchar, varchar) AS SELECT $1::INT8, $2::VARCHAR(10), $3::VARCHAR(20)  {bigint,"'character varying'","'character varying'"}  true
args_test_few       PREPARE args_test_few (int, int) AS SELECT $1, $2::INT8                                                  {bigint,bigint}                                       true
args_test_many      PREPARE args_test_many (int, int) AS SELECT $1                                                           {bigint,bigint}                                       true

statement ok
DROP TABLE types

## TODO(masha): #16769
#statement ok
#CREATE TABLE types(a int8, b int2);

#query I
#SELECT attname, atttypid, typname FROM pg_attribute a JOIN pg_type t ON a.atttypid=t.oid WHERE attrelid = 'types'::REGCLASS;
#attname   atttypid  typname
#a         20        int8
#b         20        int2

subtest pg_catalog.pg_seclabel

query OOOTT colnames
SELECT objoid, classoid, objsubid, provider, label FROM pg_catalog.pg_seclabel
----
objoid  classoid  objsubid  provider  label

subtest pg_catalog.pg_shseclabel

query OOTT colnames
SELECT objoid, classoid, provider, label FROM pg_catalog.pg_shseclabel
----
objoid  classoid  provider  label

subtest pg_catalog.pg_aggregate

query O colnames
SELECT oid::REGPROC FROM pg_proc WHERE prokind = 'a' EXCEPT SELECT aggfnoid FROM pg_aggregate
----
oid

# Check whether correct operator's oid is set for max and bool_or.
query OTO colnames,rowsort
SELECT c.oid, c.oprname, a.aggsortop FROM pg_aggregate a
JOIN pg_proc b ON a.aggfnoid = b.oid::REGPROC
JOIN pg_operator c ON c.oprname = '>' AND b.proargtypes[0] = c.oprleft AND b.proargtypes[0] = c.oprright
WHERE (b.proname = 'max' OR b.proname = 'bool_or') AND c.oid = a.aggsortop;
----
oid         oprname  aggsortop
3636536082  >        3636536082
1737252658  >        1737252658
1737252658  >        1737252658
1224236426  >        1224236426
3636536082  >        3636536082
264553706   >        264553706
883535762   >        883535762
1383827510  >        1383827510
2318307066  >        2318307066
3234851498  >        3234851498
256681770   >        256681770
530358714   >        530358714
2105536758  >        2105536758
1928531314  >        1928531314
1737252658  >        1737252658
1737252658  >        1737252658
2948286002  >        2948286002
2139039570  >        2139039570
3802002898  >        3802002898
3457382662  >        3457382662
3421685890  >        3421685890
3626766962  >        3626766962
1064453514  >        1064453514
1778355034  >        1778355034
3944320082  >        3944320082
1385359122  >        1385359122

# Check whether correct operator's oid is set for min, bool_and and every.
query OTO colnames,rowsort
SELECT c.oid, c.oprname, a.aggsortop FROM pg_aggregate a
JOIN pg_proc b ON a.aggfnoid = b.oid::REGPROC
JOIN pg_operator c ON c.oprname = '<' AND b.proargtypes[0] = c.oprleft AND b.proargtypes[0] = c.oprright
WHERE (b.proname = 'min' OR b.proname = 'bool_and' OR b.proname = 'every') AND c.oid = a.aggsortop;
----
oid         oprname  aggsortop
2134593616  <        2134593616
2134593616  <        2134593616
235310192   <        235310192
235310192   <        235310192
3859576864  <        3859576864
2134593616  <        2134593616
3269496816  <        3269496816
3676560592  <        3676560592
2011297100  <        2011297100
2790955336  <        2790955336
2457977576  <        2457977576
426663592   <        426663592
1494969736  <        1494969736
2104629996  <        2104629996
3942776496  <        3942776496
235310192   <        235310192
235310192   <        235310192
1446343536  <        1446343536
2699108304  <        2699108304
3842027408  <        3842027408
2897050084  <        2897050084
4132205728  <        4132205728
1634400784  <        1634400784
2300570720  <        2300570720
3675947880  <        3675947880
3575809104  <        3575809104
1579888144  <        1579888144

subtest collated_string_type

statement ok
CREATE TABLE coltab (a STRING COLLATE en)

query OT
SELECT typ.oid, typ.typname FROM pg_attribute att JOIN pg_type typ ON atttypid=typ.oid WHERE attrelid='coltab'::regclass AND attname='a'
----
25 text

subtest 31545

# Test an index of 2 referencing an index of 2.
statement ok
CREATE TABLE a (
  id_a_1 INT UNIQUE,
  id_a_2 INT,
  PRIMARY KEY (id_a_1, id_a_2)
)

statement ok
CREATE TABLE b (
  id_b_1 INT,
  id_b_2 INT,
  PRIMARY KEY (id_b_1, id_b_2),
  CONSTRAINT my_fkey FOREIGN KEY (id_b_1, id_b_2) REFERENCES a (id_a_1, id_a_2)
)

query TT colnames
SELECT conkey, confkey FROM pg_catalog.pg_constraint WHERE conname = 'my_fkey'
----
conkey  confkey
{1,2}   {1,2}

# Test an index of 3 referencing an index of 2.
statement ok
DROP TABLE b;

statement ok
CREATE TABLE b (
  id_b_1 INT,
  id_b_2 INT,
  id_b_3 INT,
  PRIMARY KEY (id_b_1, id_b_2, id_b_3),
  CONSTRAINT my_fkey FOREIGN KEY (id_b_1, id_b_2) REFERENCES a (id_a_1, id_a_2)
)

query TT colnames
SELECT conkey, confkey FROM pg_catalog.pg_constraint WHERE conname = 'my_fkey'
----
conkey  confkey
{1,2}   {1,2}

# Test an index of 3 referencing an index of 1.
statement ok
DROP TABLE b;

statement ok
CREATE TABLE b (
  id_b_1 INT,
  id_b_2 INT,
  id_b_3 INT,
  PRIMARY KEY (id_b_1, id_b_2, id_b_3),
  CONSTRAINT my_fkey FOREIGN KEY (id_b_1) REFERENCES a (id_a_1)
)

query TT colnames
SELECT conkey, confkey FROM pg_catalog.pg_constraint WHERE conname = 'my_fkey'
----
conkey  confkey
{1}     {1}

subtest regression_34856

statement ok
CREATE DATABASE d34856

statement ok
CREATE TABLE d34856.t(x INT);
  CREATE VIEW d34856.v AS SELECT x FROM d34856.t;
  CREATE SEQUENCE d34856.s

# Check that only tables show up in pg_tables.
query T
SELECT tablename FROM d34856.pg_catalog.pg_tables WHERE schemaname = 'public'
----
t

statement ok
DROP DATABASE d34856 CASCADE

subtest regression_34862

statement ok
CREATE DATABASE d34862; SET database=d34862

statement ok
CREATE TABLE t(x INT UNIQUE);
  CREATE TABLE u(
    a INT REFERENCES t(x) ON DELETE NO ACTION,
    b INT REFERENCES t(x) ON DELETE RESTRICT,
    c INT REFERENCES t(x) ON DELETE SET NULL,
    d INT DEFAULT 123 REFERENCES t(x) ON DELETE SET DEFAULT,
    e INT REFERENCES t(x) ON DELETE CASCADE,
    f INT REFERENCES t(x) ON UPDATE NO ACTION,
    g INT REFERENCES t(x) ON UPDATE RESTRICT,
    h INT REFERENCES t(x) ON UPDATE SET NULL,
    i INT DEFAULT 123 REFERENCES t(x) ON UPDATE SET DEFAULT,
    j INT REFERENCES t(x) ON UPDATE CASCADE,
    k INT REFERENCES t(x) ON DELETE RESTRICT ON UPDATE SET NULL
  );

query TTT
SELECT conname, confupdtype, confdeltype FROM pg_constraint ORDER BY conname
----
t_pkey    NULL  NULL
t_x_key   NULL  NULL
u_a_fkey  a     a
u_b_fkey  a     r
u_c_fkey  a     n
u_d_fkey  a     d
u_e_fkey  a     c
u_f_fkey  a     a
u_g_fkey  r     a
u_h_fkey  n     a
u_i_fkey  d     a
u_j_fkey  c     a
u_k_fkey  n     r
u_pkey    NULL  NULL

statement ok
DROP TABLE u; DROP TABLE t

statement ok
CREATE TABLE v(x INT, y INT, UNIQUE (x,y))

statement ok
CREATE TABLE w(
  a INT, b INT, c INT, d INT,
  FOREIGN KEY (a,b) REFERENCES v(x,y) MATCH FULL,
  FOREIGN KEY (c,d) REFERENCES v(x,y) MATCH SIMPLE
  );

query TT
SELECT conname, confmatchtype FROM pg_constraint ORDER BY conname
----
v_pkey      NULL
v_x_y_key   NULL
w_a_b_fkey  f
w_c_d_fkey  s
w_pkey      NULL

statement ok
DROP DATABASE d34862 CASCADE; SET database=test

subtest regression_46450

statement ok
CREATE TABLE regression_46450 (id UUID PRIMARY KEY, json JSONB)

statement ok
CREATE INDEX regression_46450_idx ON regression_46450 USING gin(json)

query T
select indexdef from pg_indexes where indexname = 'regression_46450_idx'
----
CREATE INDEX regression_46450_idx ON test.public.regression_46450 USING gin (json)

# Make sure indexdef uses user-defined schemas.

statement ok
CREATE SCHEMA test_schema;
CREATE TABLE test_schema.test (
  a INT PRIMARY KEY,
  b INT
);
CREATE index on test_schema.test(b)

query TTTT colnames
SELECT schemaname, tablename, indexname, indexdef
FROM pg_indexes WHERE schemaname='test_schema' and tablename='test'
ORDER BY indexname
----
schemaname   tablename  indexname   indexdef
test_schema  test       test_b_idx  CREATE INDEX test_b_idx ON test.test_schema.test USING btree (b ASC)
test_schema  test       test_pkey   CREATE UNIQUE INDEX test_pkey ON test.test_schema.test USING btree (a ASC)

# Make sure that selecting from vtables with indexes in other dbs properly
# hides descriptors that should be hidden.

statement ok
CREATE TABLE hidden_in_vtable_index_test(a int)

let $testid
SELECT oid FROM pg_class WHERE relname='hidden_in_vtable_index_test'

statement ok
CREATE DATABASE other_db; SET DATABASE = other_db

query O
SELECT oid FROM pg_class WHERE oid=$testid
----

subtest geospatial

statement ok
SET DATABASE = test

statement ok
CREATE TABLE geospatial_table (
  id UUID PRIMARY KEY,
  a geography(geometry, 4326),
  b geometry(point, 4326),
  INVERTED INDEX idxa (a)
)

statement ok
CREATE INVERTED INDEX idxb ON geospatial_table (b)

query TT colnames
SELECT indexname, indexdef
FROM pg_catalog.pg_indexes
WHERE tablename = 'geospatial_table'
ORDER BY indexname
----
indexname              indexdef
geospatial_table_pkey  CREATE UNIQUE INDEX geospatial_table_pkey ON test.public.geospatial_table USING btree (id ASC)
idxa                   CREATE INDEX idxa ON test.public.geospatial_table USING gin (a)
idxb                   CREATE INDEX idxb ON test.public.geospatial_table USING gin (b)

subtest partial_index

statement ok
SET DATABASE = test

statement ok
CREATE TYPE testenum AS ENUM ('foo', 'bar', 'baz')

statement ok
CREATE TABLE partial_index_table (
  a INT,
  b testenum,
  UNIQUE INDEX (a) WHERE a > 0
)

statement ok
CREATE UNIQUE INDEX ON partial_index_table (a) WHERE b IN ('foo', 'bar')

query TT colnames
SELECT indexname, indexdef
FROM pg_catalog.pg_indexes
WHERE tablename = 'partial_index_table'
ORDER BY indexname
----
indexname                   indexdef
partial_index_table_a_key   CREATE UNIQUE INDEX partial_index_table_a_key ON test.public.partial_index_table USING btree (a ASC) WHERE (a > 0)
partial_index_table_a_key1  CREATE UNIQUE INDEX partial_index_table_a_key1 ON test.public.partial_index_table USING btree (a ASC) WHERE (b IN ('foo'::public.testenum, 'bar'::public.testenum))
partial_index_table_pkey    CREATE UNIQUE INDEX partial_index_table_pkey ON test.public.partial_index_table USING btree (rowid ASC)

query TT colnames
SELECT conname, condef
FROM pg_catalog.pg_constraint c JOIN pg_catalog.pg_class t
ON c.conrelid = t.oid
WHERE t.relname = 'partial_index_table'
ORDER BY conname
----
conname                     condef
partial_index_table_a_key   UNIQUE (a ASC) WHERE (a > 0)
partial_index_table_a_key1  UNIQUE (a ASC) WHERE (b IN ('foo'::public.testenum, 'bar'::public.testenum))
partial_index_table_pkey    PRIMARY KEY (rowid ASC)

subtest regression_46799
statement ok
CREATE TABLE t46799 (x INT DEFAULT 1, y INT DEFAULT 1);

query I rowsort
SELECT adnum FROM pg_attrdef WHERE adrelid = 't46799'::REGCLASS
----
1
2
3

statement ok
ALTER TABLE t46799 DROP COLUMN y;

statement ok
ALTER TABLE t46799 ADD COLUMN y INT DEFAULT 1;

# Make sure after adding and dropping the same column, the adnum for the re-added column increases.
query I rowsort
select adnum from pg_attrdef WHERE adrelid = 't46799'::REGCLASS
----
1
3
4

# Check virtual table lookup joins.
statement ok
CREATE TABLE jt (a INT PRIMARY KEY); INSERT INTO jt VALUES(1); INSERT INTO jt VALUES('jt'::regclass::int)

query ITT
SELECT a, oid, relname FROM jt INNER LOOKUP JOIN pg_class ON a::oid=oid
----
173  173  jt

query ITT rowsort
SELECT a, oid, relname FROM jt LEFT OUTER LOOKUP JOIN pg_class ON a::oid=oid
----
1    NULL  NULL
173  173   jt

subtest regression_49207
statement ok
CREATE ROLE role_test_login with LOGIN;
CREATE ROLE role_test_nologin;

query B
SELECT rolcanlogin FROM pg_roles WHERE rolname = 'role_test_login';
----
true

query B
SELECT rolcanlogin FROM pg_roles WHERE rolname = 'role_test_nologin';
----
false

subtest regression_49420
statement ok
CREATE USER role_test_with_date VALID UNTIL '2021-01-01';
CREATE USER role_test_with_date_timezone VALID UNTIL '2021-01-01 00:00:00 +02:00';
CREATE USER role_test_nodate;

query T
SELECT rolvaliduntil FROM pg_roles WHERE rolname = 'role_test_with_date';
----
2021-01-01 00:00:00 +0000 UTC

query T
SELECT rolvaliduntil FROM pg_roles WHERE rolname = 'role_test_with_date_timezone';
----
2020-12-31 22:00:00 +0000 UTC

query T
SELECT rolvaliduntil FROM pg_roles WHERE rolname = 'role_test_nodate';
----
NULL

query T
SELECT rolvaliduntil FROM pg_authid WHERE rolname = 'role_test_with_date';
----
2021-01-01 00:00:00 +0000 UTC

query T
SELECT rolvaliduntil FROM pg_authid WHERE rolname = 'role_test_with_date_timezone';
----
2020-12-31 22:00:00 +0000 UTC

query T
SELECT rolvaliduntil FROM pg_authid WHERE rolname = 'role_test_nodate';
----
NULL

subtest mutations

statement error pg_tables is a system catalog
ALTER TABLE pg_catalog.pg_tables RENAME TO pg_catalog.bad

statement error pg_tables is a system catalog
ALTER TABLE pg_catalog.pg_tables RENAME COLUMN x TO y

statement error pg_tables is a system catalog
ALTER TABLE pg_catalog.pg_tables ADD COLUMN x DECIMAL

statement error pg_tables is a system catalog
ALTER TABLE pg_catalog.pg_tables DROP COLUMN x

statement error pg_tables is a system catalog
ALTER TABLE pg_catalog.pg_tables ADD CONSTRAINT foo UNIQUE (b)

statement error pg_tables is a system catalog
ALTER TABLE pg_catalog.pg_tables DROP CONSTRAINT bar

statement error pg_tables is a system catalog
ALTER TABLE pg_catalog.pg_tables ALTER COLUMN x SET DEFAULT 'foo'

statement error pg_tables is a system catalog
ALTER TABLE pg_catalog.pg_tables ALTER x DROP NOT NULL

statement error pg_tables is a system catalog
CREATE INDEX i on pg_catalog.pg_tables (x)

statement error pg_tables is a system catalog
DROP TABLE pg_catalog.pg_tables

statement error pg_tables is a system catalog
DROP INDEX pg_catalog.pg_tables@i

statement error pq: invalid privilege type CREATE for virtual_table
GRANT CREATE ON pg_catalog.pg_tables TO root

statement error pq: invalid privilege type CREATE for virtual_table
REVOKE CREATE ON pg_catalog.pg_tables FROM root

# Verify pg_catalog tables handles read-only property correctly.

query error user root does not have DELETE privilege on relation pg_tables
DELETE FROM pg_catalog.pg_tables

query error user root does not have INSERT privilege on relation pg_tables
INSERT INTO pg_catalog.pg_tables VALUES ('abc')

statement error user root does not have UPDATE privilege on relation pg_tables
UPDATE pg_catalog.pg_tables SET a = 'abc'

statement error pg_tables is a system catalog
TRUNCATE TABLE pg_catalog.pg_tables

# Regression for #47285.
statement ok
CREATE TABLE t47285 (x STRING DEFAULT 'hello');
ALTER TABLE t47285 ALTER COLUMN x SET DEFAULT 'howdy'

query T
SELECT
  pg_get_expr(d.adbin, d.adrelid)
FROM
  pg_attribute AS a
  LEFT JOIN pg_attrdef AS d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
  LEFT JOIN pg_type AS t ON a.atttypid = t.oid
  LEFT JOIN pg_collation AS c ON
    a.attcollation = c.oid AND a.attcollation != t.typcollation
WHERE
  a.attrelid = 't47285'::REGCLASS
  AND a.attnum > 0
  AND NOT a.attisdropped
  AND attname = 'x'
----
'howdy'::STRING

# Regression test for array formatting logic, #55320.
statement ok
CREATE TABLE default_arrays (
  id INT8 NOT NULL PRIMARY KEY,
  string_array text[] DEFAULT '{cat, dog}',
  weird_array text[] DEFAULT '{a,"", "b,c", "a''::string","''::string", "a''::string, ''::string",null}',
  int_array int[] default '{1, 2}',
  varchar_array varchar(32)[] DEFAULT '{cat, dog}'
);

query TTTBOI
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
  pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
 FROM pg_attribute a
 LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
 LEFT JOIN pg_type t ON a.atttypid = t.oid
 LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
WHERE a.attrelid = 'default_arrays'::regclass
  AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
----
id             bigint                   NULL                                                                            true   20    -1
string_array   text[]                   '{cat,dog}'::STRING[]                                                           false  1009  -1
weird_array    text[]                   '{a,"","b,c",a''::string,''::string,"a''::string, ''::string",NULL}'::STRING[]  false  1009  -1
int_array      bigint[]                 '{1,2}'::INT8[]                                                                 false  1016  -1
varchar_array  character varying(32)[]  '{cat,dog}'::STRING[]                                                           false  1015  36

# Regression test for atttypmod being populated for timestamp types (#110787)
statement ok
CREATE TABLE  timestamp_with_typmod(
	a time(1) NULL,
	b timetz(2) NULL,
	c timestamp(3) NULL,
	d timestamptz(4) NULL,
	e interval(5) NULL,
	f time NULL,
	g timetz NULL,
	h timestamp NULL,
	i timestamptz NULL,
	j interval NULL
);

query TTTBOI
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
  pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
 FROM pg_attribute a
 LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
 LEFT JOIN pg_type t ON a.atttypid = t.oid
 LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
WHERE a.attrelid = 'timestamp_with_typmod'::regclass
  AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
----
a      time(1) without time zone       NULL            false  1083  1
b      time(2) with time zone          NULL            false  1266  2
c      timestamp(3) without time zone  NULL            false  1114  3
d      timestamp(4) with time zone     NULL            false  1184  4
e      interval(5)                     NULL            false  1186  5
f      time without time zone          NULL            false  1083  -1
g      time with time zone             NULL            false  1266  -1
h      timestamp without time zone     NULL            false  1114  -1
i      timestamp with time zone        NULL            false  1184  -1
j      interval                        NULL            false  1186  -1
rowid  bigint                          unique_rowid()  true   20    -1



# Regression test for limits on virtual index scans. (#53522)

let $testid
SELECT 't47285'::REGCLASS::OID

query T
SELECT attname FROM pg_attribute WHERE attrelid = $testid LIMIT 1
----
x

# Regression test for #53854.
statement ok
SELECT
  t.typname, t.oid
FROM
  pg_catalog.pg_type AS t JOIN pg_catalog.pg_namespace AS n ON t.typnamespace = n.oid
WHERE
  n.nspname != 'pg_toast'
  AND (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class AS c WHERE c.oid = t.typrelid))

# Regression test for range constraints on virtual index scans. (#56440)
query O
SELECT oid FROM pg_type WHERE oid IN (19,20,24) ORDER BY oid
----
19
20
24

statement ok
SELECT * FROM pg_class WHERE oid = 10 OR oid BETWEEN 20 AND 30 OR oid = 40

statement ok
SET experimental_enable_temp_tables = 'on';

statement ok
CREATE TEMPORARY TABLE test_temp (id UUID PRIMARY KEY);
CREATE UNLOGGED TABLE test_unlogged (id UUID PRIMARY KEY);
CREATE TABLE test_persistent (id UUID PRIMARY KEY);

# We don't store UNLOGGED beyond the parser at the moment so we expect 'p' for test_unlogged.
query TTB
SELECT
  relname, relpersistence, relistemp
FROM
  pg_catalog.pg_class
WHERE
  relname IN ('test_temp', 'test_unlogged', 'test_persistent')
ORDER BY
  relname
----
test_persistent  p  false
test_temp        t  true
test_unlogged    p  false

# Issue 44793
statement ok
CREATE TABLE PARENT_TABLE_A(id UUID PRIMARY KEY);
CREATE TABLE CHILD_TABLE_B(
  id UUID PRIMARY KEY,
  a_id UUID,
  CONSTRAINT fk_b_to_a FOREIGN KEY (a_id) REFERENCES PARENT_TABLE_A (id)
);

query TT
SELECT pg_typeof(confkey), pg_typeof(conkey) FROM pg_constraint WHERE conname = 'fk_b_to_a'
----
smallint[]  smallint[]

# Postgres always uses "char" (oid=18) and not CHAR (oid=1042) for character
# columns in pg_catalog. (Nor does it use CHAR[] (oid=1014).) See #57301.

query I
SELECT count(*)
FROM pg_class c
JOIN pg_attribute a ON a.attrelid = c.oid
JOIN pg_type t ON t.oid = a.atttypid
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'pg_catalog' AND (t.oid = 1042 OR t.oid = 1014)
----
0

# pg_catalog is explicitly disallowed for use with the anonymous database.
query error cannot access virtual schema in anonymous database
SELECT tablename FROM "".pg_catalog.pg_tables

statement ok
SET DATABASE = "";

query error cannot access virtual schema in anonymous database
SELECT tablename FROM pg_catalog.pg_tables

statement ok
SET DATABASE = test;

subtest 58945

statement ok
CREATE TABLE t_hash (
  a INT,
  INDEX t_hash_a_idx (a DESC) USING HASH WITH (bucket_count=8)
);

query T colnames
SELECT indoption
FROM pg_catalog.pg_index
WHERE indexrelid IN (SELECT crdb_oid FROM pg_catalog.pg_indexes WHERE indexname = 't_hash_a_idx')
----
indoption
2 1

subtest end

# Regression #59561.
# database_name would not be populated even when the SELECT does not use the virtual index.
query TTI
SELECT database_name, descriptor_name, descriptor_id from test.crdb_internal.create_statements where descriptor_name = 'pg_views'
----
test  pg_views  4294966966

# Verify INCLUDED columns appear in pg_index. See issue #59563
statement ok
CREATE TABLE "indexes_table" (
    "id" integer NOT NULL PRIMARY KEY DEFAULT unique_rowid(),
    "a" varchar(100) NOT NULL,
    "b" timestamptz NOT NULL,
    "c" boolean NOT NULL,
    "d" TEXT NOT NULL
);
CREATE INDEX "indexes_include_idx" ON "indexes_table" ("a") INCLUDE ("c", "d");

query TII colnames
SELECT pg_index.indkey, pg_index.indnatts, pg_index.indnkeyatts
FROM pg_class
JOIN pg_index ON pg_class.oid = pg_index.indexrelid
WHERE pg_class.relname = 'indexes_include_idx'
----
indkey  indnatts  indnkeyatts
2 4 5   3         1

query TTBBTTTT colnames
SELECT
    indexname, array_agg(attname ORDER BY rnum), indisunique, indisprimary,
    array_agg(ordering ORDER BY rnum), amname, exprdef, s2.attoptions
FROM (
    SELECT
        c2.relname as indexname, idx.*, attr.attname, am.amname,
        CASE
            WHEN idx.indexprs IS NOT NULL THEN
                pg_get_indexdef(idx.indexrelid)
        END AS exprdef,
        CASE am.amname
            WHEN 'prefix' THEN
                CASE (option & 1)
                    WHEN 1 THEN 'DESC' ELSE 'ASC'
                END
        END as ordering,
        c2.reloptions as attoptions
    FROM (
        SELECT
            row_number() OVER () as rnum, *,
            unnest(i.indkey) as key, unnest(i.indoption) as option
        FROM pg_index i
    ) idx
    LEFT JOIN pg_class c ON idx.indrelid = c.oid
    LEFT JOIN pg_class c2 ON idx.indexrelid = c2.oid
    LEFT JOIN pg_am am ON c2.relam = am.oid
    LEFT JOIN pg_attribute attr ON attr.attrelid = c.oid AND attr.attnum = idx.key
    WHERE c.relname = 'indexes_table'
) s2
GROUP BY indexname, indisunique, indisprimary, amname, exprdef, attoptions
ORDER BY indexname
----
indexname            array_agg  indisunique  indisprimary  array_agg      amname  exprdef  attoptions
indexes_include_idx  {a,c,d}    false        false         {ASC,ASC,ASC}  prefix  NULL     NULL
indexes_table_pkey   {id}       true         true          {ASC}          prefix  NULL     NULL

statement ok
SET stub_catalog_tables=false

statement error pq: unimplemented: virtual schema table not implemented: pg_catalog.pg_seclabel
SELECT * FROM pg_seclabel

statement ok
SELECT count(*) FROM pg_depend

statement ok
SET stub_catalog_tables=true

statement ok
SELECT * FROM pg_seclabel

statement ok
CREATE SEQUENCE serial START 101 INCREMENT 5

# Last value must return NULL when querying pg_sequences and sequence haven't
# been used.
query I
SELECT last_value FROM pg_sequences WHERE sequencename = 'serial'
----
NULL

statement ok
SELECT nextval('serial');
SELECT nextval('serial');
SELECT nextval('serial');

# Now last_value should be 111
query TTTOIIIIBII colnames
SELECT * FROM pg_sequences WHERE sequencename = 'serial'
----
schemaname  sequencename  sequenceowner  data_type  start_value  min_value  max_value            increment_by  cycle  cache_size  last_value
public      serial        root           20         101          1          9223372036854775807  5             false  1           111

# Testing sequenceowner and cache_size
statement ok
CREATE USER anyuser;
GRANT CREATE ON DATABASE test TO anyuser;
ALTER SEQUENCE serial OWNER TO anyuser;
ALTER SEQUENCE serial CACHE 10;

query TI colnames
SELECT sequenceowner, cache_size FROM pg_sequences WHERE sequencename = 'serial'
----
sequenceowner  cache_size
anyuser        10

statement ok
COMMENT ON SCHEMA test_schema is 'testing schema';

query T colnames
SELECT obj_description(objoid)
  FROM pg_catalog.pg_description
 WHERE description = 'testing schema'
----
obj_description
testing schema

# Testing pg_shdepend pinned elements
query T colnames
SELECT rolname
FROM pg_authid WHERE oid IN (
  SELECT refobjid FROM pg_shdepend WHERE deptype = 'p'
) ORDER BY rolname
----
rolname
admin
root

statement ok
CREATE DATABASE sh_db;
CREATE DATABASE sh_db_root;
CREATE TABLE sh_db.sh_table_a(id INT);
CREATE TABLE sh_db_root.sh_table_b(id INT);
CREATE USER sh_user;
CREATE USER sh_owner;
GRANT CREATE ON DATABASE sh_db TO sh_owner;
GRANT SELECT ON sh_db.sh_table_a TO sh_owner;
ALTER TABLE sh_db.sh_table_a OWNER TO sh_owner;
ALTER DATABASE sh_db OWNER TO sh_owner;
ALTER TABLE sh_db_root.sh_table_b OWNER TO root;
ALTER DATABASE sh_db_root OWNER TO root;
GRANT SELECT ON sh_db.sh_table_a TO sh_user;
GRANT SELECT ON sh_db_root.sh_table_b TO sh_user;
CREATE ROLE sh_role;
GRANT SELECT ON sh_db.sh_table_a TO sh_role;
GRANT SELECT ON sh_db_root.sh_table_b TO sh_role;
GRANT CONNECT ON DATABASE sh_db TO sh_role;
GRANT CONNECT ON DATABASE sh_db_root TO sh_role;
USE sh_db;

# Testing shared dependencies on sh_table_a
query TTTT colnames
SELECT
  pg_class.relname,
  pg_authid.rolname,
  pg_shdepend.deptype,
  pg_database.datname
FROM pg_authid
JOIN pg_shdepend ON pg_authid.oid = pg_shdepend.refobjid
JOIN pg_class ON pg_shdepend.objid = pg_class.oid
JOIN pg_database ON pg_database.oid = pg_shdepend.dbid
WHERE pg_class.relname IN ('sh_table_a')
ORDER BY pg_class.relname, pg_authid.rolname
----
relname     rolname   deptype  datname
sh_table_a  sh_owner  o        sh_db
sh_table_a  sh_role   a        sh_db
sh_table_a  sh_user   a        sh_db

statement ok
USE sh_db_root;

# Testing shared dependencies on sh_table_a
query TTTT colnames
SELECT
  pg_class.relname,
  pg_authid.rolname,
  pg_shdepend.deptype,
  pg_database.datname
FROM pg_authid
JOIN pg_shdepend ON pg_authid.oid = pg_shdepend.refobjid
JOIN pg_class ON pg_shdepend.objid = pg_class.oid
JOIN pg_database ON pg_database.oid = pg_shdepend.dbid
WHERE pg_class.relname IN ('sh_table_b')
ORDER BY pg_class.relname, pg_authid.rolname
----
relname     rolname  deptype  datname
sh_table_b  sh_role  a        sh_db_root
sh_table_b  sh_user  a        sh_db_root

statement ok
USE test;

# Testing shared dependencies on sh_db
query TTT colnames
SELECT
  pg_database.datname,
  pg_authid.rolname,
  pg_shdepend.deptype
FROM pg_authid
JOIN pg_shdepend ON pg_authid.oid = pg_shdepend.refobjid
JOIN pg_database ON pg_shdepend.objid = pg_database.oid
WHERE pg_database.datname IN ('sh_db', 'sh_db_root')
ORDER BY pg_database.datname, pg_authid.rolname
----
datname     rolname   deptype
sh_db       sh_owner  o
sh_db       sh_role   a
sh_db_root  sh_role   a

# Testing settings and createDB from forEachRoles
statement ok
CREATE USER testuser1;
CREATE USER testuser2;
CREATE ROLE testrole1;
CREATE DATABASE foreachroles;
ALTER USER testuser1 WITH CREATEDB;
ALTER USER testuser1 SET TimeZone = 'America/Los_Angeles';
ALTER USER testuser1 SET application_name = 'a';
ALTER USER testuser1 IN DATABASE foreachroles SET application_name = 'b';
ALTER USER testuser2 WITH CREATEROLE PASSWORD '123' VALID UNTIL '3022-01-01';

query TBT colnames
SELECT usename, usecreatedb, useconfig
FROM pg_user
WHERE usename IN ('testuser1', 'testuser2')
ORDER BY usename
----
usename    usecreatedb  useconfig
testuser1  true         {timezone=America/Los_Angeles,application_name=a}
testuser2  false        NULL

query TBTBBT colnames
SELECT rolname, rolcreatedb, rolconfig, rolinherit, rolcanlogin, rolvaliduntil
FROM pg_roles
WHERE rolname IN ('testuser1', 'testuser2', 'testrole1')
ORDER BY rolname
----
rolname    rolcreatedb  rolconfig                                          rolinherit  rolcanlogin  rolvaliduntil
testrole1  false        NULL                                               true        false        NULL
testuser1  true         {timezone=America/Los_Angeles,application_name=a}  true        true         NULL
testuser2  false        NULL                                               true        true         3022-01-01 00:00:00 +0000 UTC

query TBBBBT colnames
SELECT rolname, rolcreatedb, rolcreaterole, rolinherit, rolcanlogin, rolvaliduntil
FROM pg_authid
WHERE rolname IN ('testuser1', 'testuser2', 'testrole1', 'root')
ORDER BY rolname
----
rolname    rolcreatedb  rolcreaterole  rolinherit  rolcanlogin  rolvaliduntil
root       true         true           true        true         NULL
testrole1  false        false          true        false        NULL
testuser1  true         false          true        true         NULL
testuser2  false        true           true        true         3022-01-01 00:00:00 +0000 UTC

# Testing users that have admin role

statement ok;
CREATE USER super_user;
GRANT admin TO super_user;
CREATE USER regular_user;
CREATE ROLE super_role;
GRANT admin TO super_role;
CREATE ROLE regular_role;

query TB colnames
SELECT rolname, rolsuper
FROM pg_authid
WHERE rolname IN ('super_user', 'super_role', 'regular_user', 'regular_role', 'root', 'admin')
ORDER BY rolname
----
rolname       rolsuper
admin         true
regular_role  false
regular_user  false
root          true
super_role    true
super_user    true

query TB colnames
SELECT rolname, rolsuper
FROM pg_roles
WHERE rolname IN ('super_user', 'super_role', 'regular_user', 'regular_role', 'root', 'admin')
ORDER BY rolname
----
rolname       rolsuper
admin         true
regular_role  false
regular_user  false
root          true
super_role    true
super_user    true

query TB colnames
SELECT usename, usesuper
FROM pg_user
WHERE usename IN ('super_user', 'regular_user', 'root')
ORDER BY usename
----
usename       usesuper
regular_user  false
root          true
super_user    true

# Testing null valid until roles
statement ok
CREATE USER regression_70180 WITH password '123' VALID UNTIL null;

query TT colnames
SELECT usename, valuntil
FROM pg_user
WHERE usename = 'regression_70180'
----
usename           valuntil
regression_70180  NULL

# Testing pg_statistic_ext
statement ok
CREATE TABLE stxtbl(a INT, b INT, c INT);
CREATE STATISTICS stxobj ON b, c FROM stxtbl;

statement ok
CREATE SCHEMA test;
CREATE TABLE test.stxtbl2(a INT, b INT, c INT);
CREATE STATISTICS stxobj2 ON a, c FROM test.stxtbl2;
CREATE TABLE stx(stx) AS SELECT generate_series(1,100);
ANALYZE stx;

query TTOOITT colnames,rowsort
SELECT
  relname,
  stxname,
  stxnamespace,
  stxowner,
  stxstattarget,
  stxkeys,
  stxkind
FROM pg_statistic_ext
JOIN pg_class ON pg_statistic_ext.stxrelid = pg_class.oid
----
relname  stxname  stxnamespace  stxowner  stxstattarget  stxkeys  stxkind
stxtbl   stxobj   105           NULL      -1             {2,3}    {d}
stxtbl2  stxobj2  195           NULL      -1             {1,3}    {d}
stx      NULL     105           NULL      -1             {2}      {d}
stx      NULL     105           NULL      -1             {1}      {d}

# Regression test for https://github.com/cockroachdb/cockroach/issues/108813:
# pg_statistic_ext should still work after dropping the table.
statement ok
DROP TABLE test.stxtbl2

query TTOOITT colnames,rowsort
SELECT
  relname,
  stxname,
  stxnamespace,
  stxowner,
  stxstattarget,
  stxkeys,
  stxkind
FROM pg_statistic_ext
JOIN pg_class ON pg_statistic_ext.stxrelid = pg_class.oid
----
relname  stxname  stxnamespace  stxowner  stxstattarget  stxkeys  stxkind
stxtbl   stxobj   105           NULL      -1             {2,3}    {d}
stx      NULL     105           NULL      -1             {2}      {d}
stx      NULL     105           NULL      -1             {1}      {d}

# Test that pg_shadow doesn't include roles that can't login
query B colnames
SELECT (count(1) = 0) AS PASSED
FROM pg_shadow
WHERE EXISTS (
  SELECT 1 FROM pg_authid WHERE oid = usesysid AND NOT rolcanlogin
)
----
passed
true

# Test pg_shadow contents
query TOBBBBTTT colnames
SELECT * FROM pg_shadow ORDER BY usename;
----
usename                       usesysid    usecreatedb  usesuper  userepl  usebypassrls  passwd    valuntil                       useconfig
admin                         2310524507  true         true      false    false         ********  NULL                           NULL
anyuser                       2525089181  false        false     false    false         ********  NULL                           NULL
regression_70180              2066478618  false        false     false    false         ********  NULL                           NULL
regular_user                  3044356792  false        false     false    false         ********  NULL                           NULL
role_test_login               2531829827  false        false     false    false         ********  NULL                           NULL
role_test_nodate              1492950893  false        false     false    false         ********  NULL                           NULL
role_test_with_date           1212615927  false        false     false    false         ********  2021-01-01 00:00:00 +0000 UTC  NULL
role_test_with_date_timezone  1682504215  false        false     false    false         ********  2020-12-31 22:00:00 +0000 UTC  NULL
root                          1546506610  true         true      false    false         ********  NULL                           NULL
sh_owner                      2488412215  false        false     false    false         ********  NULL                           NULL
sh_user                       2387559583  false        false     false    false         ********  NULL                           NULL
super_user                    2430969455  false        true      false    false         ********  NULL                           NULL
testuser                      2264919399  false        false     false    false         ********  NULL                           NULL
testuser1                     3957504276  true         false     false    false         ********  NULL                           {timezone=America/Los_Angeles,application_name=a}
testuser2                     3957504279  false        false     false    false         ********  3022-01-01 00:00:00 +0000 UTC  NULL

# Testing oids references the same roles in pg_shadow and pg_authid
query B colnames
SELECT bool_and(usename = rolname) PASSED
FROM pg_shadow
JOIN pg_authid ON usesysid = oid
----
passed
true

# Regression test for crashing when performing a lookup join of NULL into
# pg_type.oid virtual table (#76768).
query T
SELECT pg_type.oid
FROM (SELECT null::OID AS b) AS a
INNER LOOKUP JOIN pg_type ON pg_type.oid=a.b
----

## pg_cast

# This should always be empty.
query OO
SELECT castsource, casttarget FROM pg_cast WHERE castfunc IS NULL
ORDER BY oid
----

query OOOOTT colnames
SELECT * FROM pg_cast
ORDER BY oid
----
oid         castsource  casttarget  castfunc  castcontext  castmethod
140679991   1042        25          2205      i            NULL
140679996   1042        18          2142      a            NULL
140679997   1042        19          2282      i            NULL
186882866   869         1042        2342      a            NULL
186882867   869         1043        2224      a            NULL
207790440   1042        1042        2347      i            NULL
207790441   1042        1043        2229      i            NULL
253993333   869         25          881       a            NULL
398529196   90002       90002       2362      i            NULL
398529198   90002       90000       2162      e            NULL
486164264   1266        1266        2083      i            NULL
486164449   1266        1083        2287      a            NULL
519779712   25          25          2205      i            NULL
519779722   25          19          2282      i            NULL
519779723   25          18          2142      a            NULL
586890230   25          1043        2229      i            NULL
586890231   25          1042        2347      i            NULL
637806108   700         1700        2355      a            NULL
641069276   1700        700         2167      i            NULL
641069277   1700        701         2106      i            NULL
654000812   25          2205        2237      i            NULL
674624401   1700        23          2150      a            NULL
674624402   1700        20          2087      a            NULL
674624403   1700        21          2300      a            NULL
704916921   700         701         2112      i            NULL
705151184   3802        16          2292      e            NULL
705151188   3802        20          2095      e            NULL
705151189   3802        21          2308      e            NULL
705151191   3802        23          2157      e            NULL
708179464   1700        1700        2349      i            NULL
718142737   1186        1083        2283      a            NULL
718142856   1186        1186        2310      i            NULL
738471997   700         23          2156      a            NULL
738471998   700         20          2094      a            NULL
738471999   700         21          2307      a            NULL
738706266   3802        700         2173      e            NULL
738706267   3802        701         2113      e            NULL
805816982   3802        1700        2356      e            NULL
939073229   25          90000       2165      i            NULL
1019153911  90002       17          2145      i            NULL
1039252266  19          25          2205      i            NULL
1106362732  19          1043        2229      a            NULL
1106362733  19          1042        2347      a            NULL
1298988567  16          23          2153      e            NULL
1298988569  16          25          2193      a            NULL
1366099038  16          1042        2335      a            NULL
1366099039  16          1043        2217      a            NULL
1418646496  1043        1043        2229      i            NULL
1418646497  1043        1042        2347      i            NULL
1485756966  1043        25          2205      i            NULL
1485756972  1043        19          2282      i            NULL
1485756973  1043        18          2142      a            NULL
1619977802  1043        2205        2237      i            NULL
1646747850  26          4089        2232      i            NULL
1730635912  26          2202        2176      i            NULL
1730635916  26          2206        2179      i            NULL
1730635919  26          2205        2235      i            NULL
1864856754  26          24          2316      i            NULL
1864856765  26          23          2152      a            NULL
1864856766  26          20          2089      a            NULL
1940039391  23          4089        2233      i            NULL
1984069072  1560        1560        2102      i            NULL
1984069074  1560        1562        2242      i            NULL
1990371905  23          2206        2180      i            NULL
1990371906  23          2205        2236      i            NULL
1990371909  23          2202        2177      i            NULL
2083548972  701         23          2156      a            NULL
2083548974  701         21          2307      a            NULL
2083548975  701         20          2094      a            NULL
2084734765  1560        23          2148      e            NULL
2084734766  1560        20          2085      e            NULL
2091037769  23          1560        2103      e            NULL
2091037941  23          1700        2352      i            NULL
2117104349  701         700         2175      a            NULL
2124592994  23          21          2304      a            NULL
2124592995  23          20          2091      i            NULL
2124592997  23          18          2131      e            NULL
2124592999  23          16          2290      e            NULL
2124593005  23          26          2256      i            NULL
2124593007  23          24          2317      i            NULL
2133298650  26          4096        2249      i            NULL
2146493458  1114        1184        2246      i            NULL
2146493576  1114        1082        2320      a            NULL
2146493577  1114        1083        2285      a            NULL
2146493672  1114        1114        2099      i            NULL
2158148128  23          701         2109      i            NULL
2158148129  23          700         2170      i            NULL
2173360273  2205        20          2089      a            NULL
2173360274  2205        23          2152      a            NULL
2173360287  2205        26          2258      i            NULL
2184214537  701         1700        2355      a            NULL
2188735018  1184        1114        2100      a            NULL
2188735050  1184        1082        2321      a            NULL
2188735051  1184        1083        2286      a            NULL
2188735106  1184        1266        2082      a            NULL
2188735184  1184        1184        2247      i            NULL
2233330912  20          4089        2233      i            NULL
2250108209  20          2205        2236      i            NULL
2250108210  20          2206        2180      i            NULL
2250108214  20          2202        2177      i            NULL
2350774022  20          1560        2103      e            NULL
2350774202  20          1700        2352      i            NULL
2384329297  20          21          2304      a            NULL
2384329299  20          23          2159      a            NULL
2384329308  20          24          2317      i            NULL
2384329310  20          26          2256      i            NULL
2393034919  23          4096        2250      i            NULL
2417884630  20          700         2170      i            NULL
2417884631  20          701         2109      i            NULL
2424867656  1082        1114        2097      i            NULL
2424867762  1082        1184        2244      i            NULL
2433096517  2202        23          2152      a            NULL
2433096518  2202        20          2089      a            NULL
2433096520  2202        26          2258      i            NULL
2433096522  2202        24          2316      i            NULL
2456191196  90000       3802        2252      e            NULL
2493265536  4089        20          2089      a            NULL
2493265539  4089        23          2152      a            NULL
2493265550  4089        26          2258      i            NULL
2623967189  90000       17          2144      i            NULL
2623967197  90000       25          2190      i            NULL
2652771188  20          4096        2250      i            NULL
2794916917  17          90000       2163      i            NULL
2794916919  17          90002       2363      i            NULL
3132647220  90004       90000       2160      i            NULL
3335448938  24          2202        2176      i            NULL
3460964389  21          4096        2250      i            NULL
3469670034  24          26          2258      i            NULL
3469670044  24          20          2089      a            NULL
3469670047  24          23          2152      a            NULL
3518437249  2206        23          2152      a            NULL
3518437250  2206        20          2089      a            NULL
3518437260  2206        26          2258      i            NULL
3628740423  21          1700        2352      i            NULL
3635723561  1083        1186        2312      i            NULL
3635723641  1083        1266        2081      i            NULL
3635723696  1083        1083        2284      i            NULL
3695851154  21          701         2109      i            NULL
3695851155  21          700         2170      i            NULL
3729406273  21          20          2091      i            NULL
3729406274  21          23          2159      i            NULL
3729406285  21          24          2317      i            NULL
3729406287  21          26          2256      i            NULL
3746183697  21          4089        2233      i            NULL
3790213776  1562        1562        2242      i            NULL
3790213778  1562        1560        2102      i            NULL
3815325360  90000       90000       2161      i            NULL
3815325362  90000       90002       2361      i            NULL
3815325364  90000       90004       2358      i            NULL
3854332660  4096        20          2089      a            NULL
3854332663  4096        23          2152      a            NULL
3854332666  4096        26          2258      i            NULL
3863627120  21          2205        2236      i            NULL
3863627123  21          2206        2180      i            NULL
3863627127  21          2202        2177      i            NULL
3922032068  18          1042        2347      a            NULL
3922032069  18          1043        2229      a            NULL
3989142581  18          23          2158      e            NULL
3989142587  18          25          2205      i            NULL

subtest seq_bound_should_consistent_with_session_var

statement ok
DROP sequence serial

statement ok
set default_int_size=4

statement ok
CREATE SEQUENCE serial START 101 INCREMENT 5

query TTTOIIIIBII colnames
SELECT * FROM pg_sequences WHERE sequencename = 'serial'
----
schemaname  sequencename  sequenceowner  data_type  start_value  min_value  max_value   increment_by  cycle  cache_size  last_value
public      serial        root           20         101          1          2147483647  5             false  1           NULL

statement ok
set default_int_size=8

query TTTOIIIIBII colnames
SELECT * FROM pg_sequences WHERE sequencename = 'serial'
----
schemaname  sequencename  sequenceowner  data_type  start_value  min_value  max_value   increment_by  cycle  cache_size  last_value
public      serial        root           20         101          1          2147483647  5             false  1           NULL

statement ok
DROP sequence serial

statement ok
CREATE SEQUENCE serial START 101 INCREMENT 5

query TTTOIIIIBII colnames
SELECT * FROM pg_sequences WHERE sequencename = 'serial'
----
schemaname  sequencename  sequenceowner  data_type  start_value  min_value  max_value            increment_by  cycle  cache_size  last_value
public      serial        root           20         101          1          9223372036854775807  5             false  1           NULL

statement ok
CREATE TABLE t (a INT PRIMARY KEY, b INT);
INSERT INTO t VALUES (1, 2), (2, 3);

statement ok
BEGIN;

statement ok
DECLARE "a"" b'c" CURSOR FOR TABLE t;
DECLARE "a b" CURSOR FOR TABLE t;
DECLARE "a\b" CURSOR FOR TABLE t;

## pg_catalog.pg_cursors

query TTBBB colnames
SELECT name, statement, is_holdable, is_binary, is_scrollable FROM pg_catalog.pg_cursors ORDER BY name;
----
name    statement  is_holdable  is_binary  is_scrollable
a b     TABLE t    false        false      false
a" b'c  TABLE t    false        false      false
a\b     TABLE t    false        false      false

statement ok
COMMIT;

statement ok
DROP TABLE t;

## Check key columns for indexes PG_Attribute
statement ok
CREATE TABLE t1(x int, y int primary key);

statement ok
CREATE TABLE t2(x int, y int);

statement ok
CREATE TABLE t3(x int, y int);

statement ok
CREATE INDEX t3idx ON t3(x) include(y);

query IT colnames
select attnum, attname from pg_attribute a join pg_class c on c.oid = a.attrelid where c.relname = 't1_pkey'
order by attnum;
----
attnum  attname
1       y

query IT colnames
select attnum, attname from pg_attribute a join pg_class c on c.oid = a.attrelid where c.relname = 't2_pkey'
order by attnum;
----
attnum  attname
1       rowid

query IT colnames
select attnum, attname from pg_attribute a join pg_class c on c.oid = a.attrelid where c.relname = 't3idx'
order by attnum;
----
attnum  attname
1       x
2       y

# Regression test for not projecting away looked up columns by the left semi
# virtual lookup join (#91012).
statement ok
CREATE TABLE t91012 (id INT, a_id INT);

query I
SELECT
    count(*)
FROM
    pg_class AS t INNER JOIN pg_attribute AS a ON t.oid = a.attrelid
WHERE
    a.attnotnull = 'f'
    AND a.attname = 'a_id'
    AND t.relname = 't91012'
    AND a.atttypid IN (SELECT oid FROM pg_type WHERE typname = ANY (ARRAY['int8']));
----
1

# Same query, but with left anti join instead.
query I
SELECT
    count(*)
FROM
    pg_class AS t INNER JOIN pg_attribute AS a ON t.oid = a.attrelid
WHERE
    a.attnotnull = 'f'
    AND a.attname = 'a_id'
    AND t.relname = 't91012'
    AND NOT EXISTS(SELECT 1 FROM pg_type WHERE typname = ANY (ARRAY['typefoo']) AND a.atttypid = oid);
----
1

# pg_timezone_names

# Test using LIKE to scan the whole table.
# Use Honolulu as there is no DST.
query TTTB
SELECT * from pg_timezone_names WHERE name LIKE 'Pacific/Honolulu%'
----
Pacific/Honolulu  HST  -10:00:00  false

# Test with the virtual index.
query TTTB
SELECT * from pg_timezone_names WHERE name = 'Pacific/Honolulu'
----
Pacific/Honolulu  HST  -10:00:00  false

query TTTB
SELECT * from pg_timezone_names WHERE name = 'DoesNotExist'
----

# Regression test for incorrectly handling left anti virtual lookup joins
# (#88096).
statement ok
CREATE TYPE mytype AS enum('hello')

query I
SELECT
    count(*)
FROM
    pg_type AS t
WHERE
    t.typrelid = 0
    AND NOT EXISTS(SELECT 1 FROM pg_type AS el WHERE el.oid = t.typelem AND el.typarray = t.oid)
    AND t.typname LIKE 'myt%';
----
1

# Same query, but with left semi join instead.
query I
SELECT
    count(*)
FROM
    pg_type AS t
WHERE
    t.typrelid = 0
    AND EXISTS(SELECT 1 FROM pg_type AS el WHERE el.oid = t.typelem AND el.typarray = t.oid)
    AND t.typname LIKE 'myt%';
----
0

# Regression test for a panic after physical planning combined rendering steps
# (#95633).
statement ok
SELECT d.datname, pg_catalog.pg_get_userbyid(d.datdba) FROM pg_catalog.pg_database d;

# pg_language

query OTOBBOOOT colnames
SELECT * FROM pg_language ORDER BY oid
----
oid    lanname   lanowner    lanispl  lanpltrusted  lanplcallfoid  laninline  lanvalidator  lanacl
12     internal  2310524507  false    false         0              0          0             NULL
14     sql       2310524507  false    true          0              0          0             NULL
14024  plpgsql   2310524507  true     true          0              0          0             NULL

subtest pg_class_composite_types

statement ok
CREATE TYPE u AS (ufoo int, ubar int);

query TTI colnames,rowsort
SELECT
    relname,
    relkind,
    relnatts
FROM
    pg_catalog.pg_class
WHERE
    relname = 'u';
----
relname  relkind  relnatts
u        c        2

query TTI colnames,rowsort
SELECT
    relname,
    relkind,
    relnatts
FROM
    pg_catalog.pg_class
WHERE
    oid = 'u'::regtype::oid;
----
relname  relkind  relnatts
u        c        2

subtest end

subtest pg_attribute_composite_types

query TII colnames,rowsort
SELECT
    attname,
    attlen,
    attnum
FROM
    pg_catalog.pg_attribute
WHERE
    attname IN ('ufoo', 'ubar');
----
attname  attlen  attnum
ufoo     8       1
ubar     8       2

query TII colnames,rowsort
SELECT
    attname,
    attlen,
    attnum
FROM
    pg_catalog.pg_attribute
WHERE
    attrelid = 'u'::regtype::oid;
----
attname  attlen  attnum
ufoo     8       1
ubar     8       2

subtest end

subtest pg_type_composite_types

query TO colnames,rowsort
SELECT typname, typrelid FROM pg_catalog.pg_type WHERE typrelid = 'u'::regtype::oid;
----
typname  typrelid
u        100207

query TOO colnames,rowsort
SELECT typname, typrelid, typarray FROM pg_catalog.pg_type WHERE oid = 'u[]'::regtype::oid;
----
typname  typrelid  typarray
_u       0         0

subtest end

subtest regression_126042

statement ok
CREATE TABLE t126042 (
  id INT8 NOT NULL PRIMARY KEY,
  b BYTES DEFAULT 'f'::BYTES,
  bytes_array BYTES[] DEFAULT '{f}'::BYTES[],
  text_array TEXT[] DEFAULT '{a, b}'::TEXT[]
)

# Regression test for #126042 and #126344. Expressions of type BYTES and BYTES[]
# should be parsable.
query TT
SELECT a.attname, pg_get_expr(d.adbin, d.adrelid)
FROM pg_attribute a
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = 't126042'::REGCLASS
ORDER BY 1
----
b            '\x66'::BYTES
bytes_array  '{"\\x66"}'::BYTES[]
id           NULL
text_array   '{a,b}'::STRING[]

subtest end

subtest pg_index_indkey_not_visible

# Verify that NOT VISIBLE columns still show up as part of an index.

statement ok
CREATE TABLE t_indkey_not_visible (
  a INT NOT VISIBLE,
  b INT,
  c INT NOT VISIBLE,
  d INT,
  PRIMARY KEY (a DESC, b ASC),
  INDEX idx_c_d (c, d)
)

query TB colnames
SELECT attname, attishidden
FROM pg_attribute
WHERE attrelid = 't_indkey_not_visible'::regclass::oid
ORDER BY attname
----
attname  attishidden
a        true
b        false
c        true
d        false

query TBTT colnames
SELECT ix_class.relname, ix.indisprimary, ix.indkey, ix.indoption
FROM pg_catalog.pg_index ix
JOIN pg_catalog.pg_class ix_class ON ix.indexrelid = ix_class.oid
WHERE ix.indrelid = 't_indkey_not_visible'::regclass::oid
ORDER BY 1
----
relname                    indisprimary  indkey  indoption
idx_c_d                    false         3 4     2 2
t_indkey_not_visible_pkey  true          1 2     1 2

subtest end
