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
rename/exchange database/table/dictionary support IF EXISTS syntax #31081
rename/exchange database/table/dictionary support IF EXISTS syntax #31081
Conversation
Needs 'can be tested' label |
@@ -13,17 +13,23 @@ CREATE TABLE t2 ENGINE=MergeTree() ORDER BY tuple() AS SELECT rowNumberInAllBloc | |||
EXCHANGE TABLES t1 AND t3; -- { serverError 60 } | |||
EXCHANGE TABLES t4 AND t2; -- { serverError 60 } | |||
RENAME TABLE t0 TO t1; -- { serverError 57 } | |||
DROP TABLE t1; | |||
RENAME TABLE t0 TO t1; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to make new test for these queries. Or, at least, add new queries to the end of this test without modifying existing queries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, has fixed.
@@ -67,6 +68,7 @@ bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) | |||
ASTPtr from_db; | |||
ASTPtr to_db; | |||
ParserIdentifier db_name_p; | |||
bool if_exists = s_if_exists.ignore(pos, expected); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to update ASTRenameQuery::formatQueryImpl(...)
to make formatter consistent with parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
return typeid_cast<DatabaseReplicated *>(database.get())->tryEnqueueReplicatedDDL(query_ptr, getContext()); | ||
if (rename.exchange) | ||
{ | ||
ignore = rename.dictionary ? (!database_catalog.isDictionaryExist(StorageID(elem.to_database_name, elem.to_table_name)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like special check for dictionaries is not needed, because if an DDL-dictionary exists, then isTableExist(...)
returns true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
It is impossible for table/dictionary with the same StorageID
to exist in the same database
bool exchange_tables; | ||
if (rename.exchange) | ||
{ | ||
exchange_tables = true; | ||
} | ||
else if (rename.rename_if_cannot_exchange) | ||
{ | ||
exchange_tables = database_catalog.isTableExist(StorageID(elem.to_database_name, elem.to_table_name), getContext()); | ||
renamed_instead_of_exchange = !exchange_tables; | ||
} | ||
else | ||
{ | ||
exchange_tables = false; | ||
database_catalog.assertTableDoesntExist(StorageID(elem.to_database_name, elem.to_table_name), getContext()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this logic work correctly after the changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it work correctly.
when rename.rename_if_cannot_exchange
is true, rename.exchange
is false, in which situation only check the source table is exists or not.
ignore = rename.dictionary ? (!database_catalog.isDictionaryExist(StorageID(elem.to_database_name, elem.to_table_name))) : | ||
(!database_catalog.isTableExist(StorageID(elem.to_database_name, elem.to_table_name), getContext())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean from_database_name
and from_table_name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo.
Thanks for contributing into ClickHouse! The However, I'm not sure what is the semantics of So I suggest not to consider |
For |
the failed case of |
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Support
IF EXISTS
modifier forRENAME DATABASE
/TABLE
/DICTIONARY
query, If this directive is used, one will not get an error if the DATABASE/TABLE/DICTIONARY to be renamed doesn't exist.