Skip to content

Commit ab44e89

Browse files
committed
MDEV-9652: EXPLAIN FORMAT=JSON should show outer_ref_cond
Show outer_ref_condition in EXPLAIN FORMAT=JSON output.
1 parent 0dbfc0f commit ab44e89

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

mysql-test/r/explain_json.result

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,3 +1543,43 @@ ANALYZE
15431543
set optimizer_switch=@tmp_optimizer_switch;
15441544
set join_cache_level=@tmp_join_cache_level;
15451545
drop table t1,t2,t3,t4;
1546+
#
1547+
# MDEV-9652: EXPLAIN FORMAT=JSON should show outer_ref_cond
1548+
#
1549+
create table t0(a int);
1550+
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1551+
create table t1 (a int, b int);
1552+
insert into t1 select a,a from t0;
1553+
explain format=json
1554+
select a, (select max(a) from t1 where t0.a<5 and t1.b<t0.a) from t0;
1555+
EXPLAIN
1556+
{
1557+
"query_block": {
1558+
"select_id": 1,
1559+
"table": {
1560+
"table_name": "t0",
1561+
"access_type": "ALL",
1562+
"rows": 10,
1563+
"filtered": 100
1564+
},
1565+
"subqueries": [
1566+
{
1567+
"expression_cache": {
1568+
"state": "uninitialized",
1569+
"query_block": {
1570+
"select_id": 2,
1571+
"outer_ref_condition": "(t0.a < 5)",
1572+
"table": {
1573+
"table_name": "t1",
1574+
"access_type": "ALL",
1575+
"rows": 10,
1576+
"filtered": 100,
1577+
"attached_condition": "((t0.a < 5) and (t1.b < t0.a))"
1578+
}
1579+
}
1580+
}
1581+
}
1582+
]
1583+
}
1584+
}
1585+
drop table t0,t1;

mysql-test/t/explain_json.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,5 +394,15 @@ set join_cache_level=@tmp_join_cache_level;
394394

395395
drop table t1,t2,t3,t4;
396396

397+
--echo #
398+
--echo # MDEV-9652: EXPLAIN FORMAT=JSON should show outer_ref_cond
399+
--echo #
400+
create table t0(a int);
401+
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
402+
create table t1 (a int, b int);
403+
insert into t1 select a,a from t0;
397404

405+
explain format=json
406+
select a, (select max(a) from t1 where t0.a<5 and t1.b<t0.a) from t0;
407+
drop table t0,t1;
398408

sql/sql_explain.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,12 @@ void Explain_select::print_explain_json(Explain_query *query,
862862
writer->add_member("const_condition");
863863
write_item(writer, exec_const_cond);
864864
}
865+
if (outer_ref_cond)
866+
{
867+
writer->add_member("outer_ref_condition");
868+
write_item(writer, outer_ref_cond);
869+
}
870+
865871
/* we do not print HAVING which always evaluates to TRUE */
866872
if (having || (having_value == Item::COND_FALSE))
867873
{

sql/sql_explain.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ class Explain_select : public Explain_basic_join
232232

233233
/* Expensive constant condition */
234234
Item *exec_const_cond;
235+
Item *outer_ref_cond;
235236

236237
/* HAVING condition */
237-
COND *having;
238+
Item *having;
238239
Item::cond_result having_value;
239240

240241
/* Global join attributes. In tabular form, they are printed on the first row */

sql/sql_select.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24252,6 +24252,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
2425224252
xpl_sel->using_filesort= true;
2425324253

2425424254
xpl_sel->exec_const_cond= exec_const_cond;
24255+
xpl_sel->outer_ref_cond= outer_ref_cond;
2425524256
if (tmp_having)
2425624257
xpl_sel->having= tmp_having;
2425724258
else

0 commit comments

Comments
 (0)