Skip to content

Commit

Permalink
sql: rework SHOW REGIONS to SHOW REGIONS FROM CLUSTER
Browse files Browse the repository at this point in the history
Release note (sql change): SHOW REGIONS functionality is now deferred to
SHOW REGIONS FROM CLUSTER.
  • Loading branch information
otan committed Nov 13, 2020
1 parent 64592c3 commit 8e58c1e
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ show_range_for_row_stmt ::=
| 'SHOW' 'RANGE' 'FROM' 'INDEX' table_index_name 'FOR' 'ROW' '(' expr_list ')'

show_regions_stmt ::=
'SHOW' 'REGIONS'
'SHOW' 'REGIONS' 'FROM' 'CLUSTER'
| 'SHOW' 'REGIONS' 'FROM' 'DATABASE' database_name

show_roles_stmt ::=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/interactive_tests/test_demo_node_cmds.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ eexpect "internal server error: tier must be in the form \"key=value\" not \"bla
send "\\demo add region=ca-central,zone=a\r"
eexpect "node 6 has been added with locality \"region=ca-central,zone=a\""

send "show regions;\r"
send "show regions from cluster;\r"
eexpect "ca-central | \{a\}"
eexpect "us-east1 | \{b,c,d\}"
eexpect "us-west1 | \{a,b\}"
Expand Down
12 changes: 11 additions & 1 deletion pkg/sql/delegate/show_regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ package delegate
import (
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
)

// delegateShowRanges implements the SHOW REGIONS statement.
func (d *delegator) delegateShowRegions(n *tree.ShowRegions) (tree.Statement, error) {
sqltelemetry.IncrementShowCounter(sqltelemetry.Regions)

if n.Database != "" {
sqltelemetry.IncrementShowCounter(sqltelemetry.RegionsFromDatabase)
return nil, unimplemented.New(
"show regions from database",
"SHOW REGIONS FROM DATABASE not yet implemented",
)
}
sqltelemetry.IncrementShowCounter(sqltelemetry.RegionsFromCluster)

// TODO (storm): Change this so that it doesn't use hard-coded strings and is
// more flexible for custom named sub-regions.
query := `
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/multiregion
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LogicTest: multiregion-9node-3region-3azs

query TT colnames
SHOW REGIONS
SHOW REGIONS FROM CLUSTER
----
region zones
test1 {test1-az1,test1-az2,test1-az3}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func TestParse(t *testing.T) {
{`SHOW RANGES FROM INDEX t@i`},
{`SHOW RANGES FROM INDEX d.i`},
{`SHOW RANGES FROM INDEX i`},
{`SHOW REGIONS`},
{`SHOW REGIONS FROM CLUSTER`},
{`SHOW REGIONS FROM DATABASE d`},
{`SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE d.t`},
{`SHOW ZONE CONFIGURATIONS`},
Expand Down
7 changes: 4 additions & 3 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -5124,10 +5124,10 @@ show_ranges_stmt:
// %Help: SHOW REGIONS - shows regions
// %Category: DDL
// %Text:
// SHOW REGIONS
// SHOW REGIONS FOR DATABASE <database>
// SHOW REGIONS FROM CLUSTER
// SHOW REGIONS FROM DATABASE <database>
show_regions_stmt:
SHOW REGIONS
SHOW REGIONS FROM CLUSTER
{
$$.val = &tree.ShowRegions{}
}
Expand All @@ -5137,6 +5137,7 @@ show_regions_stmt:
Database: tree.Name($5),
}
}
| SHOW REGIONS error // SHOW HELP: SHOW REGIONS

show_locality_stmt:
SHOW LOCALITY
Expand Down
6 changes: 4 additions & 2 deletions pkg/sql/sem/tree/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ type ShowRegions struct {

// Format implements the NodeFormatter interface.
func (node *ShowRegions) Format(ctx *FmtCtx) {
ctx.WriteString("SHOW REGIONS")
ctx.WriteString("SHOW REGIONS ")
if node.Database != "" {
ctx.WriteString(" FROM DATABASE ")
ctx.WriteString("FROM DATABASE ")
node.Database.Format(ctx)
} else {
ctx.WriteString("FROM CLUSTER")
}
}

Expand Down
31 changes: 17 additions & 14 deletions pkg/sql/sqltelemetry/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ const (
_ ShowTelemetryType = iota
// Ranges represents the SHOW RANGES command.
Ranges
// Regions represents the SHOW REGIONS command.
Regions
// RegionsFromCluster represents the SHOW REGIONS FROM CLUSTER command.
RegionsFromCluster
// RegionsFromDatabase represents the SHOW REGIONS FROM DATABASE command.
RegionsFromDatabase
// Partitions represents the SHOW PARTITIONS command.
Partitions
// Locality represents the SHOW LOCALITY command.
Expand All @@ -49,18 +51,19 @@ const (
)

var showTelemetryNameMap = map[ShowTelemetryType]string{
Ranges: "ranges",
Partitions: "partitions",
Locality: "locality",
Create: "create",
RangeForRow: "rangeforrow",
Regions: "regions",
Queries: "queries",
Indexes: "indexes",
Constraints: "constraints",
Jobs: "jobs",
Roles: "roles",
Schedules: "schedules",
Ranges: "ranges",
Partitions: "partitions",
Locality: "locality",
Create: "create",
RangeForRow: "rangeforrow",
RegionsFromCluster: "regions_from_cluster",
RegionsFromDatabase: "regions_from_database",
Queries: "queries",
Indexes: "indexes",
Constraints: "constraints",
Jobs: "jobs",
Roles: "roles",
Schedules: "schedules",
}

func (s ShowTelemetryType) String() string {
Expand Down

0 comments on commit 8e58c1e

Please sign in to comment.