-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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 HashMethodOneNumber with const column #40020
Conversation
Thanks! Can you add a test for it? |
Also worth fixing all HashMethod*, not only HashMethodOneNumber, for example such query leads to segfault:
If you have time, you can fix it in this PR, if not, I will create a separate PR. |
I will add test. In addition, I found this bug also happens for other method, e.g. HashMethodFixedString,... The following query will crash the server. select 'aaa' from numbers(10) intersect select 'aaa' from numbers(10); Seem a critical bug. |
I will added the fix for other types. |
@Avogar I added the fix fo HashMethodString and HashMethodFixedString as well as some tests. IMO only these 3 HashMethod* are affected by this bug. If others method also need adding, I think someone else should add it as I'm not quite familiar with their implementation. |
The query no. 6 of test 'distinct_in_order' has slowed down Looks like checking const every time getting key is not a good idea. I will rewrite the implementation. |
2085583
to
17fa807
Compare
src/Common/ColumnsHashing.h
Outdated
if (isColumnConst(*column)) | ||
{ | ||
const_value = unalignedLoad<FieldType>(vec); | ||
get_key_holder_impl = [this](size_t /*row*/) { return const_value; }; | ||
} | ||
else | ||
{ | ||
get_key_holder_impl = [this](size_t row) { return unalignedLoad<FieldType>(vec + row * sizeof(FieldType)); }; | ||
} |
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.
Let's remove code duplication from these two constructors to a separate method
The tests should check both INTERSECT and EXCEPT. |
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.
.
@alexey-milovidov done materializing column in IntersectOrExceptTransform and add more test. In addition, as your suggestion, I remove some code in HashMethodString to handle const column (added in #37738 to fix server crashing while intersect const column, this PR should fix that as well). |
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.
Now it looks much better
Let's wait for the rest of checks and merge it |
Backport #40020 to 22.6: fix HashMethodOneNumber with const column
Backport #40020 to 22.3: fix HashMethodOneNumber with const column
-- Test: except return incorrect result for const column | ||
SELECT 2 FROM numbers(10) EXCEPT SELECT 1 FROM numbers(5); | ||
SELECT toString(2) FROM numbers(10) EXCEPT SELECT toString(1) FROM numbers(5); | ||
SELECT '2' FROM numbers(10) EXCEPT SELECT '1' FROM numbers(5); |
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.
Why doesn't CI complain about missing EOL?
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 think the CI only run style check for code file not test file 😂
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.
OK. There is a well-known adage: "all text files should end with a newline". POSIX also has a definition of what is a line . I think it's better to apply this rule to all text files.
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.
Ok, I will notice it for future PRs.
Backport #40020 to 22.7: fix HashMethodOneNumber with const column
Backport ClickHouse#40020 to 22.5: fix HashMethodOneNumber with const column
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
fix HashMethodOneNumber get wrong key value when column is const
Close #39818