1drop table if exists t0,t1,t2,t3;
2create table t0 (a int);
3INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
4# r_filtered=30%, because 3 rows match: 0,1,2
5analyze format=json select * from t0 where a<3;
6ANALYZE
7{
8  "query_block": {
9    "select_id": 1,
10    "r_loops": 1,
11    "r_total_time_ms": "REPLACED",
12    "table": {
13      "table_name": "t0",
14      "access_type": "ALL",
15      "r_loops": 1,
16      "rows": 10,
17      "r_rows": 10,
18      "r_table_time_ms": "REPLACED",
19      "r_other_time_ms": "REPLACED",
20      "filtered": 100,
21      "r_filtered": 30,
22      "attached_condition": "t0.a < 3"
23    }
24  }
25}
26create table t1 (a int, b int, c int, key(a));
27insert into t1 select A.a*10 + B.a, A.a*10 + B.a, A.a*10 + B.a from t0 A, t0 B;
28analyze
29select * from t0, t1 where t1.a=t0.a and t0.a > 9;
30id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
311	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	0.00	Using where
321	SIMPLE	t1	ref	a	a	5	test.t0.a	1	NULL	100.00	NULL
33analyze format=json
34select * from t0, t1 where t1.a=t0.a and t0.a > 9;
35ANALYZE
36{
37  "query_block": {
38    "select_id": 1,
39    "r_loops": 1,
40    "r_total_time_ms": "REPLACED",
41    "table": {
42      "table_name": "t0",
43      "access_type": "ALL",
44      "r_loops": 1,
45      "rows": 10,
46      "r_rows": 10,
47      "r_table_time_ms": "REPLACED",
48      "r_other_time_ms": "REPLACED",
49      "filtered": 100,
50      "r_filtered": 0,
51      "attached_condition": "t0.a > 9 and t0.a is not null"
52    },
53    "table": {
54      "table_name": "t1",
55      "access_type": "ref",
56      "possible_keys": ["a"],
57      "key": "a",
58      "key_length": "5",
59      "used_key_parts": ["a"],
60      "ref": ["test.t0.a"],
61      "r_loops": 0,
62      "rows": 1,
63      "r_rows": null,
64      "filtered": 100,
65      "r_filtered": null
66    }
67  }
68}
69analyze
70select * from t0, t1 where t1.a=t0.a and t1.b<4;
71id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
721	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	100.00	Using where
731	SIMPLE	t1	ref	a	a	5	test.t0.a	1	1.00	100.00	40.00	Using where
74analyze format=json
75select * from t0, t1 where t1.a=t0.a and t1.b<4;
76ANALYZE
77{
78  "query_block": {
79    "select_id": 1,
80    "r_loops": 1,
81    "r_total_time_ms": "REPLACED",
82    "table": {
83      "table_name": "t0",
84      "access_type": "ALL",
85      "r_loops": 1,
86      "rows": 10,
87      "r_rows": 10,
88      "r_table_time_ms": "REPLACED",
89      "r_other_time_ms": "REPLACED",
90      "filtered": 100,
91      "r_filtered": 100,
92      "attached_condition": "t0.a is not null"
93    },
94    "table": {
95      "table_name": "t1",
96      "access_type": "ref",
97      "possible_keys": ["a"],
98      "key": "a",
99      "key_length": "5",
100      "used_key_parts": ["a"],
101      "ref": ["test.t0.a"],
102      "r_loops": 10,
103      "rows": 1,
104      "r_rows": 1,
105      "r_table_time_ms": "REPLACED",
106      "r_other_time_ms": "REPLACED",
107      "filtered": 100,
108      "r_filtered": 40,
109      "attached_condition": "t1.b < 4"
110    }
111  }
112}
113analyze
114select * from t1 tbl1, t1 tbl2 where tbl1.b<2 and tbl2.b>5;
115id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1161	SIMPLE	tbl1	ALL	NULL	NULL	NULL	NULL	100	100.00	100.00	2.00	Using where
1171	SIMPLE	tbl2	ALL	NULL	NULL	NULL	NULL	100	100.00	100.00	94.00	Using where; Using join buffer (flat, BNL join)
118analyze format=json
119select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60;
120ANALYZE
121{
122  "query_block": {
123    "select_id": 1,
124    "r_loops": 1,
125    "r_total_time_ms": "REPLACED",
126    "table": {
127      "table_name": "tbl1",
128      "access_type": "ALL",
129      "r_loops": 1,
130      "rows": 100,
131      "r_rows": 100,
132      "r_table_time_ms": "REPLACED",
133      "r_other_time_ms": "REPLACED",
134      "filtered": 100,
135      "r_filtered": 20,
136      "attached_condition": "tbl1.b < 20"
137    },
138    "block-nl-join": {
139      "table": {
140        "table_name": "tbl2",
141        "access_type": "ALL",
142        "r_loops": 1,
143        "rows": 100,
144        "r_rows": 100,
145        "r_table_time_ms": "REPLACED",
146        "r_other_time_ms": "REPLACED",
147        "filtered": 100,
148        "r_filtered": 60,
149        "attached_condition": "tbl2.b < 60"
150      },
151      "buffer_type": "flat",
152      "buffer_size": "1Kb",
153      "join_type": "BNL",
154      "r_filtered": 100
155    }
156  }
157}
158analyze format=json
159select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60 and tbl1.c > tbl2.c;
160ANALYZE
161{
162  "query_block": {
163    "select_id": 1,
164    "r_loops": 1,
165    "r_total_time_ms": "REPLACED",
166    "table": {
167      "table_name": "tbl1",
168      "access_type": "ALL",
169      "r_loops": 1,
170      "rows": 100,
171      "r_rows": 100,
172      "r_table_time_ms": "REPLACED",
173      "r_other_time_ms": "REPLACED",
174      "filtered": 100,
175      "r_filtered": 20,
176      "attached_condition": "tbl1.b < 20"
177    },
178    "block-nl-join": {
179      "table": {
180        "table_name": "tbl2",
181        "access_type": "ALL",
182        "r_loops": 1,
183        "rows": 100,
184        "r_rows": 100,
185        "r_table_time_ms": "REPLACED",
186        "r_other_time_ms": "REPLACED",
187        "filtered": 100,
188        "r_filtered": 60,
189        "attached_condition": "tbl2.b < 60"
190      },
191      "buffer_type": "flat",
192      "buffer_size": "1Kb",
193      "join_type": "BNL",
194      "attached_condition": "tbl1.c > tbl2.c",
195      "r_filtered": 15.83333333
196    }
197  }
198}
199drop table t1;
200drop table t0;
201#
202# MDEV-7674: ANALYZE shows r_rows=0
203#
204create table t1(a int);
205insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
206create table t2 (a int, key(a));
207insert into t2 values (0),(1);
208analyze format=json select * from t1 straight_join t2 force index(a) where t2.a=t1.a;
209ANALYZE
210{
211  "query_block": {
212    "select_id": 1,
213    "r_loops": 1,
214    "r_total_time_ms": "REPLACED",
215    "table": {
216      "table_name": "t1",
217      "access_type": "ALL",
218      "r_loops": 1,
219      "rows": 10,
220      "r_rows": 10,
221      "r_table_time_ms": "REPLACED",
222      "r_other_time_ms": "REPLACED",
223      "filtered": 100,
224      "r_filtered": 100,
225      "attached_condition": "t1.a is not null"
226    },
227    "table": {
228      "table_name": "t2",
229      "access_type": "ref",
230      "possible_keys": ["a"],
231      "key": "a",
232      "key_length": "5",
233      "used_key_parts": ["a"],
234      "ref": ["test.t1.a"],
235      "r_loops": 10,
236      "rows": 2,
237      "r_rows": 0.2,
238      "r_table_time_ms": "REPLACED",
239      "r_other_time_ms": "REPLACED",
240      "filtered": 100,
241      "r_filtered": 100,
242      "using_index": true
243    }
244  }
245}
246drop table t1,t2;
247create table t1(a int);
248insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
249#
250# MDEV-7679: ANALYZE crashes when printing WHERE when no default db
251#
252select database();
253database()
254test
255connect  con1,localhost,root,,*NO-ONE*;
256connection con1;
257select database();
258database()
259NULL
260analyze format=json select * from test.t1 where t1.a<5;
261ANALYZE
262{
263  "query_block": {
264    "select_id": 1,
265    "r_loops": 1,
266    "r_total_time_ms": "REPLACED",
267    "table": {
268      "table_name": "t1",
269      "access_type": "ALL",
270      "r_loops": 1,
271      "rows": 10,
272      "r_rows": 10,
273      "r_table_time_ms": "REPLACED",
274      "r_other_time_ms": "REPLACED",
275      "filtered": 100,
276      "r_filtered": 50,
277      "attached_condition": "test.t1.a < 5"
278    }
279  }
280}
281disconnect con1;
282connection default;
283drop table t1;
284#
285# MDEV-7812: ANALYZE FORMAT=JSON UPDATE/DELETE doesnt print
286# the r_total_time_ms
287#
288create table t2(a int);
289insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
290create table t3(a int);
291insert into t3 select A.a + B.a* 10 + C.a * 100 from t2 A, t2 B, t2 C;
292create table t1 (pk int primary key);
293insert into t1 select a from t3;
294alter table t1 add b int;
295analyze format=json
296update t1 set b=pk;
297ANALYZE
298{
299  "query_block": {
300    "select_id": 1,
301    "r_total_time_ms": "REPLACED",
302    "table": {
303      "update": 1,
304      "table_name": "t1",
305      "access_type": "ALL",
306      "rows": 1000,
307      "r_rows": 1000,
308      "r_filtered": 100,
309      "r_total_time_ms": "REPLACED"
310    }
311  }
312}
313analyze format=json
314select * from t1 where pk < 10 and b > 4;
315ANALYZE
316{
317  "query_block": {
318    "select_id": 1,
319    "r_loops": 1,
320    "r_total_time_ms": "REPLACED",
321    "table": {
322      "table_name": "t1",
323      "access_type": "range",
324      "possible_keys": ["PRIMARY"],
325      "key": "PRIMARY",
326      "key_length": "4",
327      "used_key_parts": ["pk"],
328      "r_loops": 1,
329      "rows": 10,
330      "r_rows": 10,
331      "r_table_time_ms": "REPLACED",
332      "r_other_time_ms": "REPLACED",
333      "filtered": 100,
334      "r_filtered": 50,
335      "index_condition": "t1.pk < 10",
336      "attached_condition": "t1.b > 4"
337    }
338  }
339}
340analyze format=json
341delete from t1 where pk < 10 and b > 4;
342ANALYZE
343{
344  "query_block": {
345    "select_id": 1,
346    "r_total_time_ms": "REPLACED",
347    "table": {
348      "delete": 1,
349      "table_name": "t1",
350      "access_type": "range",
351      "possible_keys": ["PRIMARY"],
352      "key": "PRIMARY",
353      "key_length": "4",
354      "used_key_parts": ["pk"],
355      "rows": 10,
356      "r_rows": 10,
357      "r_filtered": 50,
358      "r_total_time_ms": "REPLACED",
359      "attached_condition": "t1.pk < 10 and t1.b > 4"
360    }
361  }
362}
363drop table t1, t3, t2;
364#
365# MDEV-7833:ANALYZE FORMAT=JSON and Range checked for each record
366#
367create table t3(a int);
368insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
369create table t4(a int);
370insert into t4 select A.a + B.a* 10 + C.a * 100 from t3 A, t3 B, t3 C;
371create table t1 (lb1 int, rb1 int, lb2 int, rb2 int, c1 int, c2 int);
372insert into t1 values (1,2,10,20,15,15);
373insert into t1 values (3,5,10,20,15,15);
374insert into t1 values (10,20,10,20,15,15);
375insert into t1 values (10,20,1,2,15,15);
376insert into t1 values (10,20,10,20,1,3);
377create table t2 (key1 int, key2 int, key3 int, key4 int, col1 int,
378key(key1), key(key2), key(key3), key(key4));
379insert into t2 select a,a,a,a,a from t3;
380insert into t2 select 15,15,15,15,15 from t4;
381analyze format=json
382select * from t1, t2 where (t2.key1 between t1.lb1 and t1.rb1) and
383(t2.key2 between t1.lb2 and t1.rb2) and
384(t2.key3=t1.c1  OR t2.key4=t1.c2);
385ANALYZE
386{
387  "query_block": {
388    "select_id": 1,
389    "r_loops": 1,
390    "r_total_time_ms": "REPLACED",
391    "table": {
392      "table_name": "t1",
393      "access_type": "ALL",
394      "r_loops": 1,
395      "rows": 5,
396      "r_rows": 5,
397      "r_table_time_ms": "REPLACED",
398      "r_other_time_ms": "REPLACED",
399      "filtered": 100,
400      "r_filtered": 100
401    },
402    "range-checked-for-each-record": {
403      "keys": ["key1", "key2", "key3", "key4"],
404      "r_keys": {
405        "full_scan": 1,
406        "index_merge": 1,
407        "range": {
408          "key1": 2,
409          "key2": 1,
410          "key3": 0,
411          "key4": 0
412        }
413      },
414      "table": {
415        "table_name": "t2",
416        "access_type": "ALL",
417        "possible_keys": ["key1", "key2", "key3", "key4"],
418        "r_loops": 5,
419        "rows": 1010,
420        "r_rows": 203.8,
421        "r_table_time_ms": "REPLACED",
422        "r_other_time_ms": "REPLACED",
423        "filtered": 100,
424        "r_filtered": 98.13542689
425      }
426    }
427  }
428}
429drop table t1,t2,t3,t4;
430#
431# MDEV-7904: ANALYZE FORMAT=JSON SELECT .. UNION SELECT doesn't print r_rows for union output
432#
433create table t0 (a int);
434INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
435create table t1 (a int);
436INSERT INTO t1 select * from t0;
437analyze format=json (select * from t1 tbl1 where a<5) union (select * from t1 tbl2 where a in (2,3));
438ANALYZE
439{
440  "query_block": {
441    "union_result": {
442      "table_name": "<union1,2>",
443      "access_type": "ALL",
444      "r_loops": 1,
445      "r_rows": 5,
446      "query_specifications": [
447        {
448          "query_block": {
449            "select_id": 1,
450            "r_loops": 1,
451            "r_total_time_ms": "REPLACED",
452            "table": {
453              "table_name": "tbl1",
454              "access_type": "ALL",
455              "r_loops": 1,
456              "rows": 10,
457              "r_rows": 10,
458              "r_table_time_ms": "REPLACED",
459              "r_other_time_ms": "REPLACED",
460              "filtered": 100,
461              "r_filtered": 50,
462              "attached_condition": "tbl1.a < 5"
463            }
464          }
465        },
466        {
467          "query_block": {
468            "select_id": 2,
469            "operation": "UNION",
470            "r_loops": 1,
471            "r_total_time_ms": "REPLACED",
472            "table": {
473              "table_name": "tbl2",
474              "access_type": "ALL",
475              "r_loops": 1,
476              "rows": 10,
477              "r_rows": 10,
478              "r_table_time_ms": "REPLACED",
479              "r_other_time_ms": "REPLACED",
480              "filtered": 100,
481              "r_filtered": 20,
482              "attached_condition": "tbl2.a in (2,3)"
483            }
484          }
485        }
486      ]
487    }
488  }
489}
490drop table t0, t1;
491#
492# MDEV-7970: EXPLAIN FORMAT=JSON does not print HAVING
493#
494create table t0(a int);
495insert into t0 values (0),(1),(2),(3);
496create table t1(a int);
497insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C;
498create table t2 (
499a int,
500b int,
501key (a)
502);
503insert into t2 select A.a*1000 + B.a, A.a*1000 + B.a from t0 A, t1 B;
504# normal HAVING
505analyze format=json select a, max(b) as TOP from t2 group by a having TOP > a;
506ANALYZE
507{
508  "query_block": {
509    "select_id": 1,
510    "r_loops": 1,
511    "r_total_time_ms": "REPLACED",
512    "having_condition": "TOP > t2.a",
513    "filesort": {
514      "sort_key": "t2.a",
515      "r_loops": 1,
516      "r_total_time_ms": "REPLACED",
517      "r_used_priority_queue": false,
518      "r_output_rows": 0,
519      "r_buffer_size": "REPLACED",
520      "r_sort_mode": "sort_key,rowid",
521      "temporary_table": {
522        "table": {
523          "table_name": "t2",
524          "access_type": "ALL",
525          "r_loops": 1,
526          "rows": 256,
527          "r_rows": 256,
528          "r_table_time_ms": "REPLACED",
529          "r_other_time_ms": "REPLACED",
530          "filtered": 100,
531          "r_filtered": 100
532        }
533      }
534    }
535  }
536}
537# HAVING is always TRUE (not printed)
538analyze format=json select a, max(b) as TOP from t2 group by a having 1<>2;
539ANALYZE
540{
541  "query_block": {
542    "select_id": 1,
543    "r_loops": 1,
544    "r_total_time_ms": "REPLACED",
545    "filesort": {
546      "sort_key": "t2.a",
547      "r_loops": 1,
548      "r_total_time_ms": "REPLACED",
549      "r_used_priority_queue": false,
550      "r_output_rows": 256,
551      "r_buffer_size": "REPLACED",
552      "r_sort_mode": "sort_key,rowid",
553      "temporary_table": {
554        "table": {
555          "table_name": "t2",
556          "access_type": "ALL",
557          "r_loops": 1,
558          "rows": 256,
559          "r_rows": 256,
560          "r_table_time_ms": "REPLACED",
561          "r_other_time_ms": "REPLACED",
562          "filtered": 100,
563          "r_filtered": 100
564        }
565      }
566    }
567  }
568}
569# HAVING is always FALSE (intercepted by message)
570analyze format=json select a, max(b) as TOP from t2 group by a having 1=2;
571ANALYZE
572{
573  "query_block": {
574    "select_id": 1,
575    "table": {
576      "message": "Impossible HAVING"
577    }
578  }
579}
580# HAVING is absent
581analyze format=json select a, max(b) as TOP from t2 group by a;
582ANALYZE
583{
584  "query_block": {
585    "select_id": 1,
586    "r_loops": 1,
587    "r_total_time_ms": "REPLACED",
588    "filesort": {
589      "sort_key": "t2.a",
590      "r_loops": 1,
591      "r_total_time_ms": "REPLACED",
592      "r_used_priority_queue": false,
593      "r_output_rows": 256,
594      "r_buffer_size": "REPLACED",
595      "r_sort_mode": "sort_key,rowid",
596      "temporary_table": {
597        "table": {
598          "table_name": "t2",
599          "access_type": "ALL",
600          "r_loops": 1,
601          "rows": 256,
602          "r_rows": 256,
603          "r_table_time_ms": "REPLACED",
604          "r_other_time_ms": "REPLACED",
605          "filtered": 100,
606          "r_filtered": 100
607        }
608      }
609    }
610  }
611}
612drop table t0, t1, t2;
613#
614# MDEV-7267: Server crashes in Item_field::print on ANALYZE FORMAT=JSON
615#
616CREATE TABLE t1 (a INT);
617INSERT INTO t1 VALUES (1),(2);
618CREATE TABLE t2 (b INT);
619INSERT INTO t2 VALUES (3),(4);
620ANALYZE FORMAT=JSON SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 );
621ANALYZE
622{
623  "query_block": {
624    "select_id": 1,
625    "r_loops": 1,
626    "r_total_time_ms": "REPLACED",
627    "table": {
628      "table_name": "t1",
629      "access_type": "ALL",
630      "r_loops": 1,
631      "rows": 2,
632      "r_rows": 2,
633      "r_table_time_ms": "REPLACED",
634      "r_other_time_ms": "REPLACED",
635      "filtered": 100,
636      "r_filtered": 100
637    },
638    "block-nl-join": {
639      "table": {
640        "table_name": "t2",
641        "access_type": "ALL",
642        "r_loops": 1,
643        "rows": 2,
644        "r_rows": 2,
645        "r_table_time_ms": "REPLACED",
646        "r_other_time_ms": "REPLACED",
647        "filtered": 100,
648        "r_filtered": 0,
649        "attached_condition": "<in_optimizer>(t2.b,t2.b in (subquery#2))"
650      },
651      "buffer_type": "flat",
652      "buffer_size": "65",
653      "join_type": "BNL",
654      "attached_condition": "<in_optimizer>(t2.b,t2.b in (subquery#2))",
655      "r_filtered": null
656    },
657    "subqueries": [
658      {
659        "query_block": {
660          "select_id": 2,
661          "r_loops": 1,
662          "r_total_time_ms": "REPLACED",
663          "table": {
664            "table_name": "t1",
665            "access_type": "ALL",
666            "r_loops": 1,
667            "rows": 2,
668            "r_rows": 2,
669            "r_table_time_ms": "REPLACED",
670            "r_other_time_ms": "REPLACED",
671            "filtered": 100,
672            "r_filtered": 100
673          }
674        }
675      }
676    ]
677  }
678}
679drop table t1,t2;
680#
681# MDEV-8864: Server crash #2 in Item_field::print on ANALYZE FORMAT=JSON
682#
683CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
684INSERT INTO t1 VALUES (1),(2);
685CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
686INSERT INTO t2 VALUES (2),(3);
687CREATE TABLE t3 (f3 INT) ENGINE=MyISAM;
688INSERT INTO t3 VALUES (3),(4);
689ANALYZE FORMAT=JSON
690SELECT GROUP_CONCAT(f3) AS gc, ( SELECT MAX(f1) FROM t1, t2 WHERE f2 = f3 ) sq
691FROM t2, t3
692WHERE f3 IN ( 1, 2 )
693GROUP BY sq ORDER BY gc;
694ANALYZE
695{
696  "query_block": {
697    "select_id": 1,
698    "r_loops": 1,
699    "r_total_time_ms": "REPLACED",
700    "filesort": {
701      "sort_key": "group_concat(t3.f3 separator ',')",
702      "r_loops": 1,
703      "r_total_time_ms": "REPLACED",
704      "r_used_priority_queue": false,
705      "r_output_rows": 0,
706      "r_buffer_size": "REPLACED",
707      "r_sort_mode": "packed_sort_key,rowid",
708      "temporary_table": {
709        "filesort": {
710          "sort_key": "(subquery#2)",
711          "r_loops": 1,
712          "r_total_time_ms": "REPLACED",
713          "r_used_priority_queue": false,
714          "r_output_rows": 0,
715          "r_buffer_size": "REPLACED",
716          "r_sort_mode": "sort_key,rowid",
717          "temporary_table": {
718            "table": {
719              "table_name": "t2",
720              "access_type": "ALL",
721              "r_loops": 1,
722              "rows": 2,
723              "r_rows": 2,
724              "r_table_time_ms": "REPLACED",
725              "r_other_time_ms": "REPLACED",
726              "filtered": 100,
727              "r_filtered": 100
728            },
729            "block-nl-join": {
730              "table": {
731                "table_name": "t3",
732                "access_type": "ALL",
733                "r_loops": 1,
734                "rows": 2,
735                "r_rows": 2,
736                "r_table_time_ms": "REPLACED",
737                "r_other_time_ms": "REPLACED",
738                "filtered": 100,
739                "r_filtered": 0,
740                "attached_condition": "t3.f3 in (1,2)"
741              },
742              "buffer_type": "flat",
743              "buffer_size": "1",
744              "join_type": "BNL",
745              "r_filtered": null
746            },
747            "subqueries": [
748              {
749                "expression_cache": {
750                  "state": "uninitialized",
751                  "r_loops": 0,
752                  "query_block": {
753                    "select_id": 2,
754                    "table": {
755                      "table_name": "t1",
756                      "access_type": "ALL",
757                      "r_loops": 0,
758                      "rows": 2,
759                      "r_rows": null,
760                      "filtered": 100,
761                      "r_filtered": null
762                    },
763                    "block-nl-join": {
764                      "table": {
765                        "table_name": "t2",
766                        "access_type": "ALL",
767                        "r_loops": 0,
768                        "rows": 2,
769                        "r_rows": null,
770                        "filtered": 100,
771                        "r_filtered": null
772                      },
773                      "buffer_type": "flat",
774                      "buffer_size": "65",
775                      "join_type": "BNL",
776                      "attached_condition": "t2.f2 = t3.f3",
777                      "r_filtered": null
778                    }
779                  }
780                }
781              }
782            ]
783          }
784        }
785      }
786    }
787  }
788}
789drop table t1,t2,t3;
790#
791# MDEV-13286: Floating point exception in Filesort_tracker::print_json_members(Json_writer*)
792#
793create table t0(a int);
794insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
795create table t1 (a int, b int, c int);
796insert into t1 select a,a,a from t0;
797create table t2 as select * from t1;
798analyze format=json select a, (select t2.b from t2 where t2.a<t1.a order by t2.c limit 1) from t1 where t1.a<0;
799ANALYZE
800{
801  "query_block": {
802    "select_id": 1,
803    "r_loops": 1,
804    "r_total_time_ms": "REPLACED",
805    "table": {
806      "table_name": "t1",
807      "access_type": "ALL",
808      "r_loops": 1,
809      "rows": 10,
810      "r_rows": 10,
811      "r_table_time_ms": "REPLACED",
812      "r_other_time_ms": "REPLACED",
813      "filtered": 100,
814      "r_filtered": 0,
815      "attached_condition": "t1.a < 0"
816    },
817    "subqueries": [
818      {
819        "expression_cache": {
820          "state": "uninitialized",
821          "r_loops": 0,
822          "query_block": {
823            "select_id": 2,
824            "read_sorted_file": {
825              "r_rows": null,
826              "filesort": {
827                "sort_key": "t2.c",
828                "r_loops": null,
829                "r_limit": null,
830                "r_used_priority_queue": null,
831                "r_output_rows": null,
832                "r_sort_mode": "sort_key,rowid",
833                "table": {
834                  "table_name": "t2",
835                  "access_type": "ALL",
836                  "r_loops": 0,
837                  "rows": 10,
838                  "r_rows": null,
839                  "filtered": 100,
840                  "r_filtered": null,
841                  "attached_condition": "t2.a < t1.a"
842                }
843              }
844            }
845          }
846        }
847      }
848    ]
849  }
850}
851drop table t0,t1,t2;
852