# LogicTest: default distsql

query ITTT colnames
EXPLAIN (PLAN) SELECT 1
----
Level  Type    Field Description
0      render
1      nullrow

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

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

query ITTT colnames
EXPLAIN (DEBUG) SELECT 1
----
RowIdx  Key  Value  Disposition
0       NULL NULL   ROW

query ITTT colnames
EXPLAIN (DEBUG,METADATA) SELECT 1
----
RowIdx  Key  Value  Disposition
0       NULL NULL   ROW

query TITTITTT colnames
SELECT "Duration", "Span Pos", "Operation", "Event", "RowIdx", "Key", "Value", "Disposition" FROM [EXPLAIN (TRACE) SELECT 1]
----
Duration  Span Pos  Operation      Event              RowIdx  Key   Value  Disposition
          1                                           0       NULL  NULL   t
          0         explain trace  tracing completed  0       NULL         NULL

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

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

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

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

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

# Ensure that tracing results are sorted after gathering
query ITTTTT
EXPLAIN (METADATA) EXPLAIN (TRACE) SELECT 1
----
0  sort                                            ("Cumulative Time", "Duration", "Span Pos", "Operation", "Event", "RowIdx", "Key", "Value", "Disposition")
0                 order  +"Timestamp",+"Span Pos"
1  explain trace                                   ("Cumulative Time", "Duration", "Span Pos", "Operation", "Event", "RowIdx", "Key", "Value", "Disposition", "Timestamp")
2  render                                          ("1")                                                                                                                    ="1"
3  nullrow                                         ()

# 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

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  virtual table
2                 source  information_schema.schemata
3  values
3                 size    4 columns, 6 rows

query ITTT
EXPLAIN SHOW TABLES
----
0  virtual table
0                 source  SHOW TABLES FROM test
1  values
1                 size    1 column, 1 row

query ITTT
EXPLAIN SHOW DATABASE
----
0  virtual table
0                 source  SHOW database
1  values
1                 size    1 column, 1 row

query ITTT
EXPLAIN SHOW TIME ZONE
----
0 virtual table
0                 source  SHOW TIME ZONE
1 values
1                 size    1 column, 1 row

query ITTT
EXPLAIN SHOW DEFAULT_TRANSACTION_ISOLATION
----
0  virtual table
0                 source  SHOW default_transaction_isolation
1  values
1                 size    1 column, 1 row

query ITTT
EXPLAIN SHOW TRANSACTION ISOLATION LEVEL
----
0 virtual table
0                 source  SHOW TRANSACTION ISOLATION LEVEL
1 values
1                 size    1 column, 1 row

query ITTT
EXPLAIN SHOW TRANSACTION PRIORITY
----
0 virtual table
0                 source  SHOW TRANSACTION PRIORITY
1 values
1                 size    1 column, 1 row

query ITTT
EXPLAIN SHOW COLUMNS FROM foo
----
0  virtual table
0                 source  SHOW COLUMNS FROM foo
1  values
1                 size    5 columns, 1 row

query ITTT
EXPLAIN SHOW GRANTS ON foo
----
0  virtual table
0                 source  SHOW GRANTS
1  sort
1                 order   +"Table",+"User",+"Privileges"
2  values
2                 size    3 columns, 1 row

query ITTT
EXPLAIN SHOW INDEX FROM foo
----
0  virtual table
0                 source  SHOW INDEXES FROM foo
1  values
1                 size    8 columns, 3 rows

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

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