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 crash when predicate optimzer & join on #4794

Merged
merged 2 commits into from Apr 1, 2019

Conversation

zhang2014
Copy link
Contributor

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

For changelog. Remove if this is non-significant change.

Category (leave one):

  • Bug Fix

Short description (up to few sentences):
#3588 (comment)

@@ -53,3 +53,5 @@ SELECT \n date, \n id, \n name, \n value, \n b.date, \n b.name
2000-01-01 1 test string 1 1 2000-01-01 test string 1 1
SELECT \n id, \n date, \n name, \n value\nFROM \n(\n SELECT \n toInt8(1) AS id, \n toDate(\'2000-01-01\') AS date\n FROM system.numbers \n LIMIT 1\n) \nANY LEFT JOIN \n(\n SELECT *\n FROM test.test \n WHERE date = toDate(\'2000-01-01\')\n) AS b USING (date, id)\nWHERE b.date = toDate(\'2000-01-01\')
1 2000-01-01 test string 1 1
SELECT \n date, \n id, \n name, \n value, \n `b.date`, \n `b.id`, \n `b.name`, \n `b.value`\nFROM \n(\n SELECT \n date, \n id, \n name, \n value, \n b.date, \n b.id, \n b.name, \n b.value\n FROM \n (\n SELECT \n date, \n id, \n name, \n value\n FROM test.test \n WHERE id = 1\n ) AS a \n ANY LEFT JOIN \n (\n SELECT *\n FROM test.test \n ) AS b ON id = b.id\n WHERE id = 1\n) \nWHERE id = 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if b.date should be here.

@@ -74,7 +74,7 @@ void TranslateQualifiedNamesMatcher::visit(ASTIdentifier & identifier, ASTPtr &,
IdentifierSemantic::setMembership(identifier, best_table_pos + 1);

/// In case if column from the joined table are in source columns, change it's name to qualified.
if (best_table_pos && data.source_columns.count(identifier.shortName()))
if (best_table_pos && !data.source_columns.empty() && data.source_columns.count(identifier.shortName()))
Copy link
Member

Choose a reason for hiding this comment

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

How does it change anything? Does the crash happen inside identifier.shortName()?

Copy link
Contributor

@4ertus2 4ertus2 Mar 25, 2019

Choose a reason for hiding this comment

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

It looks like some HACK. The base line means: if identifier belongs to the second table, we need a long name for it. And it looks correct without changes.
The issue may be in push down where we need to clear semantics for Identifier before pushing it down.

Copy link
Contributor

@4ertus2 4ertus2 left a comment

Choose a reason for hiding this comment

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

If you do not need to push long name for Identifier in Push Down subselect, clear IdentifierSemanticImpl.need_long_name there. Or even better, make a new Identifier with the same short name for subselect.

There's a dangerous place in Push Down ( qualifiedName() ) where we get qualified name as compound string. ASTIdentifier now expects that if it is compound it contains correct 2 name parts. The reason of crash, I think, is an attempt to make compound identifier with no parts set and later access to the long identifier name.

@zhang2014
Copy link
Contributor Author

@4ertus2 OK, I will try to understand and solve the problem you said : )

@alexey-milovidov
Copy link
Member

Functional tests with address sanitizer have failed at predicate expression optimizer:
https://clickhouse-test-reports.s3.yandex.net/4794/c4a7009c390b7f74b9a8e15124cbd82a3d35dafd/functional_stateless_tests_(address).html
(See stderr.txt)

It makes clear that the fix is not viable.

@4ertus2 4ertus2 merged commit 019c6ca into ClickHouse:master Apr 1, 2019
@abyss7 abyss7 added the pr-bugfix Pull request with bugfix, not backported by default label Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-bugfix Pull request with bugfix, not backported by default
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants