# LogicTest: local local-opt

query T colnames
SELECT * FROM [SHOW client_encoding]
----
client_encoding
UTF8

query T colnames
SELECT c.x FROM [SHOW client_encoding] AS c(x)
----
x
UTF8

query TI colnames
SELECT * FROM [SHOW client_encoding] WITH ORDINALITY
----
client_encoding     ordinality
UTF8                1

# We filter here because optimizer will be different depending on which
# configuration this logic test is running in.
query TT colnames
SELECT *
FROM [SHOW ALL]
WHERE variable != 'optimizer' AND variable != 'crdb_version'
----
variable                             value
application_name                     ·
bytea_output                         hex
client_encoding                      UTF8
client_min_messages                  notice
database                             test
datestyle                            ISO, MDY
default_int_size                     8
default_transaction_isolation        serializable
default_transaction_read_only        off
distsql                              off
experimental_enable_zigzag_join      off
experimental_force_split_at          off
experimental_serial_normalization    rowid
experimental_vectorize               off
extra_float_digits                   0
force_savepoint_restart              off
idle_in_transaction_session_timeout  0
integer_datetimes                    on
intervalstyle                        postgres
lock_timeout                         0
max_index_keys                       32
node_id                              1
reorder_joins_limit                  4
results_buffer_size                  16384
row_security                         off
search_path                          public
server_encoding                      UTF8
server_version                       9.5.0
server_version_num                   90500
session_user                         root
sql_safe_updates                     off
standard_conforming_strings          on
statement_timeout                    0
synchronize_seqscans                 on
timezone                             UTC
tracing                              off
transaction_isolation                serializable
transaction_priority                 normal
transaction_read_only                off
transaction_status                   NoTxn

query I colnames
SELECT * FROM [SHOW CLUSTER SETTING sql.defaults.distsql]
----
sql.defaults.distsql
0

query TTTT colnames
SELECT * FROM [SHOW ALL CLUSTER SETTINGS] WHERE variable LIKE '%organization'
----
variable              value  setting_type  description
cluster.organization  ·      s             organization name

query T colnames
SELECT * FROM [SHOW SESSION_USER]
----
session_user
root

query T colnames
SELECT * FROM [SHOW DATABASE]
----
database
test

query TT colnames
SELECT * FROM [SHOW ZONE CONFIGURATIONS] LIMIT 0
----
zone_name  config_sql

query TT colnames
SELECT * FROM [SHOW ZONE CONFIGURATION FOR TABLE system.users] LIMIT 0
----
zone_name  config_sql

query T colnames
SELECT * FROM [SHOW DATABASES]
----
database_name
defaultdb
postgres
system
test

query TTTTT colnames
SELECT * FROM [SHOW GRANTS ON system.descriptor]
----
database_name  schema_name  table_name  grantee  privilege_type
system         public       descriptor  admin    GRANT
system         public       descriptor  admin    SELECT
system         public       descriptor  root     GRANT
system         public       descriptor  root     SELECT

query TTBITTBB colnames
SELECT * FROM [SHOW INDEX FROM system.descriptor]
----
table_name  index_name  non_unique  seq_in_index  column_name  direction  storing  implicit
descriptor  primary     false       1             id           ASC        false    false

query TTTTB colnames
SELECT * FROM [SHOW CONSTRAINT FROM system.descriptor]
----
table_name  constraint_name  constraint_type  details               validated
descriptor  primary          PRIMARY KEY      PRIMARY KEY (id ASC)  true

query TTBITTBB colnames
SELECT * FROM [SHOW KEYS FROM system.descriptor]
----
table_name  index_name  non_unique  seq_in_index  column_name  direction  storing  implicit
descriptor  primary     false       1             id           ASC        false    false

query T colnames
SELECT * FROM [SHOW SCHEMAS FROM system]
----
schema_name
crdb_internal
information_schema
pg_catalog
public

query T colnames
SELECT * FROM [SHOW SEQUENCES FROM system]
----
sequence_name

query T colnames
SELECT * FROM [SHOW TABLES FROM system]
----
table_name
comments
descriptor
eventlog
jobs
lease
locations
namespace
rangelog
role_members
settings
table_statistics
ui
users
web_sessions
zones

