From cdb6b6d6502c6fd75ce97724e38a37d4f137d4da Mon Sep 17 00:00:00 2001 From: Rohan Yadav Date: Mon, 3 Jun 2019 12:50:15 -0400 Subject: [PATCH] addressing raphaels comments --- pkg/sql/delegate/delegate.go | 4 ++-- pkg/sql/delegate/show_table.go | 4 ++-- .../logictest/testdata/logic_test/show_source | 17 ++++++++++++++++- pkg/sql/parser/parse_test.go | 1 + pkg/sql/parser/sql.y | 6 +++--- pkg/sql/sem/tree/show.go | 10 +++++----- pkg/sql/sem/tree/stmt.go | 8 ++++---- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/pkg/sql/delegate/delegate.go b/pkg/sql/delegate/delegate.go index ac724eabd267..da346eaece48 100644 --- a/pkg/sql/delegate/delegate.go +++ b/pkg/sql/delegate/delegate.go @@ -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) diff --git a/pkg/sql/delegate/show_table.go b/pkg/sql/delegate/show_table.go index 3a93ad982930..30ce086e1baf 100644 --- a/pkg/sql/delegate/show_table.go +++ b/pkg/sql/delegate/show_table.go @@ -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, @@ -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) { diff --git a/pkg/sql/logictest/testdata/logic_test/show_source b/pkg/sql/logictest/testdata/logic_test/show_source index 3f29c65f92c3..33ff9f78841f 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_source +++ b/pkg/sql/logictest/testdata/logic_test/show_source @@ -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 \ No newline at end of file +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 diff --git a/pkg/sql/parser/parse_test.go b/pkg/sql/parser/parse_test.go index ebe22ef9bcaa..96df7792effb 100644 --- a/pkg/sql/parser/parse_test.go +++ b/pkg/sql/parser/parse_test.go @@ -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`}, diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 2da34e2c57da..e713782accd1 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -3357,7 +3357,7 @@ 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 { @@ -3365,7 +3365,7 @@ show_indexes_stmt: } | 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 @@ -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 diff --git a/pkg/sql/sem/tree/show.go b/pkg/sql/sem/tree/show.go index 15622d229bd0..0dd40dade12f 100644 --- a/pkg/sql/sem/tree/show.go +++ b/pkg/sql/sem/tree/show.go @@ -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 diff --git a/pkg/sql/sem/tree/stmt.go b/pkg/sql/sem/tree/stmt.go index 3376ad6a8e40..7f904a84461b 100644 --- a/pkg/sql/sem/tree/stmt.go +++ b/pkg/sql/sem/tree/stmt.go @@ -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 } @@ -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) }