Skip to content

Commit befb0be

Browse files
committed
Merge 10.2 into 10.3
2 parents a9bee98 + f458b40 commit befb0be

File tree

7 files changed

+252
-17
lines changed

7 files changed

+252
-17
lines changed

mysql-test/main/cte_recursive.result

Lines changed: 163 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -691,13 +691,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
691691
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
692692
1 PRIMARY <derived3> ref key0 key0 5 c.h_id 2 100.00
693693
1 PRIMARY <derived3> ref key0 key0 5 c.w_id 2 100.00
694-
2 DERIVED <derived3> ALL NULL NULL NULL NULL 12 100.00 Using where
695694
3 DERIVED folks ALL NULL NULL NULL NULL 12 100.00 Using where
696695
4 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00
697696
4 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
698697
5 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00
699698
5 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
700699
NULL UNION RESULT <union3,4,5> ALL NULL NULL NULL NULL NULL NULL
700+
2 DERIVED <derived3> ALL NULL NULL NULL NULL 12 100.00 Using where
701701
Warnings:
702702
Note 1003 with recursive ancestor_couple_ids(h_id,w_id) as (/* select#2 */ select `a`.`father` AS `h_id`,`a`.`mother` AS `w_id` from `coupled_ancestors` `a` where `a`.`father` is not null and `a`.`mother` is not null), coupled_ancestors(id,name,dob,father,mother) as (/* select#3 */ select `test`.`folks`.`id` AS `id`,`test`.`folks`.`name` AS `name`,`test`.`folks`.`dob` AS `dob`,`test`.`folks`.`father` AS `father`,`test`.`folks`.`mother` AS `mother` from `test`.`folks` where `test`.`folks`.`name` = 'Me' union all /* select#4 */ select `test`.`p`.`id` AS `id`,`test`.`p`.`name` AS `name`,`test`.`p`.`dob` AS `dob`,`test`.`p`.`father` AS `father`,`test`.`p`.`mother` AS `mother` from `test`.`folks` `p` join `ancestor_couple_ids` `fa` where `test`.`p`.`id` = `fa`.`h_id` union all /* select#5 */ select `test`.`p`.`id` AS `id`,`test`.`p`.`name` AS `name`,`test`.`p`.`dob` AS `dob`,`test`.`p`.`father` AS `father`,`test`.`p`.`mother` AS `mother` from `test`.`folks` `p` join `ancestor_couple_ids` `ma` where `test`.`p`.`id` = `ma`.`w_id`)/* select#1 */ select `h`.`name` AS `name`,`h`.`dob` AS `dob`,`w`.`name` AS `name`,`w`.`dob` AS `dob` from `ancestor_couple_ids` `c` join `coupled_ancestors` `h` join `coupled_ancestors` `w` where `h`.`id` = `c`.`h_id` and `w`.`id` = `c`.`w_id`
703703
# simple mutual recursion
@@ -1302,12 +1302,12 @@ id select_type table type possible_keys key key_len ref rows Extra
13021302
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 24
13031303
4 DERIVED folks ALL NULL NULL NULL NULL 12 Using where
13041304
6 RECURSIVE UNION <derived3> ALL NULL NULL NULL NULL 12
1305+
5 RECURSIVE UNION <derived4> ALL NULL NULL NULL NULL 24
1306+
NULL UNION RESULT <union4,6,5> ALL NULL NULL NULL NULL NULL
13051307
3 DERIVED folks ALL NULL NULL NULL NULL 12 Using where
13061308
2 RECURSIVE UNION folks ALL PRIMARY NULL NULL NULL 12
13071309
2 RECURSIVE UNION <derived3> ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
13081310
NULL UNION RESULT <union3,2> ALL NULL NULL NULL NULL NULL
1309-
5 RECURSIVE UNION <derived4> ALL NULL NULL NULL NULL 24
1310-
NULL UNION RESULT <union4,6,5> ALL NULL NULL NULL NULL NULL
13111311
explain FORMAT=JSON
13121312
with recursive
13131313
prev_gen
@@ -3370,13 +3370,13 @@ select * from cte1, cte2;
33703370
id select_type table type possible_keys key key_len ref rows filtered Extra
33713371
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 6 100.00
33723372
1 PRIMARY <derived5> ALL NULL NULL NULL NULL 6 100.00 Using join buffer (flat, BNL join)
3373+
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
3374+
3 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
3375+
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
33733376
4 DERIVED <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
33743377
4 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
33753378
5 DERIVED <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
33763379
5 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
3377-
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
3378-
3 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
3379-
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
33803380
Warnings:
33813381
Note 1003 with recursive rcte(a) as (/* select#2 */ select 1 AS `a` union /* select#3 */ select cast(`rcte`.`a` + 1 as unsigned) AS `cast(a+1 as unsigned)` from `rcte` where `rcte`.`a` < 10), cte1 as (/* select#4 */ select count(0) AS `c1` from `rcte` join `test`.`t1` where `rcte`.`a` between 3 and 5 and `test`.`t1`.`id` = `rcte`.`a` - 3), cte2 as (/* select#5 */ select count(0) AS `c2` from `rcte` join `test`.`t1` where `rcte`.`a` between 7 and 8 and `test`.`t1`.`id` = `rcte`.`a` - 7)/* select#1 */ select `cte1`.`c1` AS `c1`,`cte2`.`c2` AS `c2` from `cte1` join `cte2`
33823382
prepare stmt from "with recursive
@@ -3435,6 +3435,65 @@ cte2 as
34353435
(select count(*) as c2 from rcte,t1 where a between 7 and 8 and id=a-7)
34363436
select * from cte1, cte2 where cte1.c1 = 3;
34373437
c1 c2
3438+
with recursive
3439+
rcte(a) as
3440+
(select 1 union select cast(a+1 as unsigned) from rcte where a < 10),
3441+
cte1 as
3442+
(select count(*) as c1 from rcte,t1 where a between 3 and 5 and id=a-3),
3443+
cte2 as
3444+
(select count(*) as c2 from rcte,t1 where a between 7 and 8 and id=a-7)
3445+
select * from cte2, cte1;
3446+
c2 c1
3447+
1 2
3448+
explain extended with recursive
3449+
rcte(a) as
3450+
(select 1 union select cast(a+1 as unsigned) from rcte where a < 10),
3451+
cte1 as
3452+
(select count(*) as c1 from rcte,t1 where a between 3 and 5 and id=a-3),
3453+
cte2 as
3454+
(select count(*) as c2 from rcte,t1 where a between 7 and 8 and id=a-7)
3455+
select * from cte2, cte1;
3456+
id select_type table type possible_keys key key_len ref rows filtered Extra
3457+
1 PRIMARY <derived5> ALL NULL NULL NULL NULL 6 100.00
3458+
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 6 100.00 Using join buffer (flat, BNL join)
3459+
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
3460+
3 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
3461+
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
3462+
5 DERIVED <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
3463+
5 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
3464+
4 DERIVED <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
3465+
4 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
3466+
Warnings:
3467+
Note 1003 with recursive rcte(a) as (/* select#2 */ select 1 AS `a` union /* select#3 */ select cast(`rcte`.`a` + 1 as unsigned) AS `cast(a+1 as unsigned)` from `rcte` where `rcte`.`a` < 10), cte1 as (/* select#4 */ select count(0) AS `c1` from `rcte` join `test`.`t1` where `rcte`.`a` between 3 and 5 and `test`.`t1`.`id` = `rcte`.`a` - 3), cte2 as (/* select#5 */ select count(0) AS `c2` from `rcte` join `test`.`t1` where `rcte`.`a` between 7 and 8 and `test`.`t1`.`id` = `rcte`.`a` - 7)/* select#1 */ select `cte2`.`c2` AS `c2`,`cte1`.`c1` AS `c1` from `cte2` join `cte1`
3468+
prepare stmt from "with recursive
3469+
rcte(a) as
3470+
(select 1 union select cast(a+1 as unsigned) from rcte where a < 10),
3471+
cte1 as
3472+
(select count(*) as c1 from rcte,t1 where a between 3 and 5 and id=a-3),
3473+
cte2 as
3474+
(select count(*) as c2 from rcte,t1 where a between 7 and 8 and id=a-7)
3475+
select * from cte2, cte1";
3476+
execute stmt;
3477+
c2 c1
3478+
1 2
3479+
execute stmt;
3480+
c2 c1
3481+
1 2
3482+
drop procedure p;
3483+
drop table t2;
3484+
create table t2 (c1 int, c2 int);
3485+
create procedure p() insert into t2 with recursive
3486+
rcte(a) as
3487+
(select 1 union select cast(a+1 as unsigned) from rcte where a < 10),
3488+
cte1 as
3489+
(select count(*) as c1 from rcte,t1 where a between 3 and 5 and id=a-3),
3490+
cte2 as
3491+
(select count(*) as c2 from rcte,t1 where a between 7 and 8 and id=a-7)
3492+
select * from cte2, cte1;
3493+
call p();
3494+
select * from t2;
3495+
c1 c2
3496+
1 2
34383497
drop procedure p;
34393498
drop table t1,t2;
34403499
#
@@ -3853,7 +3912,104 @@ ANALYZE
38533912
}
38543913
drop function f1;
38553914
drop table t1,t2;
3856-
End of 10.2 tests
3915+
#
3916+
# MDEV-22748: two materialized CTEs using the same recursive CTE
3917+
# (see also test case for MDEV-17024)
3918+
#
3919+
CREATE TABLE t1 (YEAR int(4), d1 date , d2 date) ;
3920+
INSERT INTO t1 VALUES (2018,'2018-01-01','2018-09-20');
3921+
CREATE TABLE t2 (id int, tm date);
3922+
INSERT INTO t2 VALUES (1,'2018-08-30'),(2,'2018-08-30'),(3,'2018-08-30');
3923+
CREATE TABLE t3 (id int, tm date);
3924+
INSERT INTO t3 VALUES (1,'2018-08-30'),(2,'2018-08-30');
3925+
WITH RECURSIVE
3926+
cte AS
3927+
(SELECT YEAR(t1.d1) AS YEAR, t1.d1 AS st, t1.d1 + INTERVAL 1 MONTH AS fn
3928+
FROM t1
3929+
UNION ALL
3930+
SELECT YEAR(cte.st + INTERVAL 1 MONTH),
3931+
cte.st + INTERVAL 1 MONTH, t1.d2 + INTERVAL 1 DAY
3932+
FROM cte JOIN t1
3933+
WHERE cte.st + INTERVAL 1 MONTH < t1.d2 ),
3934+
cte2 AS (SELECT YEAR, COUNT(*)
3935+
FROM cte JOIN t2 ON t2.tm BETWEEN cte.st AND cte.fn),
3936+
cte3 AS (SELECT YEAR, COUNT(*)
3937+
FROM cte JOIN t3 ON t3.tm BETWEEN cte.st AND cte.fn)
3938+
SELECT t1.* FROM t1 JOIN cte2 USING (YEAR) JOIN cte3 USING (YEAR);
3939+
YEAR d1 d2
3940+
2018 2018-01-01 2018-09-20
3941+
EXPLAIN EXTENDED WITH RECURSIVE
3942+
cte AS
3943+
(SELECT YEAR(t1.d1) AS YEAR, t1.d1 AS st, t1.d1 + INTERVAL 1 MONTH AS fn
3944+
FROM t1
3945+
UNION ALL
3946+
SELECT YEAR(cte.st + INTERVAL 1 MONTH),
3947+
cte.st + INTERVAL 1 MONTH, t1.d2 + INTERVAL 1 DAY
3948+
FROM cte JOIN t1
3949+
WHERE cte.st + INTERVAL 1 MONTH < t1.d2 ),
3950+
cte2 AS (SELECT YEAR, COUNT(*)
3951+
FROM cte JOIN t2 ON t2.tm BETWEEN cte.st AND cte.fn),
3952+
cte3 AS (SELECT YEAR, COUNT(*)
3953+
FROM cte JOIN t3 ON t3.tm BETWEEN cte.st AND cte.fn)
3954+
SELECT t1.* FROM t1 JOIN cte2 USING (YEAR) JOIN cte3 USING (YEAR);
3955+
id select_type table type possible_keys key key_len ref rows filtered Extra
3956+
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
3957+
1 PRIMARY <derived5> ref key0 key0 5 const 0 0.00
3958+
1 PRIMARY <derived4> ref key0 key0 5 const 0 0.00
3959+
2 DERIVED t1 system NULL NULL NULL NULL 1 100.00
3960+
3 RECURSIVE UNION t1 system NULL NULL NULL NULL 1 100.00
3961+
3 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
3962+
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
3963+
4 DERIVED <derived2> ALL NULL NULL NULL NULL 2 100.00
3964+
4 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
3965+
5 DERIVED <derived2> ALL NULL NULL NULL NULL 2 100.00
3966+
5 DERIVED t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
3967+
Warnings:
3968+
Note 1003 with recursive cte as (/* select#2 */ select year(`test`.`t1`.`d1`) AS `YEAR`,`test`.`t1`.`d1` AS `st`,`test`.`t1`.`d1` + interval 1 month AS `fn` from `test`.`t1` union all /* select#3 */ select year(`cte`.`st` + interval 1 month) AS `YEAR(cte.st + INTERVAL 1 MONTH)`,`cte`.`st` + interval 1 month AS `cte.st + INTERVAL 1 MONTH`,`test`.`t1`.`d2` + interval 1 day AS `t1.d2 + INTERVAL 1 DAY` from `cte` join `test`.`t1` where `cte`.`st` + interval 1 month < `test`.`t1`.`d2`), cte2 as (/* select#4 */ select `cte`.`YEAR` AS `YEAR`,count(0) AS `COUNT(*)` from `cte` join `test`.`t2` where `test`.`t2`.`tm` between `cte`.`st` and `cte`.`fn`), cte3 as (/* select#5 */ select `cte`.`YEAR` AS `YEAR`,count(0) AS `COUNT(*)` from `cte` join `test`.`t3` where `test`.`t3`.`tm` between `cte`.`st` and `cte`.`fn`)/* select#1 */ select 2018 AS `YEAR`,'2018-01-01' AS `d1`,'2018-09-20' AS `d2` from `cte2` join `cte3` where `cte3`.`YEAR` = 2018 and `cte2`.`YEAR` = 2018
3969+
PREPARE stmt FROM "WITH RECURSIVE
3970+
cte AS
3971+
(SELECT YEAR(t1.d1) AS YEAR, t1.d1 AS st, t1.d1 + INTERVAL 1 MONTH AS fn
3972+
FROM t1
3973+
UNION ALL
3974+
SELECT YEAR(cte.st + INTERVAL 1 MONTH),
3975+
cte.st + INTERVAL 1 MONTH, t1.d2 + INTERVAL 1 DAY
3976+
FROM cte JOIN t1
3977+
WHERE cte.st + INTERVAL 1 MONTH < t1.d2 ),
3978+
cte2 AS (SELECT YEAR, COUNT(*)
3979+
FROM cte JOIN t2 ON t2.tm BETWEEN cte.st AND cte.fn),
3980+
cte3 AS (SELECT YEAR, COUNT(*)
3981+
FROM cte JOIN t3 ON t3.tm BETWEEN cte.st AND cte.fn)
3982+
SELECT t1.* FROM t1 JOIN cte2 USING (YEAR) JOIN cte3 USING (YEAR)";
3983+
EXECUTE stmt;
3984+
YEAR d1 d2
3985+
2018 2018-01-01 2018-09-20
3986+
EXECUTE stmt;
3987+
YEAR d1 d2
3988+
2018 2018-01-01 2018-09-20
3989+
CREATE TABLE t4 (YEAR int(4), d1 date , d2 date);
3990+
CREATE PROCEDURE p() INSERT INTO t4 WITH RECURSIVE
3991+
cte AS
3992+
(SELECT YEAR(t1.d1) AS YEAR, t1.d1 AS st, t1.d1 + INTERVAL 1 MONTH AS fn
3993+
FROM t1
3994+
UNION ALL
3995+
SELECT YEAR(cte.st + INTERVAL 1 MONTH),
3996+
cte.st + INTERVAL 1 MONTH, t1.d2 + INTERVAL 1 DAY
3997+
FROM cte JOIN t1
3998+
WHERE cte.st + INTERVAL 1 MONTH < t1.d2 ),
3999+
cte2 AS (SELECT YEAR, COUNT(*)
4000+
FROM cte JOIN t2 ON t2.tm BETWEEN cte.st AND cte.fn),
4001+
cte3 AS (SELECT YEAR, COUNT(*)
4002+
FROM cte JOIN t3 ON t3.tm BETWEEN cte.st AND cte.fn)
4003+
SELECT t1.* FROM t1 JOIN cte2 USING (YEAR) JOIN cte3 USING (YEAR);
4004+
CALL p();
4005+
SELECT * FROM t4;
4006+
YEAR d1 d2
4007+
2018 2018-01-01 2018-09-20
4008+
DROP PROCEDURE p;
4009+
DROP TABLE t1,t2,t3,t4;
4010+
#
4011+
# End of 10.2 tests
4012+
#
38574013
#
38584014
# MDEV-14217 [db crash] Recursive CTE when SELECT includes new field
38594015
#

