mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Backport #64766 to 24.3: Fix OrderByLimitByDuplicateEliminationVisitor across subqueries
This commit is contained in:
parent
55d2592888
commit
a722ad4f5c
@ -22,6 +22,7 @@ public:
|
||||
|
||||
if (query_node->hasOrderBy())
|
||||
{
|
||||
QueryTreeNodeConstRawPtrWithHashSet unique_expressions_nodes_set;
|
||||
QueryTreeNodes result_nodes;
|
||||
|
||||
auto & query_order_by_nodes = query_node->getOrderBy().getNodes();
|
||||
@ -45,10 +46,9 @@ public:
|
||||
query_order_by_nodes = std::move(result_nodes);
|
||||
}
|
||||
|
||||
unique_expressions_nodes_set.clear();
|
||||
|
||||
if (query_node->hasLimitBy())
|
||||
{
|
||||
QueryTreeNodeConstRawPtrWithHashSet unique_expressions_nodes_set;
|
||||
QueryTreeNodes result_nodes;
|
||||
|
||||
auto & query_limit_by_nodes = query_node->getLimitBy().getNodes();
|
||||
@ -63,9 +63,6 @@ public:
|
||||
query_limit_by_nodes = std::move(result_nodes);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QueryTreeNodeConstRawPtrWithHashSet unique_expressions_nodes_set;
|
||||
};
|
||||
|
||||
}
|
||||
|
39
tests/queries/0_stateless/03165_order_by_duplicate.reference
Normal file
39
tests/queries/0_stateless/03165_order_by_duplicate.reference
Normal file
@ -0,0 +1,39 @@
|
||||
QUERY id: 0
|
||||
PROJECTION COLUMNS
|
||||
id UInt64
|
||||
PROJECTION
|
||||
LIST id: 1, nodes: 1
|
||||
COLUMN id: 2, column_name: id, result_type: UInt64, source_id: 3
|
||||
JOIN TREE
|
||||
TABLE id: 3, alias: __table1, table_name: default.test, final: 1
|
||||
WHERE
|
||||
FUNCTION id: 4, function_name: in, function_type: ordinary, result_type: UInt8
|
||||
ARGUMENTS
|
||||
LIST id: 5, nodes: 2
|
||||
COLUMN id: 2, column_name: id, result_type: UInt64, source_id: 3
|
||||
QUERY id: 6, is_subquery: 1, is_distinct: 1
|
||||
PROJECTION COLUMNS
|
||||
id UInt64
|
||||
PROJECTION
|
||||
LIST id: 7, nodes: 1
|
||||
COLUMN id: 8, column_name: id, result_type: UInt64, source_id: 9
|
||||
JOIN TREE
|
||||
TABLE id: 9, alias: __table1, table_name: default.test, final: 1
|
||||
ORDER BY
|
||||
LIST id: 10, nodes: 1
|
||||
SORT id: 11, sort_direction: ASCENDING, with_fill: 0
|
||||
EXPRESSION
|
||||
COLUMN id: 8, column_name: id, result_type: UInt64, source_id: 9
|
||||
LIMIT
|
||||
CONSTANT id: 12, constant_value: UInt64_4, constant_value_type: UInt64
|
||||
ORDER BY
|
||||
LIST id: 13, nodes: 1
|
||||
SORT id: 14, sort_direction: ASCENDING, with_fill: 0
|
||||
EXPRESSION
|
||||
COLUMN id: 2, column_name: id, result_type: UInt64, source_id: 3
|
||||
LIMIT BY LIMIT
|
||||
CONSTANT id: 15, constant_value: UInt64_1, constant_value_type: UInt64
|
||||
LIMIT BY
|
||||
LIST id: 16, nodes: 1
|
||||
COLUMN id: 2, column_name: id, result_type: UInt64, source_id: 3
|
||||
SETTINGS allow_experimental_analyzer=1
|
16
tests/queries/0_stateless/03165_order_by_duplicate.sql
Normal file
16
tests/queries/0_stateless/03165_order_by_duplicate.sql
Normal file
@ -0,0 +1,16 @@
|
||||
CREATE TABLE test
|
||||
ENGINE = ReplacingMergeTree
|
||||
PRIMARY KEY id
|
||||
AS SELECT number AS id FROM numbers(100);
|
||||
|
||||
EXPLAIN QUERY TREE SELECT id
|
||||
FROM test FINAL
|
||||
WHERE id IN (
|
||||
SELECT DISTINCT id
|
||||
FROM test FINAL
|
||||
ORDER BY id ASC
|
||||
LIMIT 4
|
||||
)
|
||||
ORDER BY id ASC
|
||||
LIMIT 1 BY id
|
||||
SETTINGS allow_experimental_analyzer = 1;
|
Loading…
Reference in New Issue
Block a user