Skip to content

Commit

Permalink
Merge #51839
Browse files Browse the repository at this point in the history
51839: opt: improve the partial index label in EXPLAIN r=RaduBerinde a=RaduBerinde

This commit moves the "partial index" mention next to the name of the
index.

Release note: None

Co-authored-by: Radu Berinde <[email protected]>
  • Loading branch information
craig[bot] and RaduBerinde committed Jul 27, 2020
2 parents c37e92d + 279c1a3 commit 069d328
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
11 changes: 5 additions & 6 deletions pkg/sql/opt/exec/execbuilder/testdata/partial_index
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,8 @@ CPut /Table/54/2/4/2/0 -> /BYTES/ (expecting does not exist)
query TTT
EXPLAIN SELECT b FROM t WHERE b > 10
----
· distribution local
· vectorized true
scan · ·
· table t@b_partial
· spans FULL SCAN
· partial index ·
· distribution local
· vectorized true
scan · ·
· table t@b_partial (partial index)
· spans FULL SCAN
29 changes: 13 additions & 16 deletions pkg/sql/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (v *planVisitor) visitInternal(plan planNode, name string) {

case *scanNode:
if v.observer.attr != nil {
v.observer.attr(name, "table", fmt.Sprintf("%s@%s", n.desc.Name, n.index.Name))
v.observer.attr(name, "table", formatTable(n.desc, n.index))
if n.noIndexJoin {
v.observer.attr(name, "hint", "no index join")
}
Expand All @@ -183,9 +183,6 @@ func (v *planVisitor) visitInternal(plan planNode, name string) {
if n.parallelize {
v.observer.attr(name, "parallel", "")
}
if n.index.IsPartial() {
v.observer.attr(name, "partial index", "")
}
if n.hardLimit > 0 {
v.observer.attr(name, "limit", fmt.Sprintf("%d", n.hardLimit))
}
Expand Down Expand Up @@ -354,30 +351,20 @@ func (v *planVisitor) visitInternal(plan planNode, name string) {
case *interleavedJoinNode:
if v.observer.attr != nil {
v.observer.attr(name, "type", joinTypeStr(n.joinType))
v.observer.attr(name, "left table", fmt.Sprintf("%s@%s", n.left.desc.Name, n.left.index.Name))
v.observer.attr(name, "left table", formatTable(n.left.desc, n.left.index))
}
if v.observer.spans != nil {
v.observer.spans(name, "left spans", n.left.index, n.left.spans, n.left.hardLimit != 0)
}
if v.observer.attr != nil {
if n.left.index.IsPartial() {
v.observer.attr(name, "left partial index", "")
}
}
if v.observer.expr != nil {
v.expr(name, "left filter", -1, n.leftFilter)
}
if v.observer.attr != nil {
v.observer.attr(name, "right table", fmt.Sprintf("%s@%s", n.right.desc.Name, n.right.index.Name))
v.observer.attr(name, "right table", formatTable(n.right.desc, n.right.index))
}
if v.observer.spans != nil {
v.observer.spans(name, "right spans", n.right.index, n.right.spans, n.right.hardLimit != 0)
}
if v.observer.attr != nil {
if n.right.index.IsPartial() {
v.observer.attr(name, "right partial index", "")
}
}
if v.observer.expr != nil {
v.expr(name, "right filter", -1, n.rightFilter)
v.expr(name, "pred", -1, n.onCond)
Expand Down Expand Up @@ -844,6 +831,16 @@ func (v *planVisitor) metadataTuples(nodeName string, tuples [][]tree.TypedExpr)
}
}

// formatTable returns a string of the form "<table_name>@<index_name>", or
// "<table_name>@<index_name> (partial index)" if the index is partial.
func formatTable(desc *sqlbase.ImmutableTableDescriptor, index *sqlbase.IndexDescriptor) string {
partial := ""
if index.IsPartial() {
partial = " (partial index)"
}
return fmt.Sprintf("%s@%s%s", desc.Name, index.Name, partial)
}

// formatValuesSize returns a string of the form "5 columns, 1 row".
func formatValuesSize(numRows, numCols int) string {
return fmt.Sprintf(
Expand Down

0 comments on commit 069d328

Please sign in to comment.