mysql-test/main/cte_recursive.test

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,6 +2424,30 @@ select * from cte1, cte2 where cte1.c1 = 3;
24242424

24252425
eval $q3;
24262426

2427+
let $q4=
2428+
with recursive
2429+
rcte(a) as
2430+
(select 1 union select cast(a+1 as unsigned) from rcte where a < 10),
2431+
cte1 as
2432+
(select count(*) as c1 from rcte,t1 where a between 3 and 5 and id=a-3),
2433+
cte2 as
2434+
(select count(*) as c2 from rcte,t1 where a between 7 and 8 and id=a-7)
2435+
select * from cte2, cte1;
2436+
2437+
eval $q4;
2438+
eval explain extended $q4;
2439+
eval prepare stmt from "$q4";
2440+
execute stmt;
2441+
execute stmt;
2442+
2443+
drop procedure p;
2444+
drop table t2;
2445+
2446+
create table t2 (c1 int, c2 int);
2447+
eval create procedure p() insert into t2 $q4;
2448+
call p();
2449+
select * from t2;
2450+
24272451
drop procedure p;
24282452
drop table t1,t2;
24292453

@@ -2609,7 +2633,51 @@ eval analyze format=json $q;
26092633
drop function f1;
26102634
drop table t1,t2;
26112635

2612-
--echo End of 10.2 tests
2636+
--echo #
2637+
--echo # MDEV-22748: two materialized CTEs using the same recursive CTE
2638+
--echo # (see also test case for MDEV-17024)
2639+
--echo #
2640+
2641+
CREATE TABLE t1 (YEAR int(4), d1 date , d2 date) ;
2642+
INSERT INTO t1 VALUES (2018,'2018-01-01','2018-09-20');
2643+
CREATE TABLE t2 (id int, tm date);
2644+
INSERT INTO t2 VALUES (1,'2018-08-30'),(2,'2018-08-30'),(3,'2018-08-30');
2645+
CREATE TABLE t3 (id int, tm date);
2646+
INSERT INTO t3 VALUES (1,'2018-08-30'),(2,'2018-08-30');
2647+
2648+
let $q=
2649+
WITH RECURSIVE
2650+
cte AS
2651+
(SELECT YEAR(t1.d1) AS YEAR, t1.d1 AS st, t1.d1 + INTERVAL 1 MONTH AS fn
2652+
FROM t1
2653+
UNION ALL
2654+
SELECT YEAR(cte.st + INTERVAL 1 MONTH),
2655+
cte.st + INTERVAL 1 MONTH, t1.d2 + INTERVAL 1 DAY
2656+
FROM cte JOIN t1
2657+
WHERE cte.st + INTERVAL 1 MONTH < t1.d2 ),
2658+
cte2 AS (SELECT YEAR, COUNT(*)
2659+
FROM cte JOIN t2 ON t2.tm BETWEEN cte.st AND cte.fn),
2660+
cte3 AS (SELECT YEAR, COUNT(*)
2661+
FROM cte JOIN t3 ON t3.tm BETWEEN cte.st AND cte.fn)
2662+
SELECT t1.* FROM t1 JOIN cte2 USING (YEAR) JOIN cte3 USING (YEAR);
2663+
2664+
eval $q;
2665+
eval EXPLAIN EXTENDED $q;
2666+
eval PREPARE stmt FROM "$q";
2667+
EXECUTE stmt;
2668+
EXECUTE stmt;
2669+
2670+
CREATE TABLE t4 (YEAR int(4), d1 date , d2 date);
2671+
eval CREATE PROCEDURE p() INSERT INTO t4 $q;
2672+
CALL p();
2673+
SELECT * FROM t4;
2674+
2675+
DROP PROCEDURE p;
2676+
DROP TABLE t1,t2,t3,t4;
2677+
2678+
--echo #
2679+
--echo # End of 10.2 tests
2680+
--echo #
26132681

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

