-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Disambiguate alter commands list #59532
Disambiguate alter commands list #59532
Conversation
This is an automated comment for commit 425799b with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page Successful checks
|
Can it cover as well #17303? |
@UnamedRus I will check that issue, but it seems like not a parsing, but a logical issue there. |
Actually yeah, my memory fails me. |
The scope of the PR is changed: because the necessary part is only the alter commands and the TTL elements are harder to parse properly ( |
Actually there is still an issue if you don't use the
Here |
So about this issue, I got stuck with some build issues. With Sasha we talked about that I shouldn't format the queries with parenthesis by default, because that makes online upgrading dangerous: if an alter command serialized by a new version reaches a node with an older version, then the parsing will fail on that node probably causing similar issues like when a user now runs
However there is an issue with option1: in order to access the server settings, we need to call If we opted for do not have server settings, then we would have to wait until the oldest LTS version of clickhouse will contain the new parsers capable of parsing alter commands with parentheses to fix this bug, or we should introduce a change where the upgrade from an older version can break online clusters if they do alters during upgrades. I don't feel any if the above choice is a good solution, so I am here to ask you, which one should we do:
I really don't see a clearly good solution here. As a result I will introduce a global variable that will be updated with the value of the regarding server setting in order to bridge the gap between server settings and the parsers. It is meant to a temporary solution until we can enforce the serialization with the new format. |
…ting" This reverts commit d7131a3.
…ement-list-and-alter-command-list
BTW, when change happened to D DDL worker, it was done via user level setting |
This change is not anyhow related to DDLWorker. There's already a compatibility setting ( |
// This function is only meant to be called during application startup | ||
// For reasons see https://github.com/ClickHouse/ClickHouse/pull/59532 | ||
static void setFormatAlterCommandsWithParentheses(bool value) { format_alter_commands_with_parentheses = value; } |
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.
Should we call it in clickhouse-client
and clickhouse-local
as well? They print a formatted query:
localhost.localdomain :) SeLeCt NuLl
SELECT NULL
Query id: fdbaa7b8-75c0-4f58-b79c-46b9ae290e1e
┌─NULL─┐
│ ᴺᵁᴸᴸ │
└──────┘
1 row in set. Elapsed: 0.005 sec.
I think it's fine to unconditionally set it to true
for that purpose
const auto alter_command = command_col.getDataAt(i).toString(); | ||
const auto with_round_bracket = alter_command.front() == '('; | ||
ParserAlterCommand parser{with_round_bracket}; |
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.
Does it make sense to always allow round brackets when parsing, despite the value of the setting? So the setting will be only used for formatting, and the parser will be able to always understand both versions
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.
The idea is by allowing parsing with parentheses by default is the transition can be smoother during migrating to newer versions. E.g. during live migration if there are one replica which produces alter commands with parens, then the older replicas will parse it properly.
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.
Maybe my previous answer wasn't the best. So I wanted to avoid allowing the "mix" of the old and new syntax. So in an alter command list each command must or mustn't have to be surrounded with parentheses. E.g.: ALTER TABLE x MODIFY TTL, DROP COLUM a
is fine, ALTER TABLE x (MODIFY TTL), (DROP COLUMN a)
also fine, but ALTER TABLE x (MODIFY TTL), DROP COLUMN a
is not fine.
This means in some way ParserAlterCommandList
has to be able to enforce it. This could be done in two ways in my opinion:
- The list parser figures this out and passes it to the individual command parser.
- The individual command parser decides whether parens should be used or not and because in
ParserAlterCommandList::parseImpl
only a single parser is used, it can carry over this information. It is doable, but it would introduce in my opnion a hidden relation between the first parsed command and every command after that. I think right now parsers doesn't have this kind of "memory" in general. Thus, I opted for option 1.
That's why here determining with_round_bracket
is necessary. What do you think?
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.
So in an alter command list each command must or mustn't have to be surrounded with parentheses.
Yes, I agree.
This means in some way ParserAlterCommandList has to be able to enforce it. ... That's why here determining with_round_bracket is necessary.
Sorry, I missed this when reading the code, it was unobvious.
Yes, the first option is better because in the worst case, someone will pass true
or false
unconditionally instead of proper with_round_bracket
flag (so only one version of the syntax will work in this place). And with the second option, someone may use one ParserAlterCommand
for multiple queries, and it will cause an obscure bug
@@ -0,0 +1,3 @@ | |||
<clickhouse> | |||
<format_alter_operations_with_parentheses>1</format_alter_operations_with_parentheses> |
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.
We can enable it in functional tests by adding this config to tests/config/install.sh
Btw, functional tests are much better than integration tests: #39359 (comment)
(but it's not necessary to rewrite existing tests)
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.
I checked this, and if we would change this in functional tests, then we would change this for all of the functional tests. I think it shouldn't cause an issue, but we would test something that is not the "default" behavior of clickhouse.
Furthermore I used the same queries in functional tests, but expecting the old behavior. So I would say the only question is which way should be the default in functional tests? The other one has to be tested in integration test either way, because we have to change the server setting.
Test failures:
The table
I don't think it has anything to do with my changes, |
…ement-list-and-alter-command-list
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Allow alter operations to be surrounded by parenthesis. The emission of parentheses can be controlled by the
format_alter_operations_with_parentheses
config. By default in formatted queries the parentheses are emitted as we store the formatted alter operations in some places as metadata (e.g.: mutations). The new syntax clarifies some of the queries where alter operations end in a list. E.g.:ALTER TABLE x MODIFY TTL date GROUP BY a, b, DROP COLUMN c
cannot be parsed properly with the old syntax. In the new syntax the queryALTER TABLE x (MODIFY TTL date GROUP BY a, b), (DROP COLUMN c)
is obvious. Older versions are not able to read the new syntax, therefore using the new syntax might cause issues if newer and older version of ClickHouse are mixed in a single cluster.Documentation entry for user-facing changes