mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
early constant folding improvement
This commit is contained in:
parent
15c4a19bb1
commit
f0b3c1f7c7
@ -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.
|
||||
result_header = getSampleBlockImpl();
|
||||
};
|
||||
@ -393,18 +396,18 @@ InterpreterSelectQuery::InterpreterSelectQuery(
|
||||
bool need_analyze_again = false;
|
||||
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)
|
||||
constant->value = 1u;
|
||||
query.setExpression(ASTSelectQuery::Expression::PREWHERE, constant);
|
||||
query.setExpression(ASTSelectQuery::Expression::PREWHERE, {});
|
||||
else
|
||||
query.setExpression(ASTSelectQuery::Expression::PREWHERE, std::make_shared<ASTLiteral>(0u));
|
||||
need_analyze_again = 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)
|
||||
constant->value = 1u;
|
||||
query.setExpression(ASTSelectQuery::Expression::WHERE, constant);
|
||||
query.setExpression(ASTSelectQuery::Expression::WHERE, {});
|
||||
else
|
||||
query.setExpression(ASTSelectQuery::Expression::WHERE, std::make_shared<ASTLiteral>(0u));
|
||||
need_analyze_again = true;
|
||||
}
|
||||
if (need_analyze_again)
|
||||
@ -1035,9 +1038,6 @@ void InterpreterSelectQuery::executeImpl(TPipeline & pipeline, const BlockInputS
|
||||
else
|
||||
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 constexpr (pipeline_with_processors)
|
||||
|
@ -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 \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-------
|
||||
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
|
||||
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
|
||||
SELECT id\nFROM \n(\n SELECT arrayJoin([1, 2, 3]) AS id\n WHERE id = 1\n)\nWHERE id = 1
|
||||
1
|
||||
SELECT id\nFROM \n(\n SELECT arrayJoin([1, 2, 3]) AS id\n WHERE id = 1\n)\nWHERE id = 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
|
||||
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
|
||||
|
@ -1,5 +1,5 @@
|
||||
SELECT 1\nWHERE 0
|
||||
SELECT 1\nWHERE 1
|
||||
SELECT 1
|
||||
SELECT 1\nWHERE 0
|
||||
SELECT 1\nWHERE 1 IN (\n(\n SELECT arrayJoin([1, 2, 3])\n) AS subquery)
|
||||
SELECT 1\nWHERE NOT ignore()
|
||||
|
Loading…
Reference in New Issue
Block a user