Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: don't use delegateQuery for ShowZoneConfig #37169

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ CREATE TABLE crdb_internal.zones (
if err != nil {
return err
}
values := make(tree.Datums, len(showZoneConfigNodeColumns))
values := make(tree.Datums, len(showZoneConfigColumns))
for _, r := range rows {
id := uint32(tree.MustBeDInt(r[0]))

Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/expand_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ func doExpandPlan(
case *setVarNode:
case *setClusterSettingNode:
case *setZoneConfigNode:
case *showZoneConfigNode:
case *showFingerprintsNode:
case *showTraceNode:
case *scatterNode:
Expand Down Expand Up @@ -903,7 +902,6 @@ func (p *planner) simplifyOrderings(plan planNode, usefulOrdering sqlbase.Column
case *setVarNode:
case *setClusterSettingNode:
case *setZoneConfigNode:
case *showZoneConfigNode:
case *showFingerprintsNode:
case *showTraceNode:
case *scatterNode:
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/opt_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ func (p *planner) propagateFilters(
case *setVarNode:
case *setClusterSettingNode:
case *setZoneConfigNode:
case *showZoneConfigNode:
case *showFingerprintsNode:
case *showTraceNode:
case *scatterNode:
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/opt_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ func (p *planner) applyLimit(plan planNode, numRows int64, soft bool) {
case *setVarNode:
case *setClusterSettingNode:
case *setZoneConfigNode:
case *showZoneConfigNode:
case *showFingerprintsNode:
case *showTraceNode:
case *scatterNode:
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/opt_needed.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func setNeededColumns(plan planNode, needed []bool) {
case *setVarNode:
case *setClusterSettingNode:
case *setZoneConfigNode:
case *showZoneConfigNode:
case *showFingerprintsNode:
case *showTraceNode:
case *scatterNode:
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/plan_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ func getPlanColumns(plan planNode, mut bool) sqlbase.ResultColumns {
return n.getColumns(mut, relocateNodeColumns)
case *scatterNode:
return n.getColumns(mut, scatterNodeColumns)
case *showZoneConfigNode:
return n.getColumns(mut, showZoneConfigNodeColumns)
case *showFingerprintsNode:
return n.getColumns(mut, showFingerprintsColumns)
case *splitNode:
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/plan_physical_props.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func planPhysicalProps(plan planNode) physicalProps {
case *showFingerprintsNode:
case *showTraceNode:
case *showTraceReplicaNode:
case *showZoneConfigNode:
case *splitNode:
case *truncateNode:
case *unaryNode:
Expand Down
120 changes: 57 additions & 63 deletions pkg/sql/show_zone_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ import (
yaml "gopkg.in/yaml.v2"
)

type showZoneConfigNode struct {
optColumnsSlot
zoneSpecifier tree.ZoneSpecifier

run showZoneConfigRun
}

// These must match crdb_internal.zones.
var showZoneConfigNodeColumns = sqlbase.ResultColumns{
var showZoneConfigColumns = sqlbase.ResultColumns{
{Name: "zone_id", Typ: types.Int, Hidden: true},
{Name: "zone_name", Typ: types.String},
{Name: "cli_specifier", Typ: types.String, Hidden: true},
Expand All @@ -57,55 +50,66 @@ const (
)

func (p *planner) ShowZoneConfig(ctx context.Context, n *tree.ShowZoneConfig) (planNode, error) {
if n.ZoneSpecifier == (tree.ZoneSpecifier{}) {
planRenderNode, err := p.delegateQuery(ctx, "SHOW ZONE CONFIGURATIONS",
`SELECT zone_id, cli_specifier AS zone_name, cli_specifier, config_sql
FROM crdb_internal.zones
WHERE cli_specifier IS NOT NULL`, nil, nil)
if err != nil {
return planRenderNode, err
}
return &delayedNode{
name: n.String(),
columns: showZoneConfigColumns,
constructor: func(ctx context.Context, p *planner) (planNode, error) {
v := p.newContainerValuesNode(showZoneConfigColumns, 0)

// Using planMutableColumns to hide the cli_specifier column,
// that needs to be supported for backwards compatibility with
// the CLI.
columns := planMutableColumns(planRenderNode)
columns[zoneIDCol].Hidden = true
columns[cliSpecifierCol].Hidden = true

return planRenderNode, nil
}
return &showZoneConfigNode{
zoneSpecifier: n.ZoneSpecifier,
if n.ZoneSpecifier == (tree.ZoneSpecifier{}) {
// SHOW ALL ZONE CONFIGURATIONS case.
rows, err := p.ExtendedEvalContext().ExecCfg.InternalExecutor.Query(
ctx,
"show-all-zone-configurations",
p.txn,
`SELECT zone_id, zone_name, cli_specifier, config_yaml, config_sql, config_protobuf
FROM crdb_internal.zones
WHERE cli_specifier IS NOT NULL`,
)
if err != nil {
return nil, err
}
for i := range rows {
if _, err := v.rows.AddRow(ctx, rows[i]); err != nil {
v.Close(ctx)
return nil, err
}
}
} else {
row, err := getShowZoneConfigRow(ctx, p, n.ZoneSpecifier)
if err != nil {
v.Close(ctx)
return nil, err
}
if _, err := v.rows.AddRow(ctx, row); err != nil {
v.Close(ctx)
return nil, err
}
}
return v, nil
},
}, nil
}

// showZoneConfigRun contains the run-time state of showZoneConfigNode
// during local execution.
type showZoneConfigRun struct {
values tree.Datums
done bool
}

func (n *showZoneConfigNode) startExec(params runParams) error {
tblDesc, err := params.p.resolveTableForZone(params.ctx, &n.zoneSpecifier)
func getShowZoneConfigRow(
ctx context.Context, p *planner, zoneSpecifier tree.ZoneSpecifier,
) (tree.Datums, error) {
tblDesc, err := p.resolveTableForZone(ctx, &zoneSpecifier)
if err != nil {
return err
return nil, err
}

targetID, err := resolveZone(
params.ctx, params.p.txn, &n.zoneSpecifier)
targetID, err := resolveZone(ctx, p.txn, &zoneSpecifier)
if err != nil {
return err
return nil, err
}

index, partition, err := resolveSubzone(
params.ctx, params.p.txn, &n.zoneSpecifier, targetID, tblDesc)
index, partition, err := resolveSubzone(ctx, p.txn, &zoneSpecifier, targetID, tblDesc)
if err != nil {
return err
return nil, err
}

zoneID, zone, subzone, err := GetZoneConfigInTxn(params.ctx, params.p.txn,
zoneID, zone, subzone, err := GetZoneConfigInTxn(ctx, p.txn,
uint32(targetID), index, partition, false /* getInheritedDefault */)
if err == errNoZoneConfigApplies {
// TODO(benesch): This shouldn't be the caller's responsibility;
Expand All @@ -115,22 +119,26 @@ func (n *showZoneConfigNode) startExec(params runParams) error {
zone = &defZone
zoneID = keys.RootNamespaceID
} else if err != nil {
return err
return nil, err
} else if subzone != nil {
zone = &subzone.Config
}

// Determine the CLI specifier for the zone config that actually applies
// without performing another KV lookup.
zs := ascendZoneSpecifier(n.zoneSpecifier, uint32(targetID), zoneID, subzone)
zs := ascendZoneSpecifier(zoneSpecifier, uint32(targetID), zoneID, subzone)

// Ensure subzone configs don't infect the output of config_bytes.
zone.Subzones = nil
zone.SubzoneSpans = nil

n.run.values = make(tree.Datums, len(showZoneConfigNodeColumns))
return generateZoneConfigIntrospectionValues(
n.run.values, tree.NewDInt(tree.DInt(zoneID)), &zs, zone)
vals := make(tree.Datums, len(showZoneConfigColumns))
if err := generateZoneConfigIntrospectionValues(
vals, tree.NewDInt(tree.DInt(zoneID)), &zs, zone,
); err != nil {
return nil, err
}
return vals, nil
}

// generateZoneConfigIntrospectionValues creates a result row
Expand Down Expand Up @@ -243,20 +251,6 @@ func yamlMarshalFlow(v interface{}) (string, error) {
return buf.String(), nil
}

func (n *showZoneConfigNode) Next(runParams) (bool, error) {
if !n.run.done {
n.run.done = true
return true, nil
}
return false, nil
}

func (n *showZoneConfigNode) Values() tree.Datums {
return n.run.values
}

func (*showZoneConfigNode) Close(context.Context) {}

// ascendZoneSpecifier logically ascends the zone hierarchy for the zone
// specified by (zs, resolvedID) until the zone matching actualID is found, and
// returns that zone's specifier. Results are undefined if actualID is not in
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,6 @@ var planNodeNames = map[reflect.Type]string{
reflect.TypeOf(&showFingerprintsNode{}): "showFingerprints",
reflect.TypeOf(&showTraceNode{}): "show trace for",
reflect.TypeOf(&showTraceReplicaNode{}): "replica trace",
reflect.TypeOf(&showZoneConfigNode{}): "show zone configuration",
reflect.TypeOf(&sortNode{}): "sort",
reflect.TypeOf(&splitNode{}): "split",
reflect.TypeOf(&spoolNode{}): "spool",
Expand Down