mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
ISSUE-5695: support push down predicate to final subquery
This commit is contained in:
parent
adfc369172
commit
b01f54ade1
@ -336,7 +336,8 @@ struct Settings : public SettingsCollection<Settings>
|
||||
\
|
||||
/** Obsolete settings that do nothing but left for compatibility reasons. Remove each one after half a year of obsolescence. */ \
|
||||
\
|
||||
M(SettingBool, allow_experimental_low_cardinality_type, true, "Obsolete setting, does nothing. Will be removed after 2019-08-13")
|
||||
M(SettingBool, allow_experimental_low_cardinality_type, true, "Obsolete setting, does nothing. Will be removed after 2019-08-13") \
|
||||
M(SettingBool, allow_push_predicate_to_final_subquery, 1, "Allow push predicate to final subquery.")
|
||||
|
||||
DECLARE_SETTINGS_COLLECTION(LIST_OF_SETTINGS)
|
||||
|
||||
|
@ -138,7 +138,10 @@ bool PredicateExpressionsOptimizer::allowPushDown(
|
||||
const std::vector<IdentifierWithQualifier> & dependencies,
|
||||
OptimizeKind & optimize_kind)
|
||||
{
|
||||
if (!subquery || subquery->final() || subquery->limitBy() || subquery->limitLength() || subquery->with())
|
||||
if (!subquery ||
|
||||
(!settings.allow_push_predicate_to_final_subquery && subquery->final()) ||
|
||||
subquery->limitBy() || subquery->limitLength() ||
|
||||
subquery->with())
|
||||
return false;
|
||||
else
|
||||
{
|
||||
|
@ -37,6 +37,9 @@ class PredicateExpressionsOptimizer
|
||||
const UInt64 max_expanded_ast_elements;
|
||||
const String count_distinct_implementation;
|
||||
|
||||
/// for final PredicatePushOptimizer
|
||||
const bool allow_push_predicate_to_final_subquery;
|
||||
|
||||
/// for PredicateExpressionsOptimizer
|
||||
const bool enable_optimize_predicate_expression;
|
||||
const bool join_use_nulls;
|
||||
@ -46,6 +49,7 @@ class PredicateExpressionsOptimizer
|
||||
: max_ast_depth(settings.max_ast_depth),
|
||||
max_expanded_ast_elements(settings.max_expanded_ast_elements),
|
||||
count_distinct_implementation(settings.count_distinct_implementation),
|
||||
allow_push_predicate_to_final_subquery(settings.allow_push_predicate_to_final_subquery),
|
||||
enable_optimize_predicate_expression(settings.enable_optimize_predicate_expression),
|
||||
join_use_nulls(settings.join_use_nulls)
|
||||
{}
|
||||
|
@ -0,0 +1,50 @@
|
||||
{
|
||||
"meta":
|
||||
[
|
||||
{
|
||||
"name": "COUNT()",
|
||||
"type": "UInt64"
|
||||
}
|
||||
],
|
||||
|
||||
"data":
|
||||
[
|
||||
{
|
||||
"COUNT()": "1"
|
||||
}
|
||||
],
|
||||
|
||||
"rows": 1,
|
||||
|
||||
"statistics":
|
||||
{
|
||||
"elapsed": 0.000780393,
|
||||
"rows_read": 4,
|
||||
"bytes_read": 16
|
||||
}
|
||||
}
|
||||
{
|
||||
"meta":
|
||||
[
|
||||
{
|
||||
"name": "COUNT()",
|
||||
"type": "UInt64"
|
||||
}
|
||||
],
|
||||
|
||||
"data":
|
||||
[
|
||||
{
|
||||
"COUNT()": "1"
|
||||
}
|
||||
],
|
||||
|
||||
"rows": 1,
|
||||
|
||||
"statistics":
|
||||
{
|
||||
"elapsed": 0.000687364,
|
||||
"rows_read": 2,
|
||||
"bytes_read": 8
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
DROP TABLE IF EXISTS test_00974;
|
||||
|
||||
CREATE TABLE test_00974
|
||||
(
|
||||
date Date,
|
||||
x Int32,
|
||||
ver UInt64
|
||||
)
|
||||
ENGINE = ReplacingMergeTree(date, x, 4096);
|
||||
|
||||
INSERT INTO test_00974 VALUES ('2019-07-23', 1, 1), ('2019-07-23', 1, 2);
|
||||
INSERT INTO test_00974 VALUES ('2019-07-23', 2, 1), ('2019-07-23', 2, 2);
|
||||
|
||||
SELECT COUNT() FROM (SELECT * FROM test_00974 FINAL) where x = 1 SETTINGS allow_push_predicate_to_final_subquery = 0 FORMAT JSON ;
|
||||
SELECT COUNT() FROM (SELECT * FROM test_00974 FINAL) where x = 1 SETTINGS allow_push_predicate_to_final_subquery = 1 FORMAT JSON ;
|
||||
|
||||
DROP TABLE test_00974;
|
Loading…
Reference in New Issue
Block a user