query TT colnames
SELECT * FROM [SHOW TABLES FROM system WITH COMMENT]
----
table_name        comment
namespace         ·
descriptor        ·
users             ·
zones             ·
settings          ·
lease             ·
eventlog          ·
rangelog          ·
ui                ·
jobs              ·
web_sessions      ·
table_statistics  ·
locations         ·
role_members      ·
comments          ·

query ITTT colnames
SELECT node_id, user_name, application_name, active_queries
  FROM [SHOW SESSIONS]
 WHERE active_queries != ''
----
node_id  user_name  application_name  active_queries
1        root       ·                 SELECT node_id, user_name, application_name, active_queries FROM [SHOW CLUSTER SESSIONS] WHERE active_queries != ''

query ITT colnames
SELECT node_id, user_name, query FROM [SHOW QUERIES]
----
node_id  user_name  query
1        root       SELECT node_id, user_name, query FROM [SHOW CLUSTER QUERIES]


query T colnames
SELECT * FROM [SHOW SCHEMAS]
----
schema_name
crdb_internal
information_schema
pg_catalog
public

query T colnames
CREATE TABLE foo(x INT); SELECT * FROM [SHOW TABLES]
----
table_name
foo


query T colnames
SELECT * FROM [SHOW TIMEZONE]
----
timezone
UTC


query T colnames
SELECT * FROM [SHOW TIME ZONE]
----
timezone
UTC


query T colnames
SELECT * FROM [SHOW TRANSACTION ISOLATION LEVEL]
----
transaction_isolation
serializable


query T colnames
SELECT * FROM [SHOW TRANSACTION PRIORITY]
----
transaction_priority
normal

query T colnames
SELECT * FROM [SHOW TRANSACTION STATUS]
----
transaction_status
NoTxn


query TT colnames
SELECT * FROM [SHOW CREATE TABLE system.descriptor]
----
table_name                create_statement
system.public.descriptor  CREATE TABLE descriptor (
                          id INT8 NOT NULL,
                          descriptor BYTES NULL,
                          CONSTRAINT "primary" PRIMARY KEY (id ASC),
                          FAMILY "primary" (id),
                          FAMILY fam_2_descriptor (descriptor)
)


query TT colnames
CREATE VIEW v AS SELECT id FROM system.descriptor; SELECT * FROM [SHOW CREATE VIEW v]
----
table_name  create_statement
v           CREATE VIEW v (id) AS SELECT id FROM system.public.descriptor


query T colnames
SELECT * FROM [SHOW USERS]
----
user_name
root
testuser


query TTTI colnames
SELECT start_key, end_key, replicas, lease_holder FROM [SHOW EXPERIMENTAL_RANGES FROM TABLE system.descriptor]
----
start_key  end_key  replicas  lease_holder
NULL       NULL     {1}       1

query TTTI colnames
CREATE INDEX ix ON foo(x); SELECT start_key, end_key, replicas, lease_holder FROM [SHOW EXPERIMENTAL_RANGES FROM INDEX foo@ix]
----
start_key  end_key  replicas  lease_holder
NULL       NULL     {1}       1

query TTTTTTT colnames
SELECT * FROM [SHOW TRACE FOR SESSION] LIMIT 0
----
timestamp  age  message  tag  location  operation  span

query TTTT colnames
SELECT * FROM [SHOW COMPACT TRACE FOR SESSION] LIMIT 0
----
age  message  tag  operation

query ITTTTTTTTTTRTI colnames
SELECT * FROM [SHOW JOBS] LIMIT 0
----
job_id  job_type  description  statement  user_name  status  running_status  created  started  finished  modified  fraction_completed  error  coordinator_id

query TT colnames
SELECT * FROM [SHOW SYNTAX 'select 1; select 2']
----
field  text
sql    SELECT 1
sql    SELECT 2

# Test the SHOW SYNTAX statement. We avoid printing out the line number
# here because that is highly likely to change as code is edited.
query TT colnames
SELECT field, replace(text, e'\n', ' ') AS text FROM [SHOW SYNTAX 'foo']
 WHERE field != 'line'
----
field     text
error     syntax error at or near "foo"
code      42601
file      sql/show_syntax.go
function  runShowSyntax
detail    source SQL: foo ^
