Skip to content

Commit

Permalink
sql: alias SHOW STATEMENTS to SHOW QUERIES
Browse files Browse the repository at this point in the history
Fixes cockroachdb#56240

This commit makes SHOW STATEMENTS a (preferred) alias of SHOW QUERIES.

Release note: None
  • Loading branch information
ivern committed Dec 18, 2020
1 parent fa312ba commit 5c6a19f
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 39 deletions.
5 changes: 0 additions & 5 deletions docs/generated/sql/bnf/show_queries.bnf

This file was deleted.

9 changes: 9 additions & 0 deletions docs/generated/sql/bnf/show_statements.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
show_statements_stmt ::=
'SHOW' 'CLUSTER' 'STATEMENTS'
| 'SHOW' 'CLUSTER' 'QUERIES'
| 'SHOW' 'LOCAL' 'STATEMENTS'
| 'SHOW' 'LOCAL' 'QUERIES'
| 'SHOW' 'ALL' 'CLUSTER' 'STATEMENTS'
| 'SHOW' 'ALL' 'CLUSTER' 'QUERIES'
| 'SHOW' 'ALL' 'LOCAL' 'STATEMENTS'
| 'SHOW' 'ALL' 'LOCAL' 'QUERIES'
2 changes: 1 addition & 1 deletion docs/generated/sql/bnf/show_var.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ show_stmt ::=
| show_jobs_stmt
| show_locality_stmt
| show_schedules_stmt
| show_queries_stmt
| show_statements_stmt
| show_ranges_stmt
| show_range_for_row_stmt
| show_regions_stmt
Expand Down
13 changes: 9 additions & 4 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ show_stmt ::=
| show_jobs_stmt
| show_locality_stmt
| show_schedules_stmt
| show_queries_stmt
| show_statements_stmt
| show_ranges_stmt
| show_range_for_row_stmt
| show_regions_stmt
Expand Down Expand Up @@ -654,9 +654,9 @@ show_schedules_stmt ::=
| 'SHOW' schedule_state 'SCHEDULES' opt_schedule_executor_type
| 'SHOW' 'SCHEDULE' a_expr

show_queries_stmt ::=
'SHOW' opt_cluster 'QUERIES'
| 'SHOW' 'ALL' opt_cluster 'QUERIES'
show_statements_stmt ::=
'SHOW' opt_cluster statements_or_queries
| 'SHOW' 'ALL' opt_cluster statements_or_queries

show_ranges_stmt ::=
'SHOW' 'RANGES' 'FROM' 'TABLE' table_name
Expand Down Expand Up @@ -1057,6 +1057,7 @@ unreserved_keyword ::=
| 'SPLIT'
| 'SQL'
| 'START'
| 'STATEMENTS'
| 'STATISTICS'
| 'STDIN'
| 'STORAGE'
Expand Down Expand Up @@ -1517,6 +1518,10 @@ opt_cluster ::=
'CLUSTER'
| 'LOCAL'

statements_or_queries ::=
'STATEMENTS'
| 'QUERIES'

