Skip to content

Commit d71a885

Browse files
committed
Merge 10.2 to 10.3
Temporarily disable main.cte_recursive due to hang in an added test related to MDEV-15575.
2 parents 419385d + 66c14d3 commit d71a885

File tree

18 files changed

+633
-186
lines changed

18 files changed

+633
-186
lines changed

mysql-test/main/cte_recursive.result

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,6 +3070,142 @@ SELECT * FROM cte;
30703070
2
30713071
3
30723072
#
3073+
# MDEV-15575: using recursive cte with big_tables enabled
3074+
#
3075+
set big_tables=1;
3076+
with recursive qn as
3077+
(select 123 as a union all select 1+a from qn where a<130)
3078+
select * from qn;
3079+
a
3080+
123
3081+
124
3082+
125
3083+
126
3084+
127
3085+
128
3086+
129
3087+
130
3088+
set big_tables=default;
3089+
#
3090+
# MDEV-15571: using recursive cte with big_tables enabled
3091+
#
3092+
set big_tables=1;
3093+
with recursive qn as
3094+
(
3095+
select 1 as a from dual
3096+
union all
3097+
select a*2000 from qn where a<10000000000000000000
3098+
)
3099+
select * from qn;
3100+
ERROR 22003: BIGINT value is out of range in '`qn`.`a` * 2000'
3101+
set big_tables=default;
3102+
#
3103+
# MDEV-15556: using recursive cte with big_tables enabled
3104+
# when recursive tables are accessed by key
3105+
#
3106+
SET big_tables=1;
3107+
CREATE TABLE t1 (id int, name char(10), leftpar int, rightpar int);
3108+
INSERT INTO t1 VALUES
3109+
(1, "A", 2, 3), (2, "LA", 4, 5), (4, "LLA", 6, 7),
3110+
(6, "LLLA", NULL, NULL), (7, "RLLA", NULL, NULL), (5, "RLA", 8, 9),
3111+
(8, "LRLA", NULL, NULL), (9, "RRLA", NULL, NULL), (3, "RA", 10, 11),
3112+
(10, "LRA", 12, 13), (11, "RRA", 14, 15), (15, "RRRA", NULL, NULL),
3113+
(16, "B", 17, 18), (17, "LB", NULL, NULL), (18, "RB", NULL, NULL);
3114+
CREATE TABLE t2 SELECT * FROM t1 ORDER BY rand();
3115+
WITH RECURSIVE tree_of_a AS
3116+
(SELECT *, cast(id AS char(200)) AS path FROM t2 WHERE name="A"
3117+
UNION ALL
3118+
SELECT t2.*, concat(tree_of_a.path,",",t2.id)
3119+
FROM t2 JOIN tree_of_a ON t2.id=tree_of_a.leftpar
3120+
UNION ALL
3121+
SELECT t2.*, concat(tree_of_a.path,",",t2.id)
3122+
FROM t2 JOIN tree_of_a ON t2.id=tree_of_a.rightpar)
3123+
SELECT * FROM tree_of_a
3124+
ORDER BY path;
3125+
id name leftpar rightpar path
3126+
1 A 2 3 1
3127+
2 LA 4 5 1,2
3128+
4 LLA 6 7 1,2,4
3129+
6 LLLA NULL NULL 1,2,4,6
3130+
7 RLLA NULL NULL 1,2,4,7
3131+
5 RLA 8 9 1,2,5
3132+
8 LRLA NULL NULL 1,2,5,8
3133+
9 RRLA NULL NULL 1,2,5,9
3134+
3 RA 10 11 1,3
3135+
10 LRA 12 13 1,3,10
3136+
11 RRA 14 15 1,3,11
3137+
15 RRRA NULL NULL 1,3,11,15
3138+
EXPLAIN WITH RECURSIVE tree_of_a AS
3139+
(SELECT *, cast(id AS char(200)) AS path FROM t2 WHERE name="A"
3140+
UNION ALL
3141+
SELECT t2.*, concat(tree_of_a.path,",",t2.id)
3142+
FROM t2 JOIN tree_of_a ON t2.id=tree_of_a.leftpar
3143+
UNION ALL
3144+
SELECT t2.*, concat(tree_of_a.path,",",t2.id)
3145+
FROM t2 JOIN tree_of_a ON t2.id=tree_of_a.rightpar)
3146+
SELECT * FROM tree_of_a
3147+
ORDER BY path;
3148+
id select_type table type possible_keys key key_len ref rows Extra
3149+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 15 Using filesort
3150+
2 DERIVED t2 ALL NULL NULL NULL NULL 15 Using where
3151+
3 RECURSIVE UNION t2 ALL NULL NULL NULL NULL 15 Using where
3152+
3 RECURSIVE UNION <derived2> ref key0 key0 5 test.t2.id 2
3153+
4 RECURSIVE UNION t2 ALL NULL NULL NULL NULL 15 Using where
3154+
4 RECURSIVE UNION <derived2> ref key0 key0 5 test.t2.id 2
3155+
NULL UNION RESULT <union2,3,4> ALL NULL NULL NULL NULL NULL
3156+
DROP TABLE t1,t2;
3157+
SET big_tables=0;
3158+
#
3159+
# MDEV-15840: recursive tables are accessed by key
3160+
# (the same problem as for MDEV-15556)
3161+
#
3162+
CREATE TABLE t1 (p1 text,k2 int, p2 text, k1 int);
3163+
INSERT INTO t1 select seq, seq, seq, seq from seq_1_to_1000;
3164+
CREATE PROCEDURE getNums()
3165+
BEGIN
3166+
WITH RECURSIVE cte as
3167+
(
3168+
SELECT * FROM t1
3169+
UNION
3170+
SELECT c.* FROM t1 c JOIN cte p ON c.p1 = p.p2 AND c.k2 = p.k1
3171+
)
3172+
SELECT * FROM cte LIMIT 10;
3173+
END |
3174+
call getNums();
3175+
p1 k2 p2 k1
3176+
1 1 1 1
3177+
2 2 2 2
3178+
3 3 3 3
3179+
4 4 4 4
3180+
5 5 5 5
3181+
6 6 6 6
3182+
7 7 7 7
3183+
8 8 8 8
3184+
9 9 9 9
3185+
10 10 10 10
3186+
DROP PROCEDURE getNums;
3187+
DROP TABLE t1;
3188+
#
3189+
# MDEV-15894: aggregate/winfow functions in non-recorsive part
3190+
#
3191+
create table t1(b int);
3192+
insert into t1 values(10),(20),(10);
3193+
with recursive qn as
3194+
(select max(b) as a from t1 union
3195+
select a from qn)
3196+
select * from qn;
3197+
a
3198+
20
3199+
with recursive qn as
3200+
(select rank() over (order by b) as a from t1 union
3201+
select a from qn)
3202+
select * from qn;
3203+
a
3204+
1
3205+
3
3206+
drop table t1;
3207+
# Start of 10.3 tests
3208+
#
30733209
# MDEV-14217 [db crash] Recursive CTE when SELECT includes new field
30743210
#
30753211
CREATE TEMPORARY TABLE a_tbl (

mysql-test/main/cte_recursive.test

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,119 @@ WITH RECURSIVE cte AS
20982098
SELECT @c:=@c+1 FROM cte WHERE @c<3)
20992099
SELECT * FROM cte;
21002100

2101+
--echo #
2102+
--echo # MDEV-15575: using recursive cte with big_tables enabled
2103+
--echo #
2104+
2105+
set big_tables=1;
2106+
2107+
with recursive qn as
2108+
(select 123 as a union all select 1+a from qn where a<130)
2109+
select * from qn;
2110+
2111+
set big_tables=default;
2112+
2113+
--echo #
2114+
--echo # MDEV-15571: using recursive cte with big_tables enabled
2115+
--echo #
2116+
2117+
set big_tables=1;
2118+
2119+
--error ER_DATA_OUT_OF_RANGE
2120+
with recursive qn as
2121+
(
2122+
select 1 as a from dual
2123+
union all
2124+
select a*2000 from qn where a<10000000000000000000
2125+
)
2126+
select * from qn;
2127+
2128+
set big_tables=default;
2129+
2130+
--echo #
2131+
--echo # MDEV-15556: using recursive cte with big_tables enabled
2132+
--echo # when recursive tables are accessed by key
2133+
--echo #
2134+
2135+
SET big_tables=1;
2136+
2137+
CREATE TABLE t1 (id int, name char(10), leftpar int, rightpar int);
2138+
INSERT INTO t1 VALUES
2139+
(1, "A", 2, 3), (2, "LA", 4, 5), (4, "LLA", 6, 7),
2140+
(6, "LLLA", NULL, NULL), (7, "RLLA", NULL, NULL), (5, "RLA", 8, 9),
2141+
(8, "LRLA", NULL, NULL), (9, "RRLA", NULL, NULL), (3, "RA", 10, 11),
2142+
(10, "LRA", 12, 13), (11, "RRA", 14, 15), (15, "RRRA", NULL, NULL),
2143+
(16, "B", 17, 18), (17, "LB", NULL, NULL), (18, "RB", NULL, NULL);
2144+
2145+
CREATE TABLE t2 SELECT * FROM t1 ORDER BY rand();
2146+
2147+
let $q=
2148+
WITH RECURSIVE tree_of_a AS
2149+
(SELECT *, cast(id AS char(200)) AS path FROM t2 WHERE name="A"
2150+
UNION ALL
2151+
SELECT t2.*, concat(tree_of_a.path,",",t2.id)
2152+
FROM t2 JOIN tree_of_a ON t2.id=tree_of_a.leftpar
2153+
UNION ALL
2154+
SELECT t2.*, concat(tree_of_a.path,",",t2.id)
2155+
FROM t2 JOIN tree_of_a ON t2.id=tree_of_a.rightpar)
2156+
SELECT * FROM tree_of_a
2157+
ORDER BY path;
2158+
2159+
eval $q;
2160+
eval EXPLAIN $q;
2161+
2162+
DROP TABLE t1,t2;
2163+
2164+
SET big_tables=0;
2165+
2166+
--echo #
2167+
--echo # MDEV-15840: recursive tables are accessed by key
2168+
--echo # (the same problem as for MDEV-15556)
2169+
--echo #
2170+
2171+
--source include/have_sequence.inc
2172+
2173+
CREATE TABLE t1 (p1 text,k2 int, p2 text, k1 int);
2174+
INSERT INTO t1 select seq, seq, seq, seq from seq_1_to_1000;
2175+
2176+
DELIMITER |;
2177+
CREATE PROCEDURE getNums()
2178+
BEGIN
2179+
WITH RECURSIVE cte as
2180+
(
2181+
SELECT * FROM t1
2182+
UNION
2183+
SELECT c.* FROM t1 c JOIN cte p ON c.p1 = p.p2 AND c.k2 = p.k1
2184+
)
2185+
SELECT * FROM cte LIMIT 10;
2186+
END |
2187+
2188+
DELIMITER ;|
2189+
call getNums();
2190+
2191+
DROP PROCEDURE getNums;
2192+
DROP TABLE t1;
2193+
2194+
--echo #
2195+
--echo # MDEV-15894: aggregate/winfow functions in non-recorsive part
2196+
--echo #
2197+
2198+
create table t1(b int);
2199+
insert into t1 values(10),(20),(10);
2200+
2201+
with recursive qn as
2202+
(select max(b) as a from t1 union
2203+
select a from qn)
2204+
select * from qn;
2205+
2206+
with recursive qn as
2207+
(select rank() over (order by b) as a from t1 union
2208+
select a from qn)
2209+
select * from qn;
2210+
2211+
drop table t1;
2212+
2213+
--echo # Start of 10.3 tests
21012214

21022215
--echo #
21032216
--echo # MDEV-14217 [db crash] Recursive CTE when SELECT includes new field

mysql-test/main/disabled.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ innodb-wl5522-debug-zip : broken upstream
2121
innodb_bug12902967 : broken upstream
2222
file_contents : MDEV-6526 these files are not installed anymore
2323
max_statement_time : cannot possibly work, depends on timing
24+
cte_recursive : Merge problem (MDEV-15575)

0 commit comments

Comments
 (0)