Merge pull request #2994 from CurtizJ/CLICKHOUSE-3935

ClickHouse-3935  Fix bug with qualified columns in where clause
This commit is contained in:
alexey-milovidov 2018-08-30 15:01:47 +03:00 committed by GitHub
commit b05c62be9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -356,6 +356,16 @@ void ExpressionAnalyzer::translateQualifiedNamesImpl(ASTPtr & ast, const std::ve
}
else
{
/// If the WHERE clause or HAVING consists of a single quailified column, the reference must be translated not only in children, but also in where_expression and having_expression.
if (ASTSelectQuery * select = typeid_cast<ASTSelectQuery *>(ast.get()))
{
if (select->prewhere_expression)
translateQualifiedNamesImpl(select->prewhere_expression, tables);
if (select->where_expression)
translateQualifiedNamesImpl(select->where_expression, tables);
if (select->having_expression)
translateQualifiedNamesImpl(select->having_expression, tables);
}
for (auto & child : ast->children)
{
/// Do not go to FROM, JOIN, subqueries.

View File

@ -0,0 +1,7 @@
USE test;
DROP TABLE IF EXISTS where_qualified;
CREATE TABLE where_qualified(a UInt32, b UInt8) ENGINE = Memory;
INSERT INTO where_qualified VALUES(1, 1);
INSERT INTO where_qualified VALUES(2, 0);
SELECT a from where_qualified WHERE where_qualified.b;
DROP TABLE where_qualified;