sql/sql_cte.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ bool TABLE_LIST::set_as_with_table(THD *thd, With_element *with_elem)
11141114
{
11151115
derived= with_elem->spec;
11161116
if (derived != select_lex->master_unit() &&
1117+
!with_elem->is_recursive &&
11171118
!is_with_table_recursive_reference())
11181119
{
11191120
derived->move_as_slave(select_lex);

sql/sql_derived.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Copyright (c) 2002, 2011, Oracle and/or its affiliates.
3-
Copyright (c) 2010, 2015, MariaDB
3+
Copyright (c) 2010, 2020, MariaDB
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -1110,7 +1110,6 @@ bool mysql_derived_fill(THD *thd, LEX *lex, TABLE_LIST *derived)
11101110
DBUG_ASSERT(derived->table && derived->table->is_created());
11111111
select_unit *derived_result= derived->derived_result;
11121112
SELECT_LEX *save_current_select= lex->current_select;
1113-
bool derived_recursive_is_filled= false;
11141113

11151114
if (unit->executed && !derived_is_recursive &&
11161115
(unit->uncacheable & UNCACHEABLE_DEPENDENT))
@@ -1139,7 +1138,6 @@ bool mysql_derived_fill(THD *thd, LEX *lex, TABLE_LIST *derived)
11391138
{
11401139
/* In this case all iteration are performed */
11411140
res= derived->fill_recursive(thd);
1142-
derived_recursive_is_filled= true;
11431141
}
11441142
}
11451143
else if (unit->is_unit_op())
@@ -1195,8 +1193,7 @@ bool mysql_derived_fill(THD *thd, LEX *lex, TABLE_LIST *derived)
11951193
}
11961194
}
11971195
err:
1198-
if (res || (!lex->describe && !unit->uncacheable &&
1199-
(!derived_is_recursive || derived_recursive_is_filled)))
1196+
if (res || (!derived_is_recursive && !lex->describe && !unit->uncacheable))
12001197
unit->cleanup();
12011198
lex->current_select= save_current_select;
12021199

