Skip to content

Add create index and drop index support #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2020

Conversation

miuy56dc
Copy link
Contributor

@miuy56dc miuy56dc commented May 15, 2020

This PR adds support for:

CREATE [ UNIQUE ] INDEX [ IF NOT EXISTS ]
    <index_name>
    ON <table_name>
    ( col_name [, ...] )

DROP INDEX <index_name>

@miuy56dc miuy56dc mentioned this pull request May 18, 2020
Copy link
Contributor

@nickolay nickolay left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, and sorry it took me so long to get back to you!

I see from the tests this supports CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name) and DROP INDEX idx_name. This agrees with Postgres' syntax and has an intersection with MSSQL's syntax, which is good.

However the code in parse_index_column() is more complex than what's required to support the above, and I don't understand what specifically it tries to implement. A simple self.parse_comma_separated(Parser::parse_identifier)? should be able to parse the above example. self.parse_comma_separated(Parser::parse_order_by_expr) seems like it would support all but the most exotic syntax.

Did you intend to support trailing comma? (let's make it explicit if so, and I would prefer introducing a helper akin to parse_comma_separated instead of duplicating code from parse_columns)

Why do you parse an individual item of an index definition as a sequence of identifiers, delimited by whitespace only, and store it as an ObjectName (which represents a dot-delimited name like foo.bar.baz)? This seems wrong and wouldn't round-trip when serialized back to string...

A few minor quibbles below, which I would've fixed myself if it weren't for the above questions.

@miuy56dc
Copy link
Contributor Author

@nickolay Thanks for the comment. And yes I should use self.parse_comma_separated(Parser::parse_identifier)? to parse column names.
Actually I don't intend to support trailing comma, just because I find parse_columns support it, so I do the same thing.

@miuy56dc miuy56dc requested a review from nickolay May 26, 2020 15:54
@nickolay
Copy link
Contributor

Alright, supporting CREATE INDEX idx_name ON test (col_name[, ...]) sounds great to me!

In this case, there's no reason to have parse_index_column as a separate method (it's rather short now!), this would lead to changing let object_names into let columns, as expected by Statement::CreateIndex. If you can make this last change and squash the changes into a single commit rebased on top of the current master, I'll merge it now. Or I can take it from here, if you prefer.

@miuy56dc miuy56dc force-pushed the add_index_support branch from f0052fc to 5aacc5e Compare May 27, 2020 01:28
@miuy56dc
Copy link
Contributor Author

Hi @nickolay, thanks for the advice, I have moved parse_index_column into parse_create_index and squash the changes into a single commit rebased on top of the current master.

@nickolay
Copy link
Contributor

Excellent, thanks so much for bearing with me and for taking it to the finish line!

I just realized this can now use parse_parenthesized_column_list, but as I wanted to credit you in the CHANGELOG anyway, I've gone ahead and made the last minute change myself.

@nickolay nickolay merged commit 789fcc8 into apache:master May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants