mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Merge 10.2 into bb-10.2-ext
This commit is contained in:
@@ -2951,6 +2951,112 @@ limit 1
|
||||
ERROR HY000: Unacceptable mutual recursion with anchored table 'cte_1'
|
||||
drop table t1;
|
||||
#
|
||||
# mdev-14777: crash caused by the same as in mdev-14755
|
||||
#
|
||||
CREATE TABLE t1 (i1 int NOT NULL, i2 int);
|
||||
CREATE TABLE t2 (d1 int NOT NULL PRIMARY KEY);
|
||||
CREATE TABLE t3 (i int );
|
||||
insert into t1 select seq,seq from seq_1_to_100000;
|
||||
insert into t2 select seq from seq_1000_to_100000;
|
||||
insert into t3 select seq from seq_1_to_1000;
|
||||
SELECT *
|
||||
FROM
|
||||
(
|
||||
SELECT *
|
||||
FROM
|
||||
(
|
||||
WITH RECURSIVE rt AS
|
||||
(
|
||||
SELECT i2 P, i1 C FROM t1 WHERE i1 IN (SELECT d1 FROM t2)
|
||||
UNION
|
||||
SELECT t1.i2 P, rt.C C FROM t1, rt
|
||||
)
|
||||
SELECT C,P
|
||||
FROM ( SELECT P,C FROM rt WHERE NOT EXISTS (SELECT 1 FROM t1) ) Y
|
||||
) X
|
||||
WHERE 1 = 1
|
||||
) K, t3;
|
||||
C P i
|
||||
drop table t1,t2,t3;
|
||||
#
|
||||
# mdev-14879: subquery with recursive reference in WHERE of CTE
|
||||
#
|
||||
create table flights
|
||||
(departure varchar(32),
|
||||
arrival varchar(32),
|
||||
carrier varchar(20),
|
||||
flight_number char(7));
|
||||
insert into flights values
|
||||
('Seattle', 'Frankfurt', 'Lufthansa', 'LH 491'),
|
||||
('Seattle', 'Chicago', 'American', 'AA 2573'),
|
||||
('Seattle', 'Los Angeles', 'Alaska Air', 'AS 410'),
|
||||
('Chicago', 'New York', 'American', 'AA 375'),
|
||||
('Chicago', 'Montreal', 'Air Canada', 'AC 3053'),
|
||||
('Los Angeles', 'New York', 'Delta', 'DL 1197'),
|
||||
('Moscow', 'Tokyo', 'Aeroflot', 'SU 264'),
|
||||
('New York', 'Paris', 'Air France', 'AF 23'),
|
||||
('Frankfurt', 'Moscow', 'Lufthansa', 'LH 1444'),
|
||||
('Tokyo', 'Seattle', 'ANA', 'NH 178'),
|
||||
('Los Angeles', 'Tokyo', 'ANA', 'NH 175'),
|
||||
('Moscow', 'Los Angeles', 'Aeroflot', 'SU 106'),
|
||||
('Montreal', 'Paris', 'Air Canada', 'AC 870'),
|
||||
('Cairo', 'Paris', 'Air France', 'AF 503'),
|
||||
('New York', 'Seattle', 'American', 'AA 45'),
|
||||
('Paris', 'Chicago', 'Air France', 'AF 6734');
|
||||
with recursive destinations (city) as
|
||||
( select a.arrival from flights a where a.departure='Cairo'
|
||||
union
|
||||
select b.arrival from destinations r, flights b where r.city=b.departure)
|
||||
select * from destinations;
|
||||
city
|
||||
Paris
|
||||
Chicago
|
||||
New York
|
||||
Montreal
|
||||
Seattle
|
||||
Frankfurt
|
||||
Los Angeles
|
||||
Moscow
|
||||
Tokyo
|
||||
set standard_compliant_cte=0;
|
||||
with recursive destinations (city, legs) as
|
||||
(
|
||||
select a.arrival, 1 from flights a where a.departure='Cairo'
|
||||
union
|
||||
select b.arrival, r.legs + 1 from destinations r, flights b
|
||||
where r.city=b.departure and b.arrival not in (select city from destinations)
|
||||
)
|
||||
select * from destinations;
|
||||
city legs
|
||||
Paris 1
|
||||
Chicago 2
|
||||
New York 3
|
||||
Montreal 3
|
||||
Seattle 4
|
||||
Frankfurt 5
|
||||
Los Angeles 5
|
||||
Moscow 6
|
||||
Tokyo 6
|
||||
explain extended with recursive destinations (city, legs) as
|
||||
(
|
||||
select a.arrival, 1 from flights a where a.departure='Cairo'
|
||||
union
|
||||
select b.arrival, r.legs + 1 from destinations r, flights b
|
||||
where r.city=b.departure and b.arrival not in (select city from destinations)
|
||||
)
|
||||
select * from destinations;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 16 100.00
|
||||
2 DERIVED a ALL NULL NULL NULL NULL 16 100.00 Using where
|
||||
3 RECURSIVE UNION b ALL NULL NULL NULL NULL 16 100.00 Using where
|
||||
3 RECURSIVE UNION <derived2> ref key0 key0 35 test.b.departure 2 100.00
|
||||
4 DEPENDENT SUBQUERY <derived2> ALL NULL NULL NULL NULL 16 100.00 Using where
|
||||
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 with recursive destinations as (/* select#2 */ select `test`.`a`.`arrival` AS `city`,1 AS `legs` from `test`.`flights` `a` where `test`.`a`.`departure` = 'Cairo' union /* select#3 */ select `test`.`b`.`arrival` AS `arrival`,`r`.`legs` + 1 AS `r.legs + 1` from `destinations` `r` join `test`.`flights` `b` where `r`.`city` = `test`.`b`.`departure` and !<in_optimizer>(`test`.`b`.`arrival`,<exists>(/* select#4 */ select `destinations`.`city` from `destinations` where trigcond(`test`.`b`.`arrival` = `destinations`.`city` or `destinations`.`city` is null) having trigcond(`destinations`.`city` is null))))/* select#1 */ select `destinations`.`city` AS `city`,`destinations`.`legs` AS `legs` from `destinations`
|
||||
set standard_compliant_cte=default;
|
||||
drop table flights;
|
||||
#
|
||||
# MDEV-14217 [db crash] Recursive CTE when SELECT includes new field
|
||||
#
|
||||
CREATE TEMPORARY TABLE a_tbl (
|
||||
|
||||
Reference in New Issue
Block a user