Skip to content
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

Merged
merged 8 commits into from
Aug 12, 2022

Conversation

canhld94
Copy link
Contributor

@canhld94 canhld94 commented Aug 9, 2022

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in official stable or prestable release)

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

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label Aug 9, 2022
@Avogar Avogar self-assigned this Aug 9, 2022
@Avogar
Copy link
Member

Avogar commented Aug 9, 2022

Thanks! Can you add a test for it?

@Avogar
Copy link
Member

Avogar commented Aug 9, 2022

Also worth fixing all HashMethod*, not only HashMethodOneNumber, for example such query leads to segfault:

select '1' from numbers(10) intersect select '1' from numbers(10)

If you have time, you can fix it in this PR, if not, I will create a separate PR.

@canhld94
Copy link
Contributor Author

canhld94 commented Aug 9, 2022

Thanks! Can you add a test for it?

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.

@canhld94
Copy link
Contributor Author

canhld94 commented Aug 9, 2022

Also worth fixing all HashMethod*, not only HashMethodOneNumber, for example such query leads to segfault:

select '1' from numbers(10) intersect select '1' from numbers(10)

If you have time, you can fix it in this PR, if not, I will create a separate PR.

I will added the fix for other types.

@qoega qoega added the can be tested Allows running workflows for external contributors label Aug 9, 2022
@canhld94
Copy link
Contributor Author

canhld94 commented Aug 9, 2022

Also worth fixing all HashMethod*, not only HashMethodOneNumber, for example such query leads to segfault:

select '1' from numbers(10) intersect select '1' from numbers(10)

If you have time, you can fix it in this PR, if not, I will create a separate PR.

@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.

Comment on lines 66 to 74
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)); };
}
Copy link
Member

@Avogar Avogar Aug 10, 2022

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

@alexey-milovidov
Copy link
Member

alexey-milovidov commented Aug 11, 2022

@Avogar @canhld94 The Aggregation methods don't expect to work const columns and its implementation is correct.
It is reasonable to keep code compact. The caller should materialize const columns before using them.

@alexey-milovidov
Copy link
Member

The tests should check both INTERSECT and EXCEPT.

Copy link
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@alexey-milovidov alexey-milovidov self-assigned this Aug 11, 2022
@canhld94
Copy link
Contributor Author

@Avogar @canhld94 The Aggregation methods don't expect to work const columns and its implementation is correct. It is reasonable to keep code compact. The caller should materialize const columns before using them.

@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).

Copy link
Member

@Avogar Avogar left a 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

@Avogar Avogar added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 11, 2022
@Avogar
Copy link
Member

Avogar commented Aug 11, 2022

Let's wait for the rest of checks and merge it

@Avogar Avogar merged commit 4c7222d into ClickHouse:master Aug 12, 2022
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 18, 2022
alesapin pushed a commit that referenced this pull request Aug 22, 2022
Backport #40020 to 22.6: fix HashMethodOneNumber with const column
alesapin pushed a commit that referenced this pull request Aug 26, 2022
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);
Copy link
Collaborator

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?

Copy link
Contributor Author

@canhld94 canhld94 Aug 30, 2022

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 😂

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Felixoid pushed a commit that referenced this pull request Sep 2, 2022
Backport #40020 to 22.7: fix HashMethodOneNumber with const column
ch-devops pushed a commit to ClibMouse/ClickHouse that referenced this pull request Feb 1, 2023
Backport ClickHouse#40020 to 22.5: fix HashMethodOneNumber with const column
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors 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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong result of intersect
6 participants