Skip to content

Commit

Permalink
Merge branch 'master' into filesystemCacheSizeLimitMetric
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitamikhaylov authored Jul 20, 2023
2 parents b3c42a1 + f8f9f86 commit 59af8f4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/ru/development/build-osx.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/
$ rm -rf build
$ mkdir build
$ cd build
$ cmake -DCMAKE_C_COMPILER=$(brew --prefix llvm)/bin/clang -DCMAKE_CXX_COMPILER==$(brew --prefix llvm)/bin/clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_JEMALLOC=OFF ..
$ cmake -DCMAKE_C_COMPILER=$(brew --prefix llvm)/bin/clang -DCMAKE_CXX_COMPILER=$(brew --prefix llvm)/bin/clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_JEMALLOC=OFF ..
$ cmake -DCMAKE_C_COMPILER=$(brew --prefix llvm)/bin/clang -DCMAKE_CXX_COMPILER=$(brew --prefix llvm)/bin/clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_JEMALLOC=OFF ..
$ cmake --build . --config RelWithDebInfo
$ cd ..
Expand Down
9 changes: 6 additions & 3 deletions src/Processors/QueryPlan/Optimizations/optimizeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ void optimizeTreeSecondPass(const QueryPlanOptimizationSettings & optimization_s

while (!stack.empty())
{
/// NOTE: optimizePrewhere can modify the stack.
optimizePrewhere(stack, nodes);
optimizePrimaryKeyCondition(stack);

{
/// NOTE: frame cannot be safely used after stack was modified.
auto & frame = stack.back();
Expand All @@ -125,6 +129,7 @@ void optimizeTreeSecondPass(const QueryPlanOptimizationSettings & optimization_s
if (optimization_settings.read_in_order)
optimizeReadInOrder(*frame.node, nodes);

/// Projection optimization relies on PK optimization
if (optimization_settings.optimize_projection)
num_applied_projection
+= optimizeUseAggregateProjections(*frame.node, nodes, optimization_settings.optimize_use_implicit_projections);
Expand All @@ -148,6 +153,7 @@ void optimizeTreeSecondPass(const QueryPlanOptimizationSettings & optimization_s

if (optimization_settings.optimize_projection)
{
/// Projection optimization relies on PK optimization
if (optimizeUseNormalProjections(stack, nodes))
{
++num_applied_projection;
Expand All @@ -164,9 +170,6 @@ void optimizeTreeSecondPass(const QueryPlanOptimizationSettings & optimization_s
}
}

/// NOTE: optimizePrewhere can modify the stack.
optimizePrewhere(stack, nodes);
optimizePrimaryKeyCondition(stack);
enableMemoryBoundMerging(*stack.back().node, nodes);

stack.pop_back();
Expand Down
3 changes: 2 additions & 1 deletion src/Processors/QueryPlan/Optimizations/projectionsCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ bool QueryDAG::buildImpl(QueryPlan::Node & node, ActionsDAG::NodeRawConstPtrs &
if (prewhere_info->prewhere_actions)
{
appendExpression(prewhere_info->prewhere_actions);
if (const auto * filter_expression = findInOutputs(*dag, prewhere_info->prewhere_column_name, prewhere_info->remove_prewhere_column))
if (const auto * filter_expression
= findInOutputs(*dag, prewhere_info->prewhere_column_name, prewhere_info->remove_prewhere_column))
filter_nodes.push_back(filter_expression);
else
return false;
Expand Down
1 change: 0 additions & 1 deletion src/Processors/QueryPlan/Optimizations/projectionsCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ std::shared_ptr<PartitionIdToMaxBlock> getMaxAddedBlocks(ReadFromMergeTree * rea

/// This is a common DAG which is a merge of DAGs from Filter and Expression steps chain.
/// Additionally, for all the Filter steps, we collect filter conditions into filter_nodes.
/// Flag remove_last_filter_node is set in case if the last step is a Filter step and it should remove filter column.
struct QueryDAG
{
ActionsDAGPtr dag;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
drop table if exists t;

CREATE TABLE t (id UInt64, id2 UInt64, id3 UInt64, PROJECTION t_reverse (SELECT id, id2, id3 ORDER BY id2, id, id3)) ENGINE = MergeTree ORDER BY (id) settings index_granularity = 4;

insert into t SELECT number, -number, number FROM numbers(10000);

set max_rows_to_read = 4;

select count() from t where id = 3;

drop table t;

0 comments on commit 59af8f4

Please sign in to comment.