Skip to content
This repository was archived by the owner on Dec 25, 2019. It is now read-only.

WIP: Support CREATE/DROP INDEX#14

Merged
wangandi merged 1 commit intoMaterializeInc:masterfrom
wangandi:indexing
Oct 21, 2019
Merged

WIP: Support CREATE/DROP INDEX#14
wangandi merged 1 commit intoMaterializeInc:masterfrom
wangandi:indexing

Conversation

@wangandi
Copy link
Copy Markdown
Contributor

@wangandi wangandi commented Oct 17, 2019

Part of the work involved in MaterializeInc/materialize#218

Basic support for the CREATE INDEX and DROP INDEX syntax.

Note that index creation and management syntax is not part of the SQL standard.

Syntax for CREATE INDEX

CREATE INDEX index_name ON table_name(key_part, …)
key_part: {col_name | (expr)}

This is a subset of the overlap between PostgreSQL and MySQL. Links to the full syntax for both DBs are below in case we think that we may want to support some additional features or allow sqlparser to be able to support future implementations of the certain features.
https://www.postgresql.org/docs/12/sql-createindex.html
https://dev.mysql.com/doc/refman/8.0/en/create-index.html

In PostgreSQL, all expressions other than column names (without qualifiers) and functions must have parentheses around them, and I have followed that parsing rule in the PR. I'm not sure if MySQL exempts functions from the parentheses requirement.

Syntax for DROP INDEX

DROP INDEX [IF EXISTS] index_name [, …] (CASCADE | RESTRICT)

This is a subset of what PostgreSQL supports and a superset of what MySQL supports. This syntax is motivated by it being the default state for DROP and it being more of a hassle to not support the options.

Question: Do we want to support SHOW INDEX/INDEXES/KEYS?

Currently in this branch SHOW INDEX is not supported.

SHOW INDEX is supported in MySQL (and CockroachDB), but it is not supported in PostgreSQL, Oracle, or Microsoft SQL Server.
The MySQL syntax is here:
https://dev.mysql.com/doc/refman/8.0/en/show-index.html

Since indexes belong to tables, it seems like supporting SHOW INDEX would involve reworking the Statement::ShowObjects or ObjectType enums.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Oct 17, 2019

CLA assistant check
All committers have signed the CLA.

@wangandi wangandi requested a review from benesch October 17, 2019 21:34
Comment thread src/ast/mod.rs
on_name: ObjectName,
/// expressions that form part of the index key
key_parts: Vec<Expr>,
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: comments should have a space after the slash and start with an upper case letter. (I try not to care too much about formatting in general, but it matters here because this will be upstreamed, and the less things that can go wrong in the review when we upstream, the better.)

Comment thread src/ast/mod.rs
Source => "SOURCES",
Sink => "SINKS",
Index => unreachable!(),
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just flagging this in case you’ve forgotten about it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not be reachable until SHOW INDEXES is supported. Should I just change it to "INDEXES" preemptively?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, duh, of course. Apologies; I didn't look hard enough at where this code was. Leaving it like this is fine!

Comment thread src/parser.rs Outdated
}) {
Err(ParserError::ParserError(format!(
"Expressions must be enclosed in parentheses."
)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually drop this! The fact that you have to surround complicated expressions with parentheses is a limitation of the PostgreSQL parser. Since we don’t have that limitation, and since it’s less code to not introduce that limitation, the rule of thumb is to not have the limitation.

@benesch
Copy link
Copy Markdown
Contributor

benesch commented Oct 18, 2019

And yeah, we should support SHOW INDEX, but no need to do so in this PR.

Copy link
Copy Markdown
Contributor

@benesch benesch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing tests, as always!

@wangandi wangandi merged commit 3a077b0 into MaterializeInc:master Oct 21, 2019
@wangandi wangandi deleted the indexing branch October 21, 2019 14:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants