Skip to content

Commit 31b9dce

Browse files
committed
Revert "Bug#36652610 UNIONs are O(N^2) [1/2 noclose]"
Approved by Bjørn Munch <bjorn.munch@oracle.com>
1 parent 4fce87c commit 31b9dce

File tree

3 files changed

+7
-30
lines changed

3 files changed

+7
-30
lines changed

include/mem_root_deque.h

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ class mem_root_deque {
152152
: m_blocks(other.m_blocks),
153153
m_begin_idx(other.m_begin_idx),
154154
m_end_idx(other.m_end_idx),
155-
m_capacity(other.m_capacity),
156155
m_root(other.m_root) {
157156
other.m_blocks = nullptr;
158157
other.m_begin_idx = other.m_end_idx = other.m_capacity = 0;

sql/parse_tree_nodes.cc

+7-28
Original file line numberDiff line numberDiff line change
@@ -1491,30 +1491,6 @@ static Surrounding_context qt2sc(Query_term_type qtt) {
14911491
return SC_TOP;
14921492
}
14931493

1494-
/// Append the children of 'lower' to those of 'setop'. To avoid excessive
1495-
/// space usage of a large number of similar set ops: instead of the "obvious"
1496-
/// method of copying the operands of the child's array to the parent's array,
1497-
/// we may use the (possibly much) larger lower setop's child array as a basis,
1498-
/// inserting setop's childen at the front and then std::move'ing that (now
1499-
/// discarded) array to be setop's child array. This makes the space
1500-
/// allocation ~= linear instead of O(N*N/2) in the worst case (N: # of set
1501-
/// operations).
1502-
void PT_set_operation::merge_children(Query_term_set_op *setop,
1503-
Query_term_set_op *lower) {
1504-
if (lower->m_children.size() <= setop->m_children.size()) {
1505-
for (auto child : lower->m_children) {
1506-
setop->m_children.push_back(child);
1507-
}
1508-
} else {
1509-
const size_t lim = setop->m_children.size() - 1;
1510-
for (size_t i = 0; i < setop->m_children.size(); ++i) {
1511-
lower->m_children.push_front(setop->m_children[lim - i]);
1512-
}
1513-
setop->m_children = std::move(lower->m_children);
1514-
// lower->m_children is now empty.
1515-
}
1516-
}
1517-
15181494
/**
15191495
Possibly merge lower syntactic levels of set operations (UNION, INTERSECT and
15201496
EXCEPT) into setop, and set new last DISTINCT index for setop. We only ever
@@ -1677,7 +1653,8 @@ void PT_set_operation::merge_descendants(Parse_context *pc,
16771653
// distinct
16781654
last_distinct = count + lower->m_children.size() - 1;
16791655
count = count + lower->m_children.size();
1680-
merge_children(setop, lower);
1656+
// fold in children
1657+
for (auto child : lower->m_children) setop->m_children.push_back(child);
16811658
} else {
16821659
// similar kind of set operation, but contains limit, so do not merge
16831660
count++;
@@ -1716,7 +1693,8 @@ void PT_set_operation::merge_descendants(Parse_context *pc,
17161693
}
17171694
last_distinct = count + lower->m_last_distinct;
17181695
count = count + lower->m_children.size();
1719-
merge_children(setop, lower);
1696+
for (auto child : lower->m_children)
1697+
setop->m_children.push_back(child);
17201698
}
17211699
} else {
17221700
// upper and lower level are both ALL, so ok to merge, unless we have
@@ -1727,7 +1705,8 @@ void PT_set_operation::merge_descendants(Parse_context *pc,
17271705
first_distinct = count + lower->m_first_distinct;
17281706
}
17291707
count = count + lower->m_children.size();
1730-
merge_children(setop, lower);
1708+
for (auto child : lower->m_children)
1709+
setop->m_children.push_back(child);
17311710
} else {
17321711
// do not merge INTERSECT ALL: the execution time logic can only
17331712
// handle binary INTERSECT ALL.
@@ -1746,7 +1725,7 @@ void PT_set_operation::merge_descendants(Parse_context *pc,
17461725
first_distinct = count + lower->m_first_distinct;
17471726
}
17481727
count = count + lower->m_children.size();
1749-
merge_children(setop, lower);
1728+
for (auto child : lower->m_children) setop->m_children.push_back(child);
17501729
} else {
17511730
// do not merge
17521731
count++;

sql/parse_tree_nodes.h

-1
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,6 @@ class PT_set_operation : public PT_query_expression_body {
18221822
protected:
18231823
bool contextualize_setop(Parse_context *pc, Query_term_type setop_type,
18241824
Surrounding_context context);
1825-
void merge_children(Query_term_set_op *setop, Query_term_set_op *lower);
18261825
PT_query_expression_body *m_lhs;
18271826
bool m_is_distinct;
18281827
PT_query_expression_body *m_rhs;

0 commit comments

Comments
 (0)