early constant folding improvement

This commit is contained in:
Amos Bird 2019-11-03 15:27:35 +08:00
parent 15c4a19bb1
commit f0b3c1f7c7
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 13 additions and 13 deletions

View File

@ -384,6 +384,9 @@ InterpreterSelectQuery::InterpreterSelectQuery(
} }
} }
if (!options.only_analyze && storage && filter_info && query.prewhere())
throw Exception("PREWHERE is not supported if the table is filtered by row-level security expression", ErrorCodes::ILLEGAL_PREWHERE);
/// Calculate structure of the result. /// Calculate structure of the result.
result_header = getSampleBlockImpl(); result_header = getSampleBlockImpl();
}; };
@ -393,18 +396,18 @@ InterpreterSelectQuery::InterpreterSelectQuery(
bool need_analyze_again = false; bool need_analyze_again = false;
if (analysis_result.prewhere_constant_filter_description.always_false || analysis_result.prewhere_constant_filter_description.always_true) if (analysis_result.prewhere_constant_filter_description.always_false || analysis_result.prewhere_constant_filter_description.always_true)
{ {
auto constant = std::make_shared<ASTLiteral>(0u);
if (analysis_result.prewhere_constant_filter_description.always_true) if (analysis_result.prewhere_constant_filter_description.always_true)
constant->value = 1u; query.setExpression(ASTSelectQuery::Expression::PREWHERE, {});
query.setExpression(ASTSelectQuery::Expression::PREWHERE, constant); else
query.setExpression(ASTSelectQuery::Expression::PREWHERE, std::make_shared<ASTLiteral>(0u));
need_analyze_again = true; need_analyze_again = true;
} }
if (analysis_result.where_constant_filter_description.always_false || analysis_result.where_constant_filter_description.always_true) if (analysis_result.where_constant_filter_description.always_false || analysis_result.where_constant_filter_description.always_true)
{ {
auto constant = std::make_shared<ASTLiteral>(0u);
if (analysis_result.where_constant_filter_description.always_true) if (analysis_result.where_constant_filter_description.always_true)
constant->value = 1u; query.setExpression(ASTSelectQuery::Expression::WHERE, {});
query.setExpression(ASTSelectQuery::Expression::WHERE, constant); else
query.setExpression(ASTSelectQuery::Expression::WHERE, std::make_shared<ASTLiteral>(0u));
need_analyze_again = true; need_analyze_again = true;
} }
if (need_analyze_again) if (need_analyze_again)
@ -1035,9 +1038,6 @@ void InterpreterSelectQuery::executeImpl(TPipeline & pipeline, const BlockInputS
else else
pipeline.streams.emplace_back(std::make_shared<NullBlockInputStream>(source_header)); pipeline.streams.emplace_back(std::make_shared<NullBlockInputStream>(source_header));
if (storage && expressions.filter_info && expressions.prewhere_info)
throw Exception("PREWHERE is not supported if the table is filtered by row-level security expression", ErrorCodes::ILLEGAL_PREWHERE);
if (expressions.prewhere_info) if (expressions.prewhere_info)
{ {
if constexpr (pipeline_with_processors) if constexpr (pipeline_with_processors)

View File

@ -11,15 +11,15 @@ SELECT \n a, \n b\nFROM \n(\n SELECT \n 1 AS a, \n 1 AS b
SELECT \n a, \n b\nFROM \n(\n SELECT 1 AS a\n)\nANY FULL OUTER JOIN \n(\n SELECT \n 1 AS a, \n 1 AS b\n) USING (a)\nWHERE b = 0 SELECT \n a, \n b\nFROM \n(\n SELECT 1 AS a\n)\nANY FULL OUTER JOIN \n(\n SELECT \n 1 AS a, \n 1 AS b\n) USING (a)\nWHERE b = 0
SELECT \n a, \n b\nFROM \n(\n SELECT \n 1 AS a, \n 1 AS b\n)\nANY FULL OUTER JOIN \n(\n SELECT 1 AS a\n) USING (a)\nWHERE b = 0 SELECT \n a, \n b\nFROM \n(\n SELECT \n 1 AS a, \n 1 AS b\n)\nANY FULL OUTER JOIN \n(\n SELECT 1 AS a\n) USING (a)\nWHERE b = 0
-------Need push down------- -------Need push down-------
SELECT toString(value) AS value\nFROM \n(\n SELECT 1 AS value\n WHERE 1\n)\nWHERE 1 SELECT toString(value) AS value\nFROM \n(\n SELECT 1 AS value\n)
1 1
SELECT id\nFROM \n(\n SELECT 1 AS id\n WHERE 1\n UNION ALL\n SELECT 2 AS `2`\n WHERE 0\n)\nWHERE id = 1 SELECT id\nFROM \n(\n SELECT 1 AS id\n UNION ALL\n SELECT 2 AS `2`\n WHERE 0\n)\nWHERE id = 1
1 1
SELECT id\nFROM \n(\n SELECT arrayJoin([1, 2, 3]) AS id\n WHERE id = 1\n)\nWHERE id = 1 SELECT id\nFROM \n(\n SELECT arrayJoin([1, 2, 3]) AS id\n WHERE id = 1\n)\nWHERE id = 1
1 1
SELECT id\nFROM \n(\n SELECT arrayJoin([1, 2, 3]) AS id\n WHERE id = 1\n)\nWHERE id = 1 SELECT id\nFROM \n(\n SELECT arrayJoin([1, 2, 3]) AS id\n WHERE id = 1\n)\nWHERE id = 1
1 1
SELECT \n id, \n subquery\nFROM \n(\n SELECT \n 1 AS id, \n CAST(1, \'UInt8\') AS subquery\n WHERE 1\n)\nWHERE 1 SELECT \n id, \n subquery\nFROM \n(\n SELECT \n 1 AS id, \n CAST(1, \'UInt8\') AS subquery\n)
1 1 1 1
SELECT \n a, \n b\nFROM \n(\n SELECT \n toUInt64(sum(id) AS b) AS a, \n b\n FROM test_00597\n HAVING a = 3\n)\nWHERE a = 3 SELECT \n a, \n b\nFROM \n(\n SELECT \n toUInt64(sum(id) AS b) AS a, \n b\n FROM test_00597\n HAVING a = 3\n)\nWHERE a = 3
3 3 3 3

View File

@ -1,5 +1,5 @@
SELECT 1\nWHERE 0 SELECT 1\nWHERE 0
SELECT 1\nWHERE 1 SELECT 1
SELECT 1\nWHERE 0 SELECT 1\nWHERE 0
SELECT 1\nWHERE 1 IN (\n(\n SELECT arrayJoin([1, 2, 3])\n) AS subquery) SELECT 1\nWHERE 1 IN (\n(\n SELECT arrayJoin([1, 2, 3])\n) AS subquery)
SELECT 1\nWHERE NOT ignore() SELECT 1\nWHERE NOT ignore()