MXS-1307 CTE tests pass

There are some issues still
- With recursive CTEs qc_mysqlembedded and qc_sqlite agree upon
  the real columns, but disagree on the CTE related "virtual"
  columns. That's largely irrelevant though.
- qc_sqlite cannot parse "SET STATEMENT var=... FOR stmt",
  but it will be classified as QUERY_TYPE_GSYSVAR_WRITE.
  This is not directly CTE related.
This commit is contained in:
Johan Wikman
2017-08-10 15:03:08 +03:00
parent 4eeff705ee
commit 9d97902899
4 changed files with 264 additions and 160 deletions

View File

@ -410,31 +410,35 @@ select h_name, h_dob, w_name, w_dob
--echo # mutual recursion with union all --echo # mutual recursion with union all
with recursive #MXS qc_mysqlembedded and qc_sqlite disagree in the used fields.
ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, #MXS Both return correctly the folks fields (i.e. the real ones),
w_id, w_name, w_dob, w_father, w_mother) #MXS but disagree on the fields of the CTE tables.
as #
( #MXS with recursive
select h.*, w.* #MXS ancestor_couples(h_id, h_name, h_dob, h_father, h_mother,
from folks h, folks w, coupled_ancestors a #MXS w_id, w_name, w_dob, w_father, w_mother)
where a.father = h.id AND a.mother = w.id #MXS as
union #MXS (
select h.*, w.* #MXS select h.*, w.*
from folks v, folks h, folks w #MXS from folks h, folks w, coupled_ancestors a
where v.name = 'Me' and #MXS where a.father = h.id AND a.mother = w.id
(v.father = h.id AND v.mother= w.id) #MXS union
), #MXS select h.*, w.*
coupled_ancestors (id, name, dob, father, mother) #MXS from folks v, folks h, folks w
as #MXS where v.name = 'Me' and
( #MXS (v.father = h.id AND v.mother= w.id)
select h_id, h_name, h_dob, h_father, h_mother #MXS ),
from ancestor_couples #MXS coupled_ancestors (id, name, dob, father, mother)
union all #MXS as
select w_id, w_name, w_dob, w_father, w_mother #MXS (
from ancestor_couples #MXS select h_id, h_name, h_dob, h_father, h_mother
) #MXS from ancestor_couples
select h_name, h_dob, w_name, w_dob #MXS union all
from ancestor_couples; #MXS select w_id, w_name, w_dob, w_father, w_mother
#MXS from ancestor_couples
#MXS )
#MXS select h_name, h_dob, w_name, w_dob
#MXS from ancestor_couples;
--echo # mutual recursion with renaming --echo # mutual recursion with renaming
@ -466,115 +470,131 @@ select h_name, h_dob, w_name, w_dob
--echo # mutual recursion with union all --echo # mutual recursion with union all
with recursive #MXS qc_mysqlembedded and qc_sqlite disagree in the used fields.
ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, #MXS Both return correctly the folks fields (i.e. the real ones),
w_id, w_name, w_dob, w_father, w_mother) #MXS but disagree on the fields of the CTE tables.
as #
( #MXS with recursive
select h.*, w.* #MXS ancestor_couples(h_id, h_name, h_dob, h_father, h_mother,
from folks h, folks w, coupled_ancestors a #MXS w_id, w_name, w_dob, w_father, w_mother)
where a.father = h.id AND a.mother = w.id #MXS as
), #MXS (
coupled_ancestors (id, name, dob, father, mother) #MXS select h.*, w.*
as #MXS from folks h, folks w, coupled_ancestors a
( #MXS where a.father = h.id AND a.mother = w.id
select * #MXS ),
from folks #MXS coupled_ancestors (id, name, dob, father, mother)
where name = 'Me' #MXS as
union all #MXS (
select h_id, h_name, h_dob, h_father, h_mother #MXS select *
from ancestor_couples #MXS from folks
union all #MXS where name = 'Me'
select w_id, w_name, w_dob, w_father, w_mother #MXS union all
from ancestor_couples #MXS select h_id, h_name, h_dob, h_father, h_mother
) #MXS from ancestor_couples
select h_name, h_dob, w_name, w_dob #MXS union all
from ancestor_couples; #MXS select w_id, w_name, w_dob, w_father, w_mother
#MXS from ancestor_couples
#MXS )
#MXS select h_name, h_dob, w_name, w_dob
#MXS from ancestor_couples;
--echo # mutual recursion with one select in the first definition --echo # mutual recursion with one select in the first definition
with recursive #MXS qc_mysqlembedded and qc_sqlite disagree in the used fields.
ancestor_couple_ids(h_id, w_id) #MXS Both return correctly the folks fields (i.e. the real ones),
as #MXS but disagree on the fields of the CTE tables.
( #
select a.father, a.mother #MXS with recursive
from coupled_ancestors a #MXS ancestor_couple_ids(h_id, w_id)
where a.father is not null and a.mother is not null #MXS as
), #MXS (
coupled_ancestors (id, name, dob, father, mother) #MXS select a.father, a.mother
as #MXS from coupled_ancestors a
( #MXS where a.father is not null and a.mother is not null
select * #MXS ),
from folks #MXS coupled_ancestors (id, name, dob, father, mother)
where name = 'Me' #MXS as
union all #MXS (
select p.* #MXS select *
from folks p, ancestor_couple_ids fa #MXS from folks
where p.id = fa.h_id #MXS where name = 'Me'
union all #MXS union all
select p.* #MXS select p.*
from folks p, ancestor_couple_ids ma #MXS from folks p, ancestor_couple_ids fa
where p.id = ma.w_id #MXS where p.id = fa.h_id
) #MXS union all
select * #MXS select p.*
from ancestor_couple_ids; #MXS from folks p, ancestor_couple_ids ma
#MXS where p.id = ma.w_id
#MXS )
#MXS select *
#MXS from ancestor_couple_ids;
--echo # join of a mutually recursive table with base tables --echo # join of a mutually recursive table with base tables
with recursive #MXS qc_mysqlembedded and qc_sqlite disagree in the used fields.
ancestor_couple_ids(h_id, w_id) #MXS Both return correctly the folks fields (i.e. the real ones),
as #MXS but disagree on the fields of the CTE tables.
( #
select a.father, a.mother #MXS with recursive
from coupled_ancestors a #MXS ancestor_couple_ids(h_id, w_id)
where a.father is not null and a.mother is not null #MXS as
), #MXS (
coupled_ancestors (id, name, dob, father, mother) #MXS select a.father, a.mother
as #MXS from coupled_ancestors a
( #MXS where a.father is not null and a.mother is not null
select * #MXS ),
from folks #MXS coupled_ancestors (id, name, dob, father, mother)
where name = 'Me' #MXS as
union all #MXS (
select p.* #MXS select *
from folks p, ancestor_couple_ids fa #MXS from folks
where p.id = fa.h_id #MXS where name = 'Me'
union all #MXS union all
select p.* #MXS select p.*
from folks p, ancestor_couple_ids ma #MXS from folks p, ancestor_couple_ids fa
where p.id = ma.w_id #MXS where p.id = fa.h_id
) #MXS union all
select h.name, h.dob, w.name, w.dob #MXS select p.*
from ancestor_couple_ids c, folks h, folks w #MXS from folks p, ancestor_couple_ids ma
where c.h_id = h.id and c.w_id= w.id; #MXS where p.id = ma.w_id
#MXS )
#MXS select h.name, h.dob, w.name, w.dob
#MXS from ancestor_couple_ids c, folks h, folks w
#MXS where c.h_id = h.id and c.w_id= w.id;
--echo # join of two mutually recursive tables --echo # join of two mutually recursive tables
with recursive #MXS qc_mysqlembedded and qc_sqlite disagree in the used fields.
ancestor_couple_ids(h_id, w_id) #MXS Both return correctly the folks fields (i.e. the real ones),
as #MXS but disagree on the fields of the CTE tables.
( #
select a.father, a.mother #MXS with recursive
from coupled_ancestors a #MXS ancestor_couple_ids(h_id, w_id)
where a.father is not null and a.mother is not null #MXS as
), #MXS (
coupled_ancestors (id, name, dob, father, mother) #MXS select a.father, a.mother
as #MXS from coupled_ancestors a
( #MXS where a.father is not null and a.mother is not null
select * #MXS ),
from folks #MXS coupled_ancestors (id, name, dob, father, mother)
where name = 'Me' #MXS as
union all #MXS (
select p.* #MXS select *
from folks p, ancestor_couple_ids fa #MXS from folks
where p.id = fa.h_id #MXS where name = 'Me'
union all #MXS union all
select p.* #MXS select p.*
from folks p, ancestor_couple_ids ma #MXS from folks p, ancestor_couple_ids fa
where p.id = ma.w_id #MXS where p.id = fa.h_id
) #MXS union all
select h.name, h.dob, w.name, w.dob #MXS select p.*
from ancestor_couple_ids c, coupled_ancestors h, coupled_ancestors w #MXS from folks p, ancestor_couple_ids ma
where c.h_id = h.id and c.w_id= w.id; #MXS where p.id = ma.w_id
#MXS )
#MXS select h.name, h.dob, w.name, w.dob
#MXS from ancestor_couple_ids c, coupled_ancestors h, coupled_ancestors w
#MXS where c.h_id = h.id and c.w_id= w.id;
explain extended explain extended
with recursive with recursive
@ -869,7 +889,8 @@ as
select p.* from coupled_ancestor_ids a, folks p select p.* from coupled_ancestor_ids a, folks p
where a.id = p.id; where a.id = p.id;
set statement standard_compliant_cte=0 for #MXS qc_sqlite does not handle "SET STATEMENT ... FOR ..."
#MXS set statement standard_compliant_cte=0 for
with recursive with recursive
coupled_ancestor_ids (id) coupled_ancestor_ids (id)
as as
@ -914,7 +935,8 @@ as
) )
select * from ancestors; select * from ancestors;
set statement standard_compliant_cte=0 for #MXS qc_sqlite does not handle "SET STATEMENT ... FOR ..."
#MXS set statement standard_compliant_cte=0 for
with recursive with recursive
ancestor_ids (id) ancestor_ids (id)
as as
@ -982,7 +1004,8 @@ as
) )
select * from ancestors; select * from ancestors;
set statement standard_compliant_cte=0 for #MXS qc_sqlite does not handle "SET STATEMENT ... FOR ..."
#MXS set statement standard_compliant_cte=0 for
with recursive with recursive
ancestor_ids (id, generation) ancestor_ids (id, generation)
as as
@ -1007,7 +1030,8 @@ as
) )
select * from ancestors; select * from ancestors;
set statement max_recursive_iterations=1 for #MXS qc_sqlite does not handle "SET STATEMENT ... FOR ..."
#MXS set statement max_recursive_iterations=1 for
with recursive with recursive
ancestor_ids (id, generation) ancestor_ids (id, generation)
as as
@ -1273,22 +1297,24 @@ drop table my_ancestors;
--echo # CREATE SELECT --echo # CREATE SELECT
--echo # --echo #
create table my_ancestors #MXS qc_sqlite cannot parse this
( #MXS qc_parse : INF: QC_QUERY_PARSED != QC_QUERY_PARTIALLY_PARSED
with recursive #MXS create table my_ancestors
ancestor_ids (id) #MXS (
as #MXS with recursive
( #MXS ancestor_ids (id)
select father from folks where name = 'Me' #MXS as
union #MXS (
select mother from folks where name = 'Me' #MXS select father from folks where name = 'Me'
union #MXS union
select father from folks, ancestor_ids a where folks.id = a.id #MXS select mother from folks where name = 'Me'
union #MXS union
select mother from folks, ancestor_ids a where folks.id = a.id #MXS select father from folks, ancestor_ids a where folks.id = a.id
) #MXS union
select p.* from folks as p, ancestor_ids as a where p.id = a.id #MXS select mother from folks, ancestor_ids a where folks.id = a.id
); #MXS )
#MXS select p.* from folks as p, ancestor_ids as a where p.id = a.id
#MXS );
select * from my_ancestors; select * from my_ancestors;
drop table my_ancestors; drop table my_ancestors;
@ -1368,10 +1394,13 @@ create table t2 (a int);
insert into t2 values insert into t2 values
(1), (2), (3), (4), (5); (1), (2), (3), (4), (5);
create view v1 as #MXS qc_mysqlembedded
select a from t2 where a < 3 #MXS qc_get_function_info : ERR: <(QC_USED_IN_WHERE) != <(QC_USED_IN_WHERE) >(QC_USED_IN_WHERE)
union #
select a from t2 where a > 4; #MXS create view v1 as
#MXS select a from t2 where a < 3
#MXS union
#MXS select a from t2 where a > 4;
with recursive with recursive
t1 as t1 as
@ -1428,7 +1457,7 @@ WITH RECURSIVE transitive_closure(a, b, distance, path_string) AS
( SELECT a, b, 1 AS distance, ( SELECT a, b, 1 AS distance,
concat(a, '.', b, '.') AS path_string concat(a, '.', b, '.') AS path_string
FROM edges FROM edges
WHERE a = 1 -- source WHERE a = 1
UNION ALL UNION ALL
@ -1439,7 +1468,7 @@ WITH RECURSIVE transitive_closure(a, b, distance, path_string) AS
WHERE tc.path_string NOT LIKE concat('%', e.b, '.%') WHERE tc.path_string NOT LIKE concat('%', e.b, '.%')
) )
SELECT * FROM transitive_closure SELECT * FROM transitive_closure
WHERE b = 6 -- destination WHERE b = 6
ORDER BY a, b, distance; ORDER BY a, b, distance;
--sorted_result --sorted_result
@ -1507,12 +1536,15 @@ drop table t1;
--echo # --echo #
--source include/analyze-format.inc --source include/analyze-format.inc
analyze format=json
with recursive src(counter) as #MXS qc_sqlite cannot parse this
(select 1 #MXS qc_parse : INF: QC_QUERY_PARSED != QC_QUERY_INVALID
union #MXS analyze format=json
select counter+1 from src where counter<10 #MXS with recursive src(counter) as
) select * from src; #MXS (select 1
#MXS union
#MXS select counter+1 from src where counter<10
#MXS ) select * from src;
--echo # --echo #
--echo # mdev-12360: recursive reference in left operand of LEFT JOIN --echo # mdev-12360: recursive reference in left operand of LEFT JOIN
@ -1626,7 +1658,8 @@ insert into module_results values
('m6','v12'), ('m6','v4'), ('m6','v12'), ('m6','v4'),
('m7','v2'); ('m7','v2');
set statement max_recursive_iterations=2, standard_compliant_cte=0 for #MXS qc_sqlite does not handle "SET STATEMENT ... FOR ..."
#MXS set statement max_recursive_iterations=2, standard_compliant_cte=0 for
with recursive with recursive
reached_values as reached_values as
( (

View File

@ -523,7 +523,7 @@ insert t1 (data) values ('letter'), (1/0);
--disable_ps_protocol --disable_ps_protocol
update t1 set data='envelope' where 1/0 or 1; update t1 set data='envelope' where 1/0 or 1;
--enable_ps_protocol --enable_ps_protocol
#MXS qc_mysqlem #MXS qc_mysqlembedded does not return all functions
#MXS qc_get_function_info : ERR: != /() #MXS qc_get_function_info : ERR: != /()
#MXS insert t1 (data) values (default), (1/0), ('dead beef'); #MXS insert t1 (data) values (default), (1/0), ('dead beef');
--disable_info --disable_info

View File

@ -8,3 +8,12 @@ insert into t1 values
(if(1, 9223372036854775808, 1)), (if(1, 9223372036854775808, 1)),
(case when 1 then 9223372036854775808 else 1 end), (case when 1 then 9223372036854775808 else 1 end),
(coalesce(9223372036854775808, 1)); (coalesce(9223372036854775808, 1));
#MXS qc_mysqlembedded
#MXS qc_get_function_info : ERR: <(QC_USED_IN_WHERE) != <(QC_USED_IN_WHERE) >(QC_USED_IN_WHERE)
#
create view v1 as
select a from t2 where a < 3
union
select a from t2 where a > 4;

View File

@ -64,3 +64,65 @@ SELECT t.f FROM d.t;
# to do that. # to do that.
select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;
with t as (select c from mysqltest.t2 where c < 2) select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; with t as (select c from mysqltest.t2 where c < 2) select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a;
#MXS qc_mysqlembedded and qc_sqlite disagree in the used fields.
#MXS Both return correctly the folks fields (i.e. the real ones),
#MXS but disagree on the fields of the CTR tables.
#
with recursive
ancestor_couples(h_id, h_name, h_dob, h_father, h_mother,
w_id, w_name, w_dob, w_father, w_mother)
as
(
select h.*, w.*
from folks h, folks w, coupled_ancestors a
where a.father = h.id AND a.mother = w.id
union
select h.*, w.*
from folks v, folks h, folks w
where v.name = 'Me' and
(v.father = h.id AND v.mother= w.id)
),
coupled_ancestors (id, name, dob, father, mother)
as
(
select h_id, h_name, h_dob, h_father, h_mother
from ancestor_couples
union all
select w_id, w_name, w_dob, w_father, w_mother
from ancestor_couples
)
select h_name, h_dob, w_name, w_dob
from ancestor_couples;
#MXS qc_sqlite cannot parse this
#MXS qc_parse : INF: QC_QUERY_PARSED != QC_QUERY_TOKENIZED
set statement standard_compliant_cte=0 for select 1;
#MXS qc_sqlite cannot parse this
#MXS qc_parse : INF: QC_QUERY_PARSED != QC_QUERY_PARTIALLY_PARSED
create table my_ancestors
(
with recursive
ancestor_ids (id)
as
(
select father from folks where name = 'Me'
union
select mother from folks where name = 'Me'
union
select father from folks, ancestor_ids a where folks.id = a.id
union
select mother from folks, ancestor_ids a where folks.id = a.id
)
select p.* from folks as p, ancestor_ids as a where p.id = a.id
);
#MXS qc_sqlite cannot parse this
#MXS qc_parse : INF: QC_QUERY_PARSED != QC_QUERY_INVALID
analyze format=json
with recursive src(counter) as
(select 1
union
select counter+1 from src where counter<10
) select * from src;