You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ revised - the original version of these two patches were rolled back
due to excessive space usage for mtr: caused OOM killer ]
In this patch, we flatten equal set operations at the parsing level,
before contextualization, to avoid deep ASTs if possible[1].
Contextualization of equal set operations (with the exception of
INTERSECT ALL which due to its implementation method can't have more
than one right side operand), now happens on a shallow AST: a large
number of e.g. UNION have a parse tree looking like
PT_union
/ \ .....\
/ \ \
query-1 query-2 query-N
leading directly to Query_term_set_op structure
Query_term_union
|
-----------
| | ... |
1 2 N
[1]
It works on left deep structures, e.g.
(a UNION b) union c # type a
or
a UNION b UNION c # type b
but not on
a UNION (b UNION c) # type c
The latter type c will still be represented as a deep AST and eat
stack during contextualization, but be flattened eventually in
merge_descendants.
Luckily, the left deep form of type b is the common one for very long
set operations.
We try 100000 operands as in the test report successfully without
running out of space (~6.4Gb virtual space usage on Ubuntu, single
thread)
Change-Id: I15c1ecb42fdd9449e6d2b42827439363776f82b1
Copy file name to clipboardExpand all lines: mysql-test/r/parser.result
+36
Original file line number
Diff line number
Diff line change
@@ -2627,6 +2627,14 @@ SELECT 1 UNION SELECT 1 FROM DUAL INTO @var;
2627
2627
(SELECT 1 UNION SELECT 1 FROM DUAL INTO @var);
2628
2628
SELECT 1 UNION SELECT 1 FROM DUAL FOR UPDATE INTO @var;
2629
2629
(SELECT 1 UNION SELECT 1 FROM DUAL FOR UPDATE INTO @var);
2630
+
# Check that this also works with flatten_equal_set_ops
2631
+
# (minimum three operands to check this)
2632
+
SELECT 1 UNION SELECT 1 UNION SELECT 1 INTO @var;
2633
+
(SELECT 1 UNION SELECT 1 UNION SELECT 1 INTO @var);
2634
+
SELECT 1 UNION SELECT 1 UNION SELECT 1 FROM DUAL INTO @var;
2635
+
(SELECT 1 UNION SELECT 1 UNION SELECT 1 FROM DUAL INTO @var);
2636
+
SELECT 1 UNION SELECT 1 UNION SELECT 1 FROM DUAL FOR UPDATE INTO @var;
2637
+
(SELECT 1 UNION SELECT 1 UNION SELECT 1 FROM DUAL FOR UPDATE INTO @var);
2630
2638
#
2631
2639
# Deprecation warning expected:
2632
2640
#
@@ -2648,6 +2656,34 @@ Warning 3962 The INTO clause is deprecated inside query blocks of query expressi
2648
2656
(SELECT 1 UNION SELECT 1 INTO @var FOR UPDATE);
2649
2657
Warnings:
2650
2658
Warning 3962 The INTO clause is deprecated inside query blocks of query expressions and will be removed in a future release. Please move the INTO clause to the end of statement instead.
2659
+
# Check that warning also works with flatten_equal_set_ops
2660
+
# (minimum three operands to check this)
2661
+
SELECT 1 UNION SELECT 1 UNION SELECT 1 INTO @var FROM DUAL;
2662
+
Warnings:
2663
+
Warning 3962 The INTO clause is deprecated inside query blocks of query expressions and will be removed in a future release. Please move the INTO clause to the end of statement instead.
2664
+
SELECT 1 UNION SELECT 1 UNION (SELECT 1 INTO @var FROM DUAL);
2665
+
Warnings:
2666
+
Warning 3962 The INTO clause is deprecated inside query blocks of query expressions and will be removed in a future release. Please move the INTO clause to the end of statement instead.
2667
+
SELECT 1 UNION SELECT 1 UNION SELECT 1 FROM DUAL INTO @var FOR UPDATE;
2668
+
Warnings:
2669
+
Warning 3962 The INTO clause is deprecated inside query blocks of query expressions and will be removed in a future release. Please move the INTO clause to the end of statement instead.
2670
+
(SELECT 1 UNION SELECT 1 UNION SELECT 1 FROM DUAL INTO @var FOR UPDATE);
2671
+
Warnings:
2672
+
Warning 3962 The INTO clause is deprecated inside query blocks of query expressions and will be removed in a future release. Please move the INTO clause to the end of statement instead.
2673
+
SELECT 1 UNION SELECT 1 UNION SELECT 1 INTO @var FOR UPDATE;
2674
+
Warnings:
2675
+
Warning 3962 The INTO clause is deprecated inside query blocks of query expressions and will be removed in a future release. Please move the INTO clause to the end of statement instead.
2676
+
(SELECT 1 UNION SELECT 1 UNION SELECT 1 INTO @var FOR UPDATE);
2677
+
Warnings:
2678
+
Warning 3962 The INTO clause is deprecated inside query blocks of query expressions and will be removed in a future release. Please move the INTO clause to the end of statement instead.
2679
+
# Check that PT_set_operation::has_into_clause works correctly
2680
+
# for more than two operands after flatten_equal_set_ops
2681
+
SELECT 1 UNION (SELECT 1 INTO @var FROM DUAL) UNION SELECT 1;
2682
+
ERROR HY000: Misplaced INTO clause, INTO is not allowed inside subqueries, and must be placed at end of UNION clauses.
2683
+
SELECT 1 UNION SELECT 1 UNION SELECT * FROM (SELECT 2 UNION SELECT 1 INTO @var FROM DUAL) t;
2684
+
ERROR HY000: Misplaced INTO clause, INTO is not allowed inside subqueries, and must be placed at end of UNION clauses.
2685
+
SELECT 1 UNION SELECT 1 UNION SELECT * FROM (SELECT 1 UNION SELECT 1 UNION SELECT 1 INTO @var FROM DUAL) t;
2686
+
ERROR HY000: Misplaced INTO clause, INTO is not allowed inside subqueries, and must be placed at end of UNION clauses.
0 commit comments