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
MDEV-10372: EXPLAIN fixes for recursive CTEs, including FORMAT=JSON
- Tabular EXPLAIN now prints "RECURSIVE UNION".
- There is a basic implementation of EXPLAIN FORMAT=JSON.
- it produces "recursive_union" JSON struct
- No other details or ANALYZE support, yet.
3 SUBQUERY folks ALL NULL NULL NULL NULL 12 100.00 Using where
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
-
5 UNCACHEABLE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00
605
-
5 UNCACHEABLE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
602
+
4 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00
603
+
4 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
604
+
5 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00
605
+
5 RECURSIVE 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
607
2 UNCACHEABLE SUBQUERY <derived3> ALL NULL NULL NULL NULL 12 100.00 Using where
608
608
Warnings:
@@ -781,8 +781,8 @@ select * from ancestors;
781
781
id select_type table type possible_keys key key_len ref rows filtered Extra
782
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
-
3 UNCACHEABLE UNION p ALL NULL NULL NULL NULL 12 100.00
785
-
3 UNCACHEABLE UNION <derived2> ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
784
+
3 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00
785
+
3 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 12 100.00 Using where; Using join buffer (flat, BNL join)
786
786
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
787
787
Warnings:
788
788
Note 1003 with recursive 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') and (`test`.`folks`.`dob` = DATE'2000-01-01')) union select `p`.`id` AS `id`,`p`.`name` AS `name`,`p`.`dob` AS `dob`,`p`.`father` AS `father`,`p`.`mother` AS `mother` from `test`.`folks` `p` join `ancestors` `a` where ((`a`.`father` = `p`.`id`) or (`a`.`mother` = `p`.`id`)))select `ancestors`.`id` AS `id`,`ancestors`.`name` AS `name`,`ancestors`.`dob` AS `dob`,`ancestors`.`father` AS `father`,`ancestors`.`mother` AS `mother` from `ancestors`
@@ -1137,10 +1137,10 @@ select * from ancestors;
1137
1137
id select_type table type possible_keys key key_len ref rows Extra
1138
1138
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12
1139
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
1140
+
3 RECURSIVE UNION p ALL PRIMARY NULL NULL NULL 12
1141
+
3 RECURSIVE UNION <derived2> ref key0 key0 5 test.p.id 2
1142
+
4 RECURSIVE UNION p ALL PRIMARY NULL NULL NULL 12
1143
+
4 RECURSIVE UNION <derived2> ref key0 key0 5 test.p.id 2
1144
1144
NULL UNION RESULT <union2,3,4> ALL NULL NULL NULL NULL NULL
1145
1145
with recursive
1146
1146
ancestors
@@ -1168,4 +1168,346 @@ id name dob father mother
1168
1168
9 Grandma Ann 1941-10-15 NULL NULL
1169
1169
7 Grandma Sally 1943-08-23 NULL 6
1170
1170
6 Grandgrandma Martha 1923-05-17 NULL NULL
1171
+
#
1172
+
# EXPLAIN FORMAT=JSON on a query where one recursive CTE uses another:
1173
+
#
1174
+
explain
1175
+
with recursive
1176
+
prev_gen
1177
+
as
1178
+
(
1179
+
select folks.*
1180
+
from folks, prev_gen
1181
+
where folks.id=prev_gen.father or folks.id=prev_gen.mother
1182
+
union
1183
+
select *
1184
+
from folks
1185
+
where name='Me'
1186
+
),
1187
+
ancestors
1188
+
as
1189
+
(
1190
+
select *
1191
+
from folks
1192
+
where name='Me'
1193
+
union
1194
+
select *
1195
+
from ancestors
1196
+
union
1197
+
select *
1198
+
from prev_gen
1199
+
)
1200
+
select ancestors.name, ancestors.dob from ancestors;
1201
+
id select_type table type possible_keys key key_len ref rows Extra
1202
+
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 24
1203
+
4 SUBQUERY folks ALL NULL NULL NULL NULL 12 Using where
1204
+
6 RECURSIVE UNION <derived3> ALL NULL NULL NULL NULL 12
1205
+
5 RECURSIVE UNION <derived4> ALL NULL NULL NULL NULL 24
1206
+
NULL UNION RESULT <union4,6,5> ALL NULL NULL NULL NULL NULL
1207
+
3 SUBQUERY folks ALL NULL NULL NULL NULL 12 Using where
1208
+
2 RECURSIVE UNION folks ALL PRIMARY NULL NULL NULL 12
1209
+
2 RECURSIVE UNION <derived3> ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1210
+
NULL UNION RESULT <union3,2> ALL NULL NULL NULL NULL NULL
1211
+
explain FORMAT=JSON
1212
+
with recursive
1213
+
prev_gen
1214
+
as
1215
+
(
1216
+
select folks.*
1217
+
from folks, prev_gen
1218
+
where folks.id=prev_gen.father or folks.id=prev_gen.mother
1219
+
union
1220
+
select *
1221
+
from folks
1222
+
where name='Me'
1223
+
),
1224
+
ancestors
1225
+
as
1226
+
(
1227
+
select *
1228
+
from folks
1229
+
where name='Me2'
1230
+
union
1231
+
select *
1232
+
from ancestors where id < 234
1233
+
union
1234
+
select *
1235
+
from prev_gen where id < 345
1236
+
)
1237
+
select ancestors.name, ancestors.dob from ancestors;
1238
+
EXPLAIN
1239
+
{
1240
+
"query_block": {
1241
+
"select_id": 1,
1242
+
"table": {
1243
+
"table_name": "<derived4>",
1244
+
"access_type": "ALL",
1245
+
"rows": 24,
1246
+
"filtered": 100,
1247
+
"materialized": {
1248
+
"query_block": {
1249
+
"recursive_union": {
1250
+
"table_name": "<union4,6,5>",
1251
+
"access_type": "ALL",
1252
+
"query_specifications": [
1253
+
{
1254
+
"query_block": {
1255
+
"select_id": 4,
1256
+
"table": {
1257
+
"table_name": "folks",
1258
+
"access_type": "ALL",
1259
+
"rows": 12,
1260
+
"filtered": 100,
1261
+
"attached_condition": "(folks.`name` = 'Me2')"
1262
+
}
1263
+
}
1264
+
},
1265
+
{
1266
+
"query_block": {
1267
+
"select_id": 6,
1268
+
"table": {
1269
+
"table_name": "<derived3>",
1270
+
"access_type": "ALL",
1271
+
"rows": 12,
1272
+
"filtered": 100,
1273
+
"attached_condition": "(prev_gen.`id` < 345)",
1274
+
"materialized": {
1275
+
"query_block": {
1276
+
"recursive_union": {
1277
+
"table_name": "<union3,2>",
1278
+
"access_type": "ALL",
1279
+
"query_specifications": [
1280
+
{
1281
+
"query_block": {
1282
+
"select_id": 3,
1283
+
"table": {
1284
+
"table_name": "folks",
1285
+
"access_type": "ALL",
1286
+
"rows": 12,
1287
+
"filtered": 100,
1288
+
"attached_condition": "(folks.`name` = 'Me')"
1289
+
}
1290
+
}
1291
+
},
1292
+
{
1293
+
"query_block": {
1294
+
"select_id": 2,
1295
+
"table": {
1296
+
"table_name": "folks",
1297
+
"access_type": "ALL",
1298
+
"possible_keys": ["PRIMARY"],
1299
+
"rows": 12,
1300
+
"filtered": 100
1301
+
},
1302
+
"block-nl-join": {
1303
+
"table": {
1304
+
"table_name": "<derived3>",
1305
+
"access_type": "ALL",
1306
+
"rows": 12,
1307
+
"filtered": 100
1308
+
},
1309
+
"buffer_type": "flat",
1310
+
"buffer_size": "256Kb",
1311
+
"join_type": "BNL",
1312
+
"attached_condition": "((prev_gen.father = folks.`id`) or (prev_gen.mother = folks.`id`))"
0 commit comments