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
Fix filtering by virtual columns with OR filter in query (resubmit) #55678
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The problem with the initial implementation ClickHouse#52653 was: - OR can have multiple arguments - It simply not correct to assume that if there are two arguments this is OK. Consider the following example: "WHERE (column_not_from_partition_by = 1) OR false OR false" Will be converted to: "WHERE false OR false" And it will simply read nothing. Yes, we could apply some optimization for bool, but this will not always work, since to optimize things like "0 = 1" we need to execute it. And the only way to make handle this correctly (with ability to ignore some commands during filtering) is to make is_constant() function return has it use something from the input block, so that we can be sure, that we have some sensible, and not just "false". Plus we cannot simply ignore the difference of the input and output arguments of handling OR, we need to add always-true (1/true) if the size is different, since otherwise it could break invariants (see comment in the code). This includes (but not limited to): - _part* filtering for MergeTree - _path/_file for various File/HDFS/... engines - _table for Merge - ... P.S. analyzer does not have this bug, since it execute expression as whole, and this is what filterBlockWithQuery() should do actually instead, but this will be a more complex patch. Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com> (cherry picked from commit b107712)
After the previous patch "x OR 1" will not execute "x", and because of this test_system_merges::test_mutation_simple started to fail since "sleep" function did not executed. Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
robot-ch-test-poll1
added
the
pr-bugfix
Pull request with bugfix, not backported by default
label
Oct 16, 2023
This is an automated comment for commit b0fbd79 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
|
|
@azat a test has failed. |
@alexey-milovidov it is unrelated (see the comment above) |
alexey-milovidov
added
the
pr-must-backport
Pull request should be backported intentionally. Use this label with great care!
label
Oct 17, 2023
This was referenced Oct 17, 2023
robot-clickhouse-ci-2
added a commit
that referenced
this pull request
Oct 17, 2023
…eeaf7d3cf0ceb3af619fb45962a09 Cherry pick #55678 to 23.7: Fix filtering by virtual columns with OR filter in query (resubmit)
robot-clickhouse
added a commit
that referenced
this pull request
Oct 17, 2023
…ter in query (resubmit)
robot-clickhouse-ci-2
added a commit
that referenced
this pull request
Oct 17, 2023
…eeaf7d3cf0ceb3af619fb45962a09 Cherry pick #55678 to 23.8: Fix filtering by virtual columns with OR filter in query (resubmit)
robot-clickhouse
added a commit
that referenced
this pull request
Oct 17, 2023
…ter in query (resubmit)
robot-clickhouse-ci-2
added a commit
that referenced
this pull request
Oct 17, 2023
…eeaf7d3cf0ceb3af619fb45962a09 Cherry pick #55678 to 23.9: Fix filtering by virtual columns with OR filter in query (resubmit)
robot-clickhouse
added a commit
that referenced
this pull request
Oct 17, 2023
…ter in query (resubmit)
robot-clickhouse-ci-2
added
the
pr-backports-created
Backport PRs are successfully created, it won't be processed by CI script anymore
label
Oct 17, 2023
alexey-milovidov
added a commit
that referenced
this pull request
Oct 18, 2023
Backport #55678 to 23.9: Fix filtering by virtual columns with OR filter in query (resubmit)
alexey-milovidov
added a commit
that referenced
this pull request
Oct 18, 2023
Backport #55678 to 23.8: Fix filtering by virtual columns with OR filter in query (resubmit)
alexey-milovidov
added a commit
that referenced
this pull request
Oct 18, 2023
Backport #55678 to 23.7: Fix filtering by virtual columns with OR filter in query (resubmit)
amosbird
added a commit
to amosbird/ClickHouse
that referenced
this pull request
Dec 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
pr-backports-created
Backport PRs are successfully created, it won't be processed by CI script anymore
pr-bugfix
Pull request with bugfix, not backported by default
pr-must-backport
Pull request should be backported intentionally. Use this label with great care!
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix filtering by virtual columns with OR filter in query (_part* filtering for MergeTree, _path/_file for various File/HDFS/... engines, _table for Merge)
The problem with the initial implementation #52653 was:
OR can have multiple arguments
It simply not correct to assume that if there are two arguments this is OK.
Consider the following example:
"WHERE (column_not_from_partition_by = 1) OR false OR false"
Will be converted to:
"WHERE false OR false"
And it will simply read nothing.
Yes, we could apply some optimization for bool, but this will not always
work, since to optimize things like "0 = 1" we need to execute it.
And the only way to make handle this correctly (with ability to ignore
some commands during filtering) is to make is_constant() function return
has it use something from the input block, so that we can be sure, that
we have some sensible, and not just "false".
Plus we cannot simply ignore the difference of the input and output
arguments of handling OR, we need to add always-true (1/true) if the
size is different, since otherwise it could break invariants (see
comment in the code).
P.S. analyzer does not have this bug, since it execute expression as
whole, and this is what filterBlockWithQuery() should do actually
instead, but this will be a more complex patch.
Resubmits: #55418 (due to the test failure it got reverted, this had been addressed in this PR, see last patch) (cc @alexey-milovidov )
Reverts: #55657 (cc @antonio2368 )
Fixes: #54779 (cc @slanderous-mambo )
Fixes: #55288 (cc @allen12921)