-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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 broken SET reuse during projection analysis. #35631
Conversation
0653122
to
6749e84
Compare
@Mergifyio update |
✅ Branch has been successfully updated |
@@ -205,6 +208,7 @@ class InterpreterSelectQuery : public IInterpreterUnionOrSelectQuery | |||
StorageSnapshotPtr storage_snapshot; | |||
|
|||
/// Reuse already built sets for multiple passes of analysis, possibly across interpreters. | |||
std::shared_ptr<SubqueriesForSets> subquery_for_sets; |
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.
You don't share ownership over subquery_for_sets
so there is no need to use std::shared_ptr
.
You can just store SubqueriesForSets
as well as prepared_sets
or if you want to store it in a separate memory use std::unique_ptr
.
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 reason to use std::shared_ptr
is somehow hacky: to make it copyable.
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 understand but I don't see where it's used for the creation of the copy.
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 because we need SelectQueryInfo
to be copyable.
https://github.com/ClickHouse/ClickHouse/blob/master/src/Storages/StorageMerge.cpp#L218
I'll use a different implementation.
@@ -551,8 +550,8 @@ InterpreterSelectQuery::InterpreterSelectQuery( | |||
LOG_TRACE(log, "Running 'analyze' second time"); | |||
|
|||
/// Reuse already built sets for multiple passes of analysis | |||
subquery_for_sets = std::move(query_analyzer->getSubqueriesForSets()); | |||
prepared_sets = query_info.sets.empty() ? query_analyzer->getPreparedSets() : query_info.sets; | |||
subquery_for_sets = std::make_shared<SubqueriesForSets>(std::move(query_analyzer->getSubqueriesForSets())); |
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.
subquery_for_sets
is always initialized, so I'd prefer to use here move-assignment without new memory allocation.
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'll add a comment why shared_ptr is used.
query_info.sets = select.getQueryAnalyzer()->getPreparedSets(); | ||
query_info.subquery_for_sets = std::make_shared<SubqueriesForSets>(std::move(select.getQueryAnalyzer()->getSubqueriesForSets())); |
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 same applied here
141f92d
to
e9dc26d
Compare
e9dc26d
to
1238bab
Compare
@Mergifyio update |
✅ Branch has been successfully updated |
Manual backport #35631 to 22.3: Fix broken SET reuse during projection analysis.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix projection analysis which might lead to wrong query result when IN subquery is used. This fixes #35336