From 279c1a3057d2dbc4e07f5abda4001dcc4d5a28f2 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Thu, 23 Jul 2020 09:01:06 -0700 Subject: [PATCH] opt: improve the partial index label in EXPLAIN This commit moves the "partial index" mention next to the name of the index. Release note: None --- .../exec/execbuilder/testdata/partial_index | 11 ++++--- pkg/sql/walk.go | 29 +++++++++---------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/pkg/sql/opt/exec/execbuilder/testdata/partial_index b/pkg/sql/opt/exec/execbuilder/testdata/partial_index index 9db49bc353eb..cdf9563d36b1 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/partial_index +++ b/pkg/sql/opt/exec/execbuilder/testdata/partial_index @@ -286,9 +286,8 @@ InitPut /Table/53/4/"foo"/22/0 -> /BYTES/ 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 diff --git a/pkg/sql/walk.go b/pkg/sql/walk.go index 8a482c6fe94b..cbeb902540fd 100644 --- a/pkg/sql/walk.go +++ b/pkg/sql/walk.go @@ -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") } @@ -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)) } @@ -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) @@ -844,6 +831,16 @@ func (v *planVisitor) metadataTuples(nodeName string, tuples [][]tree.TypedExpr) } } +// formatTable returns a string of the form "@", or +// "@ (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(