Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
29464: sql: fix the syntax roundtrip for CREATE INDEX r=knz a=knz

Fixes cockroachdb#28846

Co-authored-by: Raphael 'kena' Poss <[email protected]>
  • Loading branch information
craig[bot] and knz committed Sep 2, 2018
2 parents d0971e5 + 0112afe commit 14b53bc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
4 changes: 4 additions & 0 deletions docs/generated/sql/bnf/create_index_interleaved_stmt.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ create_index_stmt ::=
| 'CREATE' 'UNIQUE' 'INDEX' '...' 'INTERLEAVE' 'IN' 'PARENT' parent_table '(' interleave_prefix ')'
| 'CREATE' 'INDEX' '...' 'STORING' '(' stored_columns ')' 'INTERLEAVE' 'IN' 'PARENT' parent_table '(' interleave_prefix ')'
| 'CREATE' 'INDEX' '...' 'INTERLEAVE' 'IN' 'PARENT' parent_table '(' interleave_prefix ')'
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' '...' 'STORING' '(' stored_columns ')' 'INTERLEAVE' 'IN' 'PARENT' parent_table '(' interleave_prefix ')'
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' '...' 'INTERLEAVE' 'IN' 'PARENT' parent_table '(' interleave_prefix ')'
| 'CREATE' 'INVERTED' 'INDEX' '...' 'STORING' '(' stored_columns ')' 'INTERLEAVE' 'IN' 'PARENT' parent_table '(' interleave_prefix ')'
| 'CREATE' 'INVERTED' 'INDEX' '...' 'INTERLEAVE' 'IN' 'PARENT' parent_table '(' interleave_prefix ')'
48 changes: 36 additions & 12 deletions docs/generated/sql/bnf/create_index_stmt.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,39 @@ create_index_stmt ::=
| 'CREATE' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')'
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'UNIQUE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'ASC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name 'DESC' ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'COVERING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' 'STORING' '(' name_list ')' opt_interleave opt_partition_by
| 'CREATE' 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' column_name ( ( ',' ( column_name ( 'ASC' | 'DESC' | ) ) ) )* ')' opt_interleave opt_partition_by
4 changes: 2 additions & 2 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,8 @@ create_database_stmt ::=
create_index_stmt ::=
'CREATE' opt_unique 'INDEX' opt_index_name 'ON' table_name opt_using_gin_btree '(' index_params ')' opt_storing opt_interleave opt_partition_by
| 'CREATE' opt_unique 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name opt_using_gin_btree '(' index_params ')' opt_storing opt_interleave opt_partition_by
| 'CREATE' opt_unique 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' index_params ')'
| 'CREATE' opt_unique 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' index_params ')'
| 'CREATE' opt_unique 'INVERTED' 'INDEX' opt_index_name 'ON' table_name '(' index_params ')' opt_storing opt_interleave opt_partition_by
| 'CREATE' opt_unique 'INVERTED' 'INDEX' 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' index_params ')' opt_storing opt_interleave opt_partition_by

create_table_stmt ::=
'CREATE' 'TABLE' table_name '(' opt_table_elem_list ')' opt_interleave opt_partition_by
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/inverted_index
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CREATE INDEX c on t1 USING GIN (id2)
statement error pq: inverted indexes don't support stored columns
CREATE INDEX c on t1 USING GIN (id2) STORING (id1,id3);

statement error pq: syntax error at or near "storing"
statement error pq: inverted indexes don't support stored columns
CREATE INVERTED INDEX c on t1 (id2) STORING (id1,id3);

statement error pq: inverted indexes can't be unique
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func TestParse(t *testing.T) {
{`CREATE UNIQUE INDEX a ON b.c (d)`},
{`CREATE INVERTED INDEX a ON b (c)`},
{`CREATE INVERTED INDEX a ON b.c (d)`},
{`CREATE INVERTED INDEX a ON b (c) STORING (d)`},
{`CREATE INVERTED INDEX a ON b (c) INTERLEAVE IN PARENT d (e)`},

{`CREATE TABLE a ()`},
{`CREATE TABLE a (b INT)`},
Expand Down
10 changes: 8 additions & 2 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -4272,17 +4272,20 @@ create_index_stmt:
Inverted: $10.bool(),
}
}
| CREATE opt_unique INVERTED INDEX opt_index_name ON table_name '(' index_params ')'
| CREATE opt_unique INVERTED INDEX opt_index_name ON table_name '(' index_params ')' opt_storing opt_interleave opt_partition_by
{
$$.val = &tree.CreateIndex{
Name: tree.Name($5),
Table: $7.normalizableTableNameFromUnresolvedName(),
Unique: $2.bool(),
Inverted: true,
Columns: $9.idxElems(),
Storing: $11.nameList(),
Interleave: $12.interleave(),
PartitionBy: $13.partitionBy(),
}
}
| CREATE opt_unique INVERTED INDEX IF NOT EXISTS index_name ON table_name '(' index_params ')'
| CREATE opt_unique INVERTED INDEX IF NOT EXISTS index_name ON table_name '(' index_params ')' opt_storing opt_interleave opt_partition_by
{
$$.val = &tree.CreateIndex{
Name: tree.Name($8),
Expand All @@ -4291,6 +4294,9 @@ create_index_stmt:
Inverted: true,
IfNotExists: true,
Columns: $12.idxElems(),
Storing: $14.nameList(),
Interleave: $15.interleave(),
PartitionBy: $16.partitionBy(),
}
}
| CREATE opt_unique INDEX error // SHOW HELP: CREATE INDEX
Expand Down

0 comments on commit 14b53bc

Please sign in to comment.