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
Temporary tables created for recursive CTE
were instantiated at the prepare phase. As
a result these temporary tables missed
indexes for look-ups and optimizer could not
use them.
3 SUBQUERY folks ALL NULL NULL NULL NULL 12 100.00 Using where
602
-
4 UNCACHEABLE UNION p ALL NULL NULL NULL NULL 12 100.00
603
-
4 UNCACHEABLE UNION <derived2> ALL NULL NULL NULL NULL 36 100.00 Using where; Using join buffer (flat, BNL join)
602
+
4 UNCACHEABLE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00
603
+
4 UNCACHEABLE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
604
604
5 UNCACHEABLE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00
605
605
5 UNCACHEABLE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
606
606
NULL UNION RESULT <union3,4,5> ALL NULL NULL NULL NULL NULL NULL
607
-
2 UNCACHEABLE SUBQUERY <derived3> ALL NULL NULL NULL NULL 36 100.00 Using where
607
+
2 UNCACHEABLE SUBQUERY <derived3> ALL NULL NULL NULL NULL 12 100.00 Using where
608
608
Warnings:
609
-
Note 1003 with recursive ancestor_couple_ids as (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 as (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 `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 (`fa`.`h_id` = `test`.`p`.`id`) union all 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 `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`))
609
+
Note 1003 with recursive ancestor_couple_ids as (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 as (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 `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 `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 `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`))
610
610
with recursive
611
611
ancestor_couple_ids(h_id, w_id)
612
612
as
@@ -779,7 +779,7 @@ where p.id = a.father or p.id = a.mother
779
779
)
780
780
select * from ancestors;
781
781
id select_type table type possible_keys key key_len ref rows filtered Extra
782
-
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 156 100.00
782
+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 100.00
783
783
2 SUBQUERY folks ALL NULL NULL NULL NULL 12 100.00 Using where
784
784
3 UNCACHEABLE UNION p ALL NULL NULL NULL NULL 12 100.00
785
785
3 UNCACHEABLE UNION <derived2> ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
@@ -809,9 +809,9 @@ id name dob father mother
809
809
20 Dad 1970-02-02 10 9
810
810
30 Mom 1975-03-03 8 7
811
811
10 Grandpa Bill 1940-04-05 NULL NULL
812
-
8 Grandpa Ben 1940-10-21 NULL NULL
813
812
9 Grandma Ann 1941-10-15 NULL NULL
814
813
7 Grandma Sally 1943-08-23 NULL 6
814
+
8 Grandpa Ben 1940-10-21 NULL NULL
815
815
6 Grandgrandma Martha 1923-05-17 NULL NULL
816
816
with recursive
817
817
ancestors
@@ -896,9 +896,9 @@ generation name
896
896
1 Dad
897
897
1 Mom
898
898
2 Grandpa Bill
899
-
2 Grandpa Ben
900
899
2 Grandma Ann
901
900
2 Grandma Sally
901
+
2 Grandpa Ben
902
902
3 Grandgrandma Martha
903
903
set standards_compliant_cte=1;
904
904
with recursive
@@ -951,9 +951,9 @@ id name dob father mother
951
951
20 Dad 1970-02-02 10 9
952
952
30 Mom 1975-03-03 8 7
953
953
10 Grandpa Bill 1940-04-05 NULL NULL
954
-
8 Grandpa Ben 1940-10-21 NULL NULL
955
954
9 Grandma Ann 1941-10-15 NULL NULL
956
955
7 Grandma Sally 1943-08-23 NULL 6
956
+
8 Grandpa Ben 1940-10-21 NULL NULL
957
957
with recursive
958
958
ancestor_ids (id)
959
959
as
@@ -998,10 +998,10 @@ id name dob father mother
998
998
20 Dad 1970-02-02 10 9
999
999
30 Mom 1975-03-03 8 7
1000
1000
10 Grandpa Bill 1940-04-05 NULL NULL
1001
-
8 Grandpa Ben 1940-10-21 NULL NULL
1002
-
25 Uncle Jim 1968-11-18 8 7
1003
1001
9 Grandma Ann 1941-10-15 NULL NULL
1002
+
25 Uncle Jim 1968-11-18 8 7
1004
1003
7 Grandma Sally 1943-08-23 NULL 6
1004
+
8 Grandpa Ben 1940-10-21 NULL NULL
1005
1005
6 Grandgrandma Martha 1923-05-17 NULL NULL
1006
1006
27 Auntie Melinda 1971-03-29 NULL NULL
1007
1007
with recursive
@@ -1029,9 +1029,9 @@ generation name
1029
1029
1 Dad
1030
1030
1 Mom
1031
1031
2 Grandpa Bill
1032
-
2 Grandpa Ben
1033
1032
2 Grandma Ann
1034
1033
2 Grandma Sally
1034
+
2 Grandpa Ben
1035
1035
3 Grandgrandma Martha
1036
1036
with recursive
1037
1037
ancestor_ids (id, generation)
@@ -1112,7 +1112,60 @@ generation name
1112
1112
1 Dad
1113
1113
1 Mom
1114
1114
2 Grandpa Bill
1115
-
2 Grandpa Ben
1116
1115
2 Grandma Ann
1117
1116
2 Grandma Sally
1117
+
2 Grandpa Ben
1118
+
alter table folks add primary key (id);
1119
+
explain
1120
+
with recursive
1121
+
ancestors
1122
+
as
1123
+
(
1124
+
select *
1125
+
from folks
1126
+
where name = 'Me'
1127
+
union
1128
+
select p.*
1129
+
from folks as p, ancestors as fa
1130
+
where p.id = fa.father
1131
+
union
1132
+
select p.*
1133
+
from folks as p, ancestors as ma
1134
+
where p.id = ma.mother
1135
+
)
1136
+
select * from ancestors;
1137
+
id select_type table type possible_keys key key_len ref rows Extra
1138
+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12
1139
+
2 SUBQUERY folks ALL NULL NULL NULL NULL 12 Using where
1140
+
3 UNCACHEABLE UNION p ALL PRIMARY NULL NULL NULL 12
1141
+
3 UNCACHEABLE UNION <derived2> ref key0 key0 5 test.p.id 2
1142
+
4 UNCACHEABLE UNION p ALL PRIMARY NULL NULL NULL 12
1143
+
4 UNCACHEABLE UNION <derived2> ref key0 key0 5 test.p.id 2
1144
+
NULL UNION RESULT <union2,3,4> ALL NULL NULL NULL NULL NULL
0 commit comments