rename/exchange database/table/dictionary support IF EXISTS syntax#31081
rename/exchange database/table/dictionary support IF EXISTS syntax#31081tavplubix merged 5 commits intoClickHouse:masterfrom kafka1991:rename_support_ifexists
Conversation
|
Needs 'can be tested' label |
| RENAME TABLE t0 TO t1; -- { serverError 57 } | ||
| DROP TABLE t1; | ||
| RENAME TABLE t0 TO t1; | ||
|
|
There was a problem hiding this comment.
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.
| 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.
Also need to update ASTRenameQuery::formatQueryImpl(...) to make formatter consistent with parser.
| 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.
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.
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.
Will this logic work correctly after the changes?
There was a problem hiding this comment.
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.
Do you mean from_database_name and from_table_name?
|
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 EXISTSmodifier forRENAME DATABASE/TABLE/DICTIONARYquery, If this directive is used, one will not get an error if the DATABASE/TABLE/DICTIONARY to be renamed doesn't exist.