From 7f130d23622c11c2a7c0732ac590a3bebc222015 Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Tue, 26 Feb 2019 17:12:25 +0300 Subject: [PATCH] Don't replace aliased tables. --- dbms/src/Interpreters/SyntaxAnalyzer.cpp | 13 +++++++------ .../0_stateless/00597_push_down_predicate.reference | 2 +- .../0_stateless/00597_push_down_predicate.sql | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dbms/src/Interpreters/SyntaxAnalyzer.cpp b/dbms/src/Interpreters/SyntaxAnalyzer.cpp index 44807f5183a..76e60cb64e6 100644 --- a/dbms/src/Interpreters/SyntaxAnalyzer.cpp +++ b/dbms/src/Interpreters/SyntaxAnalyzer.cpp @@ -606,13 +606,14 @@ void replaceJoinedTable(const ASTTablesInSelectQueryElement* join) { auto & table_id = typeid_cast(*table_expr.database_and_table_name.get()); String expr = "(select * from " + table_id.name + ")"; - if (!table_id.alias.empty()) - { - expr += " as " + table_id.alias; - } - ParserTableExpression parser; - table_expr = static_cast(*parseQuery(parser, expr, 0)); + // FIXME: since the expression "a as b" exposes both "a" and "b" names, which is not equivalent to "(select * from a) as b", + // we can't replace aliased tables. + if (table_id.alias.empty()) + { + ParserTableExpression parser; + table_expr = static_cast(*parseQuery(parser, expr, 0)); + } } } diff --git a/dbms/tests/queries/0_stateless/00597_push_down_predicate.reference b/dbms/tests/queries/0_stateless/00597_push_down_predicate.reference index 83ec3bdb663..5de57b13fd5 100644 --- a/dbms/tests/queries/0_stateless/00597_push_down_predicate.reference +++ b/dbms/tests/queries/0_stateless/00597_push_down_predicate.reference @@ -45,7 +45,7 @@ SELECT \n date, \n id, \n name, \n value, \n date, \n name, \n 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 toInt8(1) AS id\n) \nANY LEFT JOIN \n(\n SELECT *\n FROM test.test \n WHERE value = 1\n) USING (id)\nWHERE value = 1 1 2000-01-01 test string 1 1 -SELECT b.value\nFROM \n(\n SELECT toInt8(1) AS id\n) \nANY LEFT JOIN \n(\n SELECT *\n FROM test.test \n WHERE value = 1\n) AS b USING (id)\nWHERE value = 1 +SELECT b.value\nFROM \n(\n SELECT toInt8(1) AS id\n) \nANY LEFT JOIN test.test AS b USING (id)\nWHERE value = 1 1 SELECT \n date, \n id, \n name, \n value\nFROM \n(\n SELECT \n date, \n id, \n name, \n value, \n date, \n name, \n value\n FROM \n (\n SELECT \n date, \n id, \n name, \n value\n FROM test.test \n WHERE id = 1\n ) \n ANY LEFT JOIN \n (\n SELECT *\n FROM test.test \n WHERE id = 1\n ) USING (id)\n WHERE id = 1\n) \nWHERE id = 1 2000-01-01 1 test string 1 1 diff --git a/dbms/tests/queries/0_stateless/00597_push_down_predicate.sql b/dbms/tests/queries/0_stateless/00597_push_down_predicate.sql index b563a05970f..4d3187c6338 100644 --- a/dbms/tests/queries/0_stateless/00597_push_down_predicate.sql +++ b/dbms/tests/queries/0_stateless/00597_push_down_predicate.sql @@ -92,6 +92,7 @@ SELECT * FROM (SELECT * FROM test.test) ANY LEFT JOIN (SELECT * FROM test.test) ANALYZE SELECT * FROM (SELECT toInt8(1) AS id) ANY LEFT JOIN test.test USING id WHERE value = 1; SELECT * FROM (SELECT toInt8(1) AS id) ANY LEFT JOIN test.test USING id WHERE value = 1; +-- FIXME: no support for aliased tables for now. ANALYZE SELECT b.value FROM (SELECT toInt8(1) AS id) ANY LEFT JOIN test.test AS b USING id WHERE value = 1; SELECT b.value FROM (SELECT toInt8(1) AS id) ANY LEFT JOIN test.test AS b USING id WHERE value = 1;