Skip to content

Commit

Permalink
sql: use precise capacity for row container in a few places
Browse files Browse the repository at this point in the history
This commit audits all callers of `newContainerValuesNode` to specify
the precise capacity of the underlying row container since in all places
we know upfront how many rows the valuesNode will have. (Just happened to
notice it while working around one of those places.)

Epic: None

Release note: None
  • Loading branch information
yuzefovich committed Sep 26, 2023
1 parent 46cb4e3 commit 724e1f1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/explain_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (e *explainPlanNode) startExec(params runParams) error {
rows = append(rows, fmt.Sprintf(" SQL command%s: %s", plural, recs[i].SQL))
}
}
v := params.p.newContainerValuesNode(colinfo.ExplainPlanColumns, 0)
v := params.p.newContainerValuesNode(colinfo.ExplainPlanColumns, len(rows))
datums := make([]tree.DString, len(rows))
for i, row := range rows {
datums[i] = tree.DString(row)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/show_cluster_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func planShowClusterSetting(
}
}

v := p.newContainerValuesNode(columns, 0)
v := p.newContainerValuesNode(columns, 1)
if _, err := v.rows.AddRow(ctx, tree.Datums{d}); err != nil {
v.rows.Close(ctx)
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/show_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (p *planner) ShowHistogram(ctx context.Context, n *tree.ShowHistogram) (pla
return nil, err
}

v := p.newContainerValuesNode(showHistogramColumns, 0)
v := p.newContainerValuesNode(showHistogramColumns, len(histogram.Buckets))
resolver := descs.NewDistSQLTypeResolver(p.descCollection, p.InternalSQLTxn().KV())
if err := typedesc.EnsureTypeIsHydrated(ctx, histogram.ColumnType, &resolver); err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion pkg/sql/show_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ func (p *planner) ShowTableStats(ctx context.Context, n *tree.ShowTableStats) (p
}
}

v := p.newContainerValuesNode(columns, 0)
rowContainerCap := len(rows)
if n.UsingJSON {
rowContainerCap = 1
}
v := p.newContainerValuesNode(columns, rowContainerCap)
if n.UsingJSON {
result := make([]stats.JSONStatistic, 0, len(rows))
for _, r := range rows {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/show_zone_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (p *planner) ShowZoneConfig(ctx context.Context, n *tree.ShowZoneConfig) (p
name: n.String(),
columns: showZoneConfigColumns,
constructor: func(ctx context.Context, p *planner) (planNode, error) {
v := p.newContainerValuesNode(showZoneConfigColumns, 0)
v := p.newContainerValuesNode(showZoneConfigColumns, 1)

// This signifies SHOW ALL.
// However, SHOW ALL should be handled by the delegate.
Expand Down

0 comments on commit 724e1f1

Please sign in to comment.