mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-02 12:32:04 +00:00
Fixes after review
This commit is contained in:
parent
0ecf6164ac
commit
0a42d698ac
@ -1,3 +1,4 @@
|
||||
#include <string_view>
|
||||
#include <Analyzer/Passes/OptimizeRedundantFunctionsInOrderByPass.h>
|
||||
#include <Analyzer/ColumnNode.h>
|
||||
#include <Analyzer/FunctionNode.h>
|
||||
@ -23,14 +24,14 @@ class OptimizeRedundantFunctionsInOrderByVisitor : public InDepthQueryTreeVisito
|
||||
|
||||
static constexpr RedundancyVerdict makeNonRedundant() noexcept { return { .redundant = false, .done = true }; }
|
||||
|
||||
std::unordered_set<String> existing_keys;
|
||||
std::unordered_set<std::string_view> existing_keys;
|
||||
|
||||
RedundancyVerdict isRedundantExpression(FunctionNode * function)
|
||||
{
|
||||
if (function->getArguments().getNodes().empty())
|
||||
return makeNonRedundant();
|
||||
|
||||
if (!function->getFunction()->isDeterministicInScopeOfQuery())
|
||||
const auto & function_base = function->getFunction();
|
||||
if (!function_base || !function_base->isDeterministicInScopeOfQuery())
|
||||
return makeNonRedundant();
|
||||
|
||||
// TODO: handle constants here
|
||||
@ -85,8 +86,8 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
QueryTreeNodes new_order_by;
|
||||
new_order_by.reserve(order_by.getNodes().size());
|
||||
QueryTreeNodes new_order_by_nodes;
|
||||
new_order_by_nodes.reserve(order_by.getNodes().size());
|
||||
|
||||
for (auto & elem : order_by.getNodes())
|
||||
{
|
||||
@ -101,12 +102,12 @@ public:
|
||||
existing_keys.insert(column->getColumnName());
|
||||
}
|
||||
|
||||
new_order_by.push_back(elem);
|
||||
new_order_by_nodes.push_back(elem);
|
||||
}
|
||||
existing_keys.clear();
|
||||
|
||||
if (new_order_by.size() < order_by.getNodes().size())
|
||||
order_by.getNodes() = std::move(new_order_by);
|
||||
if (new_order_by_nodes.size() < order_by.getNodes().size())
|
||||
order_by.getNodes() = std::move(new_order_by_nodes);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -190,16 +190,16 @@ QUERY id: 0
|
||||
COLUMN id: 18, column_name: key, result_type: UInt64, source_id: 8
|
||||
EXPRESSION
|
||||
LIST id: 19, nodes: 2
|
||||
COLUMN id: 20, column_name: key, result_type: UInt64, source_id: 3
|
||||
COLUMN id: 21, column_name: key, result_type: UInt64, source_id: 5
|
||||
COLUMN id: 2, column_name: key, result_type: UInt64, source_id: 3
|
||||
COLUMN id: 20, column_name: key, result_type: UInt64, source_id: 5
|
||||
ORDER BY
|
||||
LIST id: 22, nodes: 2
|
||||
SORT id: 23, sort_direction: ASCENDING, with_fill: 0
|
||||
LIST id: 21, nodes: 2
|
||||
SORT id: 22, sort_direction: ASCENDING, with_fill: 0
|
||||
EXPRESSION
|
||||
COLUMN id: 24, column_name: key, result_type: UInt64, source_id: 3
|
||||
SORT id: 25, sort_direction: ASCENDING, with_fill: 0
|
||||
COLUMN id: 23, column_name: key, result_type: UInt64, source_id: 3
|
||||
SORT id: 24, sort_direction: ASCENDING, with_fill: 0
|
||||
EXPRESSION
|
||||
COLUMN id: 26, column_name: key, result_type: UInt64, source_id: 5
|
||||
COLUMN id: 25, column_name: key, result_type: UInt64, source_id: 5
|
||||
SELECT
|
||||
key,
|
||||
a
|
||||
@ -257,6 +257,28 @@ QUERY id: 0
|
||||
LIST id: 11, nodes: 2
|
||||
COLUMN id: 2, column_name: key, result_type: UInt64, source_id: 3
|
||||
COLUMN id: 4, column_name: a, result_type: UInt8, source_id: 3
|
||||
QUERY id: 0
|
||||
PROJECTION COLUMNS
|
||||
key UInt64
|
||||
PROJECTION
|
||||
LIST id: 1, nodes: 1
|
||||
COLUMN id: 2, column_name: key, result_type: UInt64, source_id: 3
|
||||
JOIN TREE
|
||||
TABLE id: 3, table_name: default.test
|
||||
GROUP BY
|
||||
LIST id: 4, nodes: 1
|
||||
COLUMN id: 2, column_name: key, result_type: UInt64, source_id: 3
|
||||
ORDER BY
|
||||
LIST id: 5, nodes: 2
|
||||
SORT id: 6, sort_direction: ASCENDING, with_fill: 0
|
||||
EXPRESSION
|
||||
FUNCTION id: 7, function_name: avg, function_type: aggregate, result_type: Float64
|
||||
ARGUMENTS
|
||||
LIST id: 8, nodes: 1
|
||||
COLUMN id: 9, column_name: a, result_type: UInt8, source_id: 3
|
||||
SORT id: 10, sort_direction: ASCENDING, with_fill: 0
|
||||
EXPRESSION
|
||||
COLUMN id: 2, column_name: key, result_type: UInt64, source_id: 3
|
||||
[0,1,2]
|
||||
[0,1,2]
|
||||
[0,1,2]
|
||||
|
@ -29,6 +29,7 @@ EXPLAIN SYNTAX SELECT key, a FROM test ORDER BY key, a, exp(key + a);
|
||||
EXPLAIN QUERY TREE run_passes=1 SELECT key, a FROM test ORDER BY key, a, exp(key + a);
|
||||
EXPLAIN SYNTAX SELECT key, a FROM test ORDER BY key, exp(key + a);
|
||||
EXPLAIN QUERY TREE run_passes=1 SELECT key, a FROM test ORDER BY key, exp(key + a);
|
||||
EXPLAIN QUERY TREE run_passes=1 SELECT key FROM test GROUP BY key ORDER BY avg(a), key;
|
||||
|
||||
set optimize_redundant_functions_in_order_by = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user