# LogicTest: default distsql

query ITTT colnames
EXPLAIN (PLAN) SELECT 1 FROM system.jobs WHERE FALSE
----
Level  Type     Field  Description
0      render   ·      ·
1      norows   ·      ·

query ITTTTT colnames
EXPLAIN (PLAN, METADATA) SELECT 1
----
Level  Type      Field  Description  Columns  Ordering
0      render    ·      ·            ("1")    ="1"
1      emptyrow  ·      ·            ()       ·

query ITTTTT colnames
EXPLAIN (METADATA,PLAN) SELECT 1
----
Level  Type     Field  Description  Columns  Ordering
0      render   ·      ·            ("1")    ="1"
1      emptyrow ·      ·            ()       ·

query T
SELECT message FROM [SHOW KV TRACE FOR SELECT 1]
 WHERE message LIKE 'fetched:%' OR message LIKE 'output row%'
----
output row: [1]

query ITTTTT colnames
EXPLAIN (TYPES) SELECT 1
----
Level  Type     Field     Description  Columns    Ordering
0      render   ·         ·            ("1" int)  ="1"
0      ·        render 0  (1)[int]     ·          ·
1      emptyrow ·         ·            ()         ·

statement error cannot set EXPLAIN mode more than once
EXPLAIN (PLAN,PLAN) SELECT 1

statement error cannot set EXPLAIN mode more than once
EXPLAIN (PLAN,DISTSQL) SELECT 1

statement error unsupported EXPLAIN option
EXPLAIN (PLAN,UNKNOWN) SELECT 1

# Ensure that tracing results are sorted after gathering
query ITTTTT
EXPLAIN (METADATA) SHOW TRACE FOR SELECT 1
----
0  sort            ·      ·             ("timestamp", age, message, context, operation, span)                             +"timestamp"
0  ·               order  +"timestamp"  ·                                                                                 ·
1  window          ·      ·             ("timestamp", age, message, context, operation, span)                             ·
2  render          ·      ·             ("timestamp", """timestamp""", message, context, operation, span)                 ·
3  window          ·      ·             ("timestamp", message, context, operation, span)                                  ·
4  render          ·      ·             ("timestamp", message, context, operation, span, txn_idx, span_idx, message_idx)  ·
5  show trace for  ·      ·             (txn_idx, span_idx, message_idx, "timestamp", duration, operation, message)       ·
6  render          ·      ·             ("1")                                                                             ="1"
7  emptyrow        ·      ·             ()                                                                                ·

# Ensure that all relevant statement types can be explained
query ITTT
EXPLAIN CREATE DATABASE foo
----
0  create database  ·  ·

query ITTT
EXPLAIN CREATE TABLE foo (x INT)
----
0  create table  ·  ·

statement ok
CREATE TABLE foo (x INT)

query ITTT
EXPLAIN CREATE INDEX a ON foo(x)
----
0  create index  ·  ·

statement ok
CREATE DATABASE foo

query ITTT
EXPLAIN DROP DATABASE foo
----
0  drop database  ·  ·

# explain SHOW JOBS - beware to test this before the CREATE INDEX
# below, otherwise the result becomes non-deterministic.
query ITTT
EXPLAIN SHOW JOBS
----
0  render  ·     ·
1  values  ·     ·
1  ·       size  13 columns, 0 rows

statement ok
CREATE INDEX a ON foo(x)

query ITTT
EXPLAIN DROP INDEX foo@a
----
0  drop index  ·  ·

query ITTT
EXPLAIN ALTER TABLE foo ADD COLUMN y INT
----
0  alter table  ·  ·

query ITTT
EXPLAIN (EXPRS) ALTER TABLE foo SPLIT AT VALUES (42)
----
0  split   ·              ·
1  values  ·              ·
1  ·       size           1 column, 1 row
1  ·       row 0, expr 0  42

query ITTT
EXPLAIN DROP TABLE foo
----
0  drop table  ·  ·

query ITTT
EXPLAIN SHOW DATABASES
----
0  sort    ·      ·
0  ·       order  +"Database"
1  render  ·      ·
2  values  ·      ·
2  ·       size   4 columns, 6 rows

query ITTT
EXPLAIN SHOW TABLES
----
0  sort    ·      ·
0  ·       order  +"Table"
1  render  ·      ·
2  filter  ·      ·
3  values  ·      ·
3  ·       size   5 columns, 68 rows

query ITTT
EXPLAIN SHOW DATABASE
----
0  render  ·     ·
1  filter  ·     ·
2  values  ·     ·
2  ·       size  2 columns, 20 rows

query ITTT
EXPLAIN SHOW TIME ZONE
----
0  render  ·     ·
1  filter  ·     ·
2  values  ·     ·
2  ·       size  2 columns, 20 rows

query ITTT
EXPLAIN SHOW DEFAULT_TRANSACTION_ISOLATION
----
0  render  ·     ·
1  filter  ·     ·
2  values  ·     ·
2  ·       size  2 columns, 20 rows

query ITTT
EXPLAIN SHOW TRANSACTION ISOLATION LEVEL
----
0  render  ·     ·
1  filter  ·     ·
2  values  ·     ·
2  ·       size  2 columns, 20 rows

query ITTT
EXPLAIN SHOW TRANSACTION PRIORITY
----
0  render  ·     ·
1  filter  ·     ·
2  values  ·     ·
2  ·       size  2 columns, 20 rows

query ITTT
EXPLAIN SHOW COLUMNS FROM foo
----
0  sort    ·         ·
0  ·       order     +ordinal_position
1  render  ·         ·
2  group   ·         ·
2  ·       group by  @1-@5
3  render  ·         ·
4  join    ·         ·
4  ·       type      left outer
4  ·       equality  (column_name) = (column_name)
5  render  ·         ·
6  filter  ·         ·
7  values  ·         ·
7  ·       size      13 columns, 574 rows
5  render  ·         ·
6  filter  ·         ·
7  values  ·         ·
7  ·       size      13 columns, 27 rows

query ITTT
EXPLAIN SHOW GRANTS ON foo
----
0  sort    ·      ·
0  ·       order  +"Table",+"User",+"Privileges"
1  render  ·      ·
2  filter  ·      ·
3  values  ·      ·
3  ·       size   8 columns, 50 rows


query ITTT
EXPLAIN SHOW INDEX FROM foo
----
0  render  ·     ·
1  filter  ·     ·
2  values  ·     ·
2  ·       size  13 columns, 27 rows

query ITTT
EXPLAIN SHOW CONSTRAINTS FROM foo
----
0  sort    ·      ·
0  ·       order  +"Table",+"Name"
1  values  ·      ·
1  ·       size   5 columns, 0 rows

query ITTT
EXPLAIN SHOW USERS
----
0  render  ·      ·
1  scan    ·      ·
1  ·       table  users@primary
1  ·       spans  ALL