opt_compact ::=
'COMPACT'
|
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/docgen/diagrams.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,9 +1298,9 @@ var specs = []stmtSpec{
name: "show_partitions_stmt",
},
{
name: "show_queries",
stmt: "show_queries_stmt",
inline: []string{"opt_cluster"},
name: "show_statements",
stmt: "show_statements_stmt",
inline: []string{"opt_cluster", "statements_or_queries"},
},
{
name: "show_roles_stmt",
Expand Down
7 changes: 5 additions & 2 deletions pkg/sql/parser/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,11 @@ func TestContextualHelp(t *testing.T) {

{`SHOW HISTOGRAM ??`, `SHOW HISTOGRAM`},

{`SHOW QUERIES ??`, `SHOW QUERIES`},
{`SHOW LOCAL QUERIES ??`, `SHOW QUERIES`},
{`SHOW QUERIES ??`, `SHOW STATEMENTS`},
{`SHOW LOCAL QUERIES ??`, `SHOW STATEMENTS`},

{`SHOW STATEMENTS ??`, `SHOW STATEMENTS`},
{`SHOW LOCAL STATEMENTS ??`, `SHOW STATEMENTS`},

{`SHOW TRACE ??`, `SHOW TRACE`},
{`SHOW TRACE FOR SESSION ??`, `SHOW TRACE`},
Expand Down
22 changes: 12 additions & 10 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,14 +615,14 @@ func TestParse(t *testing.T) {
{`EXPLAIN SHOW JOBS`},
{`SHOW AUTOMATIC JOBS`},
{`EXPLAIN SHOW AUTOMATIC JOBS`},
{`SHOW CLUSTER QUERIES`},
{`EXPLAIN SHOW CLUSTER QUERIES`},
{`SHOW ALL CLUSTER QUERIES`},
{`EXPLAIN SHOW ALL CLUSTER QUERIES`},
{`SHOW LOCAL QUERIES`},
{`EXPLAIN SHOW LOCAL QUERIES`},
{`SHOW ALL LOCAL QUERIES`},
{`EXPLAIN SHOW ALL LOCAL QUERIES`},
{`SHOW CLUSTER STATEMENTS`},
{`EXPLAIN SHOW CLUSTER STATEMENTS`},
{`SHOW ALL CLUSTER STATEMENTS`},
{`EXPLAIN SHOW ALL CLUSTER STATEMENTS`},
{`SHOW LOCAL STATEMENTS`},
{`EXPLAIN SHOW LOCAL STATEMENTS`},
{`SHOW ALL LOCAL STATEMENTS`},
{`EXPLAIN SHOW ALL LOCAL STATEMENTS`},
{`SHOW CLUSTER SESSIONS`},
{`EXPLAIN SHOW CLUSTER SESSIONS`},
{`SHOW ALL CLUSTER SESSIONS`},
Expand Down Expand Up @@ -2340,8 +2340,10 @@ $function$`,
{`SHOW ALL SESSIONS`, `SHOW ALL CLUSTER SESSIONS`},
{`SHOW TRANSACTIONS`, `SHOW CLUSTER TRANSACTIONS`},
{`SHOW ALL TRANSACTIONS`, `SHOW ALL CLUSTER TRANSACTIONS`},
{`SHOW QUERIES`, `SHOW CLUSTER QUERIES`},
{`SHOW ALL QUERIES`, `SHOW ALL CLUSTER QUERIES`},
{`SHOW QUERIES`, `SHOW CLUSTER STATEMENTS`},
{`SHOW STATEMENTS`, `SHOW CLUSTER STATEMENTS`},
{`SHOW ALL QUERIES`, `SHOW ALL CLUSTER STATEMENTS`},
{`SHOW ALL STATEMENTS`, `SHOW ALL CLUSTER STATEMENTS`},

{`USE foo`, `SET database = foo`},

Expand Down
29 changes: 19 additions & 10 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func (u *sqlSymUnion) objectNamePrefixList() tree.ObjectNamePrefixList {
%token <str> SKIP_MISSING_SEQUENCES SKIP_MISSING_SEQUENCE_OWNERS SKIP_MISSING_VIEWS SMALLINT SMALLSERIAL SNAPSHOT SOME SPLIT SQL

%token <str> START STATISTICS STATUS STDIN STRICT STRING STORAGE STORE STORED STORING SUBSTRING
%token <str> SURVIVE SURVIVAL SYMMETRIC SYNTAX SYSTEM SQRT SUBSCRIPTION
%token <str> SURVIVE SURVIVAL SYMMETRIC SYNTAX SYSTEM SQRT SUBSCRIPTION STATEMENTS

%token <str> TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TENANT TESTING_RELOCATE EXPERIMENTAL_RELOCATE TEXT THEN
%token <str> TIES TIME TIMETZ TIMESTAMP TIMESTAMPTZ TO THROTTLING TRAILING TRACE
Expand Down Expand Up @@ -886,7 +886,7 @@ func (u *sqlSymUnion) objectNamePrefixList() tree.ObjectNamePrefixList {
%type <tree.Statement> show_indexes_stmt
%type <tree.Statement> show_partitions_stmt
%type <tree.Statement> show_jobs_stmt
%type <tree.Statement> show_queries_stmt
%type <tree.Statement> show_statements_stmt
%type <tree.Statement> show_ranges_stmt
%type <tree.Statement> show_range_for_row_stmt
%type <tree.Statement> show_locality_stmt
Expand All @@ -910,6 +910,8 @@ func (u *sqlSymUnion) objectNamePrefixList() tree.ObjectNamePrefixList {
%type <tree.Statement> show_zone_stmt
%type <tree.Statement> show_schedules_stmt

%type <str> statements_or_queries

%type <str> session_var
%type <*string> comment_text

Expand Down Expand Up @@ -4368,7 +4370,7 @@ show_stmt:
| show_jobs_stmt // EXTEND WITH HELP: SHOW JOBS
| show_locality_stmt
| show_schedules_stmt // EXTEND WITH HELP: SHOW SCHEDULES
| show_queries_stmt // EXTEND WITH HELP: SHOW QUERIES
| show_statements_stmt // EXTEND WITH HELP: SHOW STATEMENTS
| show_ranges_stmt // EXTEND WITH HELP: SHOW RANGES
| show_range_for_row_stmt
| show_regions_stmt // EXTEND WITH HELP: SHOW REGIONS
Expand Down Expand Up @@ -4734,21 +4736,21 @@ show_constraints_stmt:
}
| SHOW CONSTRAINTS error // SHOW HELP: SHOW CONSTRAINTS

// %Help: SHOW QUERIES - list running queries
// %Help: SHOW STATEMENTS - list running statements
// %Category: Misc
// %Text: SHOW [ALL] [CLUSTER | LOCAL] QUERIES
// %Text: SHOW [ALL] [CLUSTER | LOCAL] STATEMENTS
// %SeeAlso: CANCEL QUERIES
show_queries_stmt:
SHOW opt_cluster QUERIES
show_statements_stmt:
SHOW opt_cluster statements_or_queries
{
$$.val = &tree.ShowQueries{All: false, Cluster: $2.bool()}
}
| SHOW opt_cluster QUERIES error // SHOW HELP: SHOW QUERIES
| SHOW ALL opt_cluster QUERIES
| SHOW opt_cluster statements_or_queries error // SHOW HELP: SHOW STATEMENTS
| SHOW ALL opt_cluster statements_or_queries
{
$$.val = &tree.ShowQueries{All: true, Cluster: $3.bool()}
}
| SHOW ALL opt_cluster QUERIES error // SHOW HELP: SHOW QUERIES
| SHOW ALL opt_cluster statements_or_queries error // SHOW HELP: SHOW STATEMENTS

opt_cluster:
/* EMPTY */
Expand All @@ -4758,6 +4760,12 @@ opt_cluster:
| LOCAL
{ $$.val = false }

// SHOW QUERIES is now an alias for SHOW STATEMENTS
// https://github.com/cockroachdb/cockroach/issues/56240
statements_or_queries:
STATEMENTS
| QUERIES

// %Help: SHOW JOBS - list background jobs
// %Category: Misc
// %Text:
Expand Down Expand Up @@ -12267,6 +12275,7 @@ unreserved_keyword:
| SPLIT
| SQL
| START
| STATEMENTS
| STATISTICS
| STDIN
| STORAGE
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/sem/tree/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (node *ShowDatabaseIndexes) Format(ctx *FmtCtx) {
}
}

// ShowQueries represents a SHOW QUERIES statement.
// ShowQueries represents a SHOW STATEMENTS statement.
type ShowQueries struct {
All bool
Cluster bool
Expand All @@ -240,9 +240,9 @@ func (node *ShowQueries) Format(ctx *FmtCtx) {
ctx.WriteString("ALL ")
}
if node.Cluster {
ctx.WriteString("CLUSTER QUERIES")
ctx.WriteString("CLUSTER STATEMENTS")
} else {
ctx.WriteString("LOCAL QUERIES")
ctx.WriteString("LOCAL STATEMENTS")
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sem/tree/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ func (*ShowPartitions) StatementTag() string { return "SHOW PARTITIONS" }
func (*ShowQueries) StatementType() StatementType { return Rows }

// StatementTag returns a short string identifying the type of statement.
func (*ShowQueries) StatementTag() string { return "SHOW QUERIES" }
func (*ShowQueries) StatementTag() string { return "SHOW STATEMENTS" }

// StatementType implements the Statement interface.
func (*ShowJobs) StatementType() StatementType { return Rows }
Expand Down

0 comments on commit 5c6a19f

Please sign in to comment.