Skip to content

Commit

Permalink
sql/opt/exec: output index/expiry in EXPLAIN SPLIT/RELOCATE statements
Browse files Browse the repository at this point in the history
Release note (sql change): The output of `EXPLAIN ALTER INDEX/TABLE
... RELOCATE/SPLIT` now includes the target table/index name and, for
the SPLIT AT variants, the expiry timestamp.
  • Loading branch information
knz committed Dec 16, 2021
1 parent d1c137d commit db59565
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/ddl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ vectorized: true
• split
│ columns: (key, pretty, split_enforced_until)
│ estimated row count: 10 (missing stats)
│ index: s@s_pkey
│ expiry: CAST(NULL AS STRING)
└── • scan
columns: (k1, k2)
Expand Down
23 changes: 23 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/explain
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ vectorized: true
• split
│ columns: (key, pretty, split_enforced_until)
│ estimated row count: 10 (missing stats)
│ index: foo@foo_pkey
│ expiry: CAST(NULL AS STRING)
└── • values
columns: (column1)
size: 1 column, 1 row
row 0, expr 0: 42

query T
EXPLAIN (VERBOSE) ALTER TABLE foo SPLIT AT VALUES (42) WITH EXPIRATION '2200-01-01 00:00:00.0'
----
distribution: local
vectorized: true
·
• split
│ columns: (key, pretty, split_enforced_until)
│ estimated row count: 10 (missing stats)
│ index: foo@foo_pkey
│ expiry: '2200-01-01 00:00:00.0'
└── • values
columns: (column1)
Expand All @@ -183,6 +202,7 @@ distribution: local
vectorized: true
·
• relocate table
│ index: foo@foo_pkey
└── • values
size: 2 columns, 1 row
Expand All @@ -196,6 +216,7 @@ vectorized: true
• relocate table
│ columns: (key, pretty)
│ estimated row count: 10 (missing stats)
│ index: foo@foo_pkey
└── • values
columns: (column1, column2)
Expand All @@ -210,6 +231,7 @@ distribution: local
vectorized: true
·
• relocate table
│ index: foo@a
└── • values
size: 2 columns, 1 row
Expand All @@ -223,6 +245,7 @@ vectorized: true
• relocate table
│ columns: (key, pretty)
│ estimated row count: 10 (missing stats)
│ index: foo@a
└── • values
columns: (column1, column2)
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/subquery
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ vectorized: true
• root
├── • split
│ │ index: abc@abc_pkey
│ │ expiry: CAST(NULL AS STRING)
│ │
│ └── • values
│ size: 1 column, 1 row
Expand Down
21 changes: 17 additions & 4 deletions pkg/sql/opt/exec/explain/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,23 @@ func (e *emitter) emitNodeAttributes(n *Node) error {
}
e.emitSpans("spans", a.Table, a.Table.Index(cat.PrimaryIndex), params)

case alterTableSplitOp:
a := n.args.(*alterTableSplitArgs)
ob.Attrf("index", "%s@%s", a.Index.Table().Name(), a.Index.Name())
ob.Expr("expiry", a.Expiration, nil /* columns */)

case alterTableUnsplitOp:
a := n.args.(*alterTableUnsplitArgs)
ob.Attrf("index", "%s@%s", a.Index.Table().Name(), a.Index.Name())

case alterTableUnsplitAllOp:
a := n.args.(*alterTableUnsplitAllArgs)
ob.Attrf("index", "%s@%s", a.Index.Table().Name(), a.Index.Name())

case alterTableRelocateOp:
a := n.args.(*alterTableRelocateArgs)
ob.Attrf("index", "%s@%s", a.Index.Table().Name(), a.Index.Name())

case recursiveCTEOp:
a := n.args.(*recursiveCTEArgs)
if e.ob.flags.Verbose && a.Deduplicate {
Expand Down Expand Up @@ -852,10 +869,6 @@ func (e *emitter) emitNodeAttributes(n *Node) error {
saveTableOp,
errorIfRowsOp,
opaqueOp,
alterTableSplitOp,
alterTableUnsplitOp,
alterTableUnsplitAllOp,
alterTableRelocateOp,
controlJobsOp,
controlSchedulesOp,
cancelQueriesOp,
Expand Down
9 changes: 9 additions & 0 deletions pkg/sql/opt/exec/explain/testdata/gists
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,14 @@ hash: 12193483658718214527
plan-gist: AgICAgYCLGoCBgY=
explain(shape):
• split
│ index: foo@foo_pkey
│ expiry: CAST(_ AS STRING)
└── • values
size: 1 column, 1 row
explain(gist):
• split
│ index: foo@foo_pkey
└── • values
size: 1 column, 1 row
Expand All @@ -879,11 +882,13 @@ hash: 8861506885543083786
plan-gist: AgICAgYCLWoCBgQ=
explain(shape):
• unsplit
│ index: foo@foo_pkey
└── • values
size: 1 column, 1 row
explain(gist):
• unsplit
│ index: foo@foo_pkey
└── • values
size: 1 column, 1 row
Expand All @@ -897,8 +902,10 @@ hash: 16533768908468588919
plan-gist: Ai5qAgYE
explain(shape):
• unsplit all
index: foo@foo_pkey
explain(gist):
• unsplit all
index: foo@foo_pkey

# alterTableRelocateOp
gist-explain-roundtrip
Expand All @@ -908,11 +915,13 @@ hash: 8656743312841134920
plan-gist: AgICBAYEL24CBgQ=
explain(shape):
• relocate table
│ index: abc@abc_pkey
└── • values
size: 2 columns, 1 row
explain(gist):
• relocate table
│ index: abc@abc_pkey
└── • values
size: 2 columns, 1 row
Expand Down

0 comments on commit db59565

Please sign in to comment.