sql/sql_union.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,19 @@ bool st_select_lex::cleanup()
20302030
delete join;
20312031
join= 0;
20322032
}
2033+
for (TABLE_LIST *tbl= get_table_list(); tbl; tbl= tbl->next_local)
2034+
{
2035+
if (tbl->is_recursive_with_table() &&
2036+
!tbl->is_with_table_recursive_reference())
2037+
{
2038+
/*
2039+
If query is killed before open_and_process_table() for tbl
2040+
is called then 'with' is already set, but 'derived' is not.
2041+
*/
2042+
st_select_lex_unit *unit= tbl->with->spec;
2043+
error|= (bool) error | (uint) unit->cleanup();
2044+
}
2045+
}
20332046
for (SELECT_LEX_UNIT *lex_unit= first_inner_unit(); lex_unit ;
20342047
lex_unit= lex_unit->next_unit())
20352048
{

storage/innobase/srv/srv0srv.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,7 +2678,7 @@ srv_purge_coordinator_suspend(
26782678

26792679
rw_lock_x_lock(&purge_sys.latch);
26802680

2681-
stop = srv_shutdown_state == SRV_SHUTDOWN_NONE
2681+
stop = srv_shutdown_state <= SRV_SHUTDOWN_INITIATED
26822682
&& purge_sys.paused_latched();
26832683

26842684
if (!stop) {
@@ -2743,7 +2743,7 @@ DECLARE_THREAD(srv_purge_coordinator_thread)(
27432743
/* If there are no records to purge or the last
27442744
purge didn't purge any records then wait for activity. */
27452745

2746-
if (srv_shutdown_state == SRV_SHUTDOWN_NONE
2746+
if (srv_shutdown_state <= SRV_SHUTDOWN_INITIATED
27472747
&& srv_undo_sources
27482748
&& (n_total_purged == 0 || purge_sys.paused())) {
27492749

0 commit comments

Comments
 (0)