Skip to content

Commit

Permalink
addressing raphaels comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rohany committed Jun 3, 2019
1 parent ba3800f commit cdb6b6d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/delegate/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func TryDelegate(
case *tree.ShowCreate:
return d.delegateShowCreate(t)

case *tree.ShowDbIndexes:
return d.delegateShowDbIndexes(t)
case *tree.ShowDatabaseIndexes:
return d.delegateShowDatabaseIndexes(t)

case *tree.ShowIndexes:
return d.delegateShowIndexes(t)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/delegate/show_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (d *delegator) delegateShowCreate(n *tree.ShowCreate) (tree.Statement, erro
return d.showTableDetails(n.Name, showCreateQuery)
}

func (d *delegator) delegateShowDbIndexes(n *tree.ShowDbIndexes) (tree.Statement, error) {
func (d *delegator) delegateShowDatabaseIndexes(n *tree.ShowDatabaseIndexes) (tree.Statement, error) {
const getAllIndexesQuery = `
SELECT table_name,
index_name,
Expand All @@ -45,7 +45,7 @@ func (d *delegator) delegateShowDbIndexes(n *tree.ShowDbIndexes) (tree.Statement
storing::BOOL,
implicit::BOOL
FROM %s.information_schema.statistics`
return parse(fmt.Sprintf(getAllIndexesQuery, n.Database))
return parse(fmt.Sprintf(getAllIndexesQuery, n.Database.String()))
}

func (d *delegator) delegateShowIndexes(n *tree.ShowIndexes) (tree.Statement, error) {
Expand Down
17 changes: 16 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,19 @@ query TTBITTBB
SHOW INDEXES FROM DATABASE showdbindexestest;
----
table1 primary false 1 key1 ASC false false
table2 primary false 1 key2 ASC false false
table2 primary false 1 key2 ASC false false

statement ok
CREATE DATABASE "$peci@l";

statement ok
CREATE TABLE "$peci@l".table1 (key1 INT PRIMARY KEY);

statement ok
CREATE TABLE "$peci@l".table2 (key2 INT PRIMARY KEY);

query TTBITTBB
SHOW INDEXES FROM DATABASE "$peci@l";
----
table1 primary false 1 key1 ASC false false
table2 primary false 1 key2 ASC false false
1 change: 1 addition & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ func TestParse(t *testing.T) {
{`EXPLAIN SHOW INDEXES FROM a`},
{`SHOW INDEXES FROM a.b.c`},
{`SHOW INDEXES FROM DATABASE a`},
{`SHOW INDEXES FROM DATABASE "$speci@ltest"`},
{`SHOW CONSTRAINTS FROM a`},
{`SHOW CONSTRAINTS FROM a.b.c`},
{`EXPLAIN SHOW CONSTRAINTS FROM a.b.c`},
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -3357,15 +3357,15 @@ show_indexes_stmt:
| SHOW INDEX error // SHOW HELP: SHOW INDEXES
| SHOW INDEX FROM DATABASE database_name
{
$$.val = &tree.ShowDbIndexes{Database: $5}
$$.val = &tree.ShowDatabaseIndexes{Database: tree.Name($5)}
}
| SHOW INDEXES FROM table_name
{
$$.val = &tree.ShowIndexes{Table: $4.unresolvedObjectName()}
}
| SHOW INDEXES FROM DATABASE database_name
{
$$.val = &tree.ShowDbIndexes{Database: $5}
$$.val = &tree.ShowDatabaseIndexes{Database: tree.Name($5)}
}
| SHOW INDEXES error // SHOW HELP: SHOW INDEXES
| SHOW KEYS FROM table_name
Expand All @@ -3374,7 +3374,7 @@ show_indexes_stmt:
}
| SHOW KEYS FROM DATABASE database_name
{
$$.val = &tree.ShowDbIndexes{Database: $5}
$$.val = &tree.ShowDatabaseIndexes{Database: tree.Name($5)}
}
| SHOW KEYS error // SHOW HELP: SHOW INDEXES

Expand Down
10 changes: 5 additions & 5 deletions pkg/sql/sem/tree/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ func (node *ShowIndexes) Format(ctx *FmtCtx) {
ctx.FormatNode(node.Table)
}

// ShowDbIndexes represents a SHOW INDEXES FROM DATABASE statement.
type ShowDbIndexes struct {
Database string
// ShowDatabaseIndexes represents a SHOW INDEXES FROM DATABASE statement.
type ShowDatabaseIndexes struct {
Database Name
}

// Format implements the NodeFormatter interface.
func (node *ShowDbIndexes) Format(ctx *FmtCtx) {
func (node *ShowDatabaseIndexes) Format(ctx *FmtCtx) {
ctx.WriteString("SHOW INDEXES FROM DATABASE ")
ctx.WriteString(node.Database)
ctx.FormatNode(&node.Database)
}

// ShowQueries represents a SHOW QUERIES statement
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/sem/tree/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,16 +685,16 @@ func (*ShowGrants) StatementType() StatementType { return Rows }
func (*ShowGrants) StatementTag() string { return "SHOW GRANTS" }

// StatementType implements the Statement interface.
func (*ShowDbIndexes) StatementType() StatementType { return Rows }
func (*ShowDatabaseIndexes) StatementType() StatementType { return Rows }

// StatementTag returns a short string identifying the type of statement.
func (*ShowDbIndexes) StatementTag() string { return "SHOW INDEXES FROM DATABASE" }
func (*ShowDatabaseIndexes) StatementTag() string { return "SHOW INDEXES FROM DATABASE" }

// StatementType implements the Statement interface.
func (*ShowIndexes) StatementType() StatementType { return Rows }

// StatementTag returns a short string identifying the type of statement.
func (*ShowIndexes) StatementTag() string { return "SHOW INDEXES" }
func (*ShowIndexes) StatementTag() string { return "SHOW INDEXES FROM TABLE" }

// StatementType implements the Statement interface.
func (*ShowQueries) StatementType() StatementType { return Rows }
Expand Down Expand Up @@ -921,7 +921,7 @@ func (n *ShowColumns) String() string { return AsString(n) }
func (n *ShowConstraints) String() string { return AsString(n) }
func (n *ShowCreate) String() string { return AsString(n) }
func (n *ShowDatabases) String() string { return AsString(n) }
func (n *ShowDbIndexes) String() string { return AsString(n) }
func (n *ShowDatabaseIndexes) String() string { return AsString(n) }
func (n *ShowGrants) String() string { return AsString(n) }
func (n *ShowHistogram) String() string { return AsString(n) }
func (n *ShowIndexes) String() string { return AsString(n) }
Expand Down

0 comments on commit cdb6b6d

Please sign in to comment.