mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
EXPLAIN JSON: Print out the "expensive constant condition" attached to joins.
This commit is contained in:
@ -551,6 +551,7 @@ EXPLAIN
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"const_condition": "1",
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
@ -778,3 +779,54 @@ EXPLAIN
|
||||
}
|
||||
}
|
||||
DROP TABLE t1,t2;
|
||||
#
|
||||
# Join's constant expression
|
||||
#
|
||||
create table t0(a int);
|
||||
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
||||
create table t1(a int, b int);
|
||||
insert into t1 select tbl1.a+10*tbl2.a, 1234 from t0 tbl1, t0 tbl2;
|
||||
explain format=json
|
||||
select * from t0
|
||||
where
|
||||
20000 > all (select max(tbl1.a + tbl2.a)
|
||||
from t1 tbl1, t1 tbl2 where tbl1.b=tbl2.b);
|
||||
EXPLAIN
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"const_condition": "<not>(<in_optimizer>(20000,(<max>(subquery#2) >= 20000)))",
|
||||
"table": {
|
||||
"table_name": "t0",
|
||||
"access_type": "ALL",
|
||||
"rows": 10,
|
||||
"filtered": 100
|
||||
},
|
||||
"subqueries": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"table": {
|
||||
"table_name": "tbl1",
|
||||
"access_type": "ALL",
|
||||
"rows": 100,
|
||||
"filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "tbl2",
|
||||
"access_type": "ALL",
|
||||
"rows": 100,
|
||||
"filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"join_type": "BNL",
|
||||
"attached_condition": "(tbl2.b = tbl1.b)"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
drop table t1;
|
||||
drop table t0;
|
||||
|
@ -2,7 +2,7 @@
|
||||
# EXPLAIN FORMAT=JSON tests. These are tests developed for MariaDB.
|
||||
#
|
||||
--disable_warnings
|
||||
drop table if exists t0,t1;
|
||||
drop table if exists t0,t1,t2;
|
||||
--enable_warnings
|
||||
|
||||
create table t0(a int);
|
||||
@ -167,3 +167,21 @@ EXPLAIN FORMAT=JSON SELECT * FROM t1 AS outer_t1 WHERE a <> ALL ( SELECT a FROM
|
||||
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
--echo #
|
||||
--echo # Join's constant expression
|
||||
--echo #
|
||||
create table t0(a int);
|
||||
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
||||
|
||||
create table t1(a int, b int);
|
||||
insert into t1 select tbl1.a+10*tbl2.a, 1234 from t0 tbl1, t0 tbl2;
|
||||
|
||||
explain format=json
|
||||
select * from t0
|
||||
where
|
||||
20000 > all (select max(tbl1.a + tbl2.a)
|
||||
from t1 tbl1, t1 tbl2 where tbl1.b=tbl2.b);
|
||||
|
||||
drop table t1;
|
||||
drop table t0;
|
||||
|
||||
|
@ -27,6 +27,8 @@ const char * STR_DELETING_ALL_ROWS= "Deleting all rows";
|
||||
const char * STR_IMPOSSIBLE_WHERE= "Impossible WHERE";
|
||||
const char * STR_NO_ROWS_AFTER_PRUNING= "No matching rows after partition pruning";
|
||||
|
||||
static void write_item(Json_writer *writer, Item *item);
|
||||
|
||||
Explain_query::Explain_query(THD *thd_arg, MEM_ROOT *root) :
|
||||
mem_root(root), upd_del_plan(NULL), insert_plan(NULL),
|
||||
unions(root), selects(root), thd(thd_arg), apc_enabled(false),
|
||||
@ -732,7 +734,17 @@ void Explain_select::print_explain_json(Explain_query *query,
|
||||
Explain_basic_join does not have ORDER/GROUP.
|
||||
A: factor out join tab printing loop into a common func.
|
||||
*/
|
||||
Explain_basic_join::print_explain_json(query, writer, is_analyze);
|
||||
writer->add_member("query_block").start_object();
|
||||
writer->add_member("select_id").add_ll(select_id);
|
||||
|
||||
if (exec_const_cond)
|
||||
{
|
||||
writer->add_member("const_condition");
|
||||
write_item(writer, exec_const_cond);
|
||||
}
|
||||
|
||||
Explain_basic_join::print_explain_json_interns(query, writer, is_analyze);
|
||||
writer->end_object();
|
||||
}
|
||||
|
||||
}
|
||||
@ -742,10 +754,20 @@ void Explain_basic_join::print_explain_json(Explain_query *query,
|
||||
Json_writer *writer,
|
||||
bool is_analyze)
|
||||
{
|
||||
Json_writer_nesting_guard guard(writer);
|
||||
|
||||
writer->add_member("query_block").start_object();
|
||||
writer->add_member("select_id").add_ll(select_id);
|
||||
|
||||
print_explain_json_interns(query, writer, is_analyze);
|
||||
|
||||
writer->end_object();
|
||||
}
|
||||
|
||||
|
||||
void Explain_basic_join::print_explain_json_interns(Explain_query *query,
|
||||
Json_writer *writer,
|
||||
bool is_analyze)
|
||||
{
|
||||
Json_writer_nesting_guard guard(writer);
|
||||
for (uint i=0; i< n_join_tabs; i++)
|
||||
{
|
||||
if (join_tabs[i]->start_dups_weedout)
|
||||
@ -757,7 +779,6 @@ void Explain_basic_join::print_explain_json(Explain_query *query,
|
||||
writer->end_object();
|
||||
}
|
||||
print_explain_json_for_children(query, writer, is_analyze);
|
||||
writer->end_object();
|
||||
}
|
||||
|
||||
|
||||
|
@ -175,6 +175,9 @@ public:
|
||||
void print_explain_json(Explain_query *query, Json_writer *writer,
|
||||
bool is_analyze);
|
||||
|
||||
void print_explain_json_interns(Explain_query *query, Json_writer *writer,
|
||||
bool is_analyze);
|
||||
|
||||
/* A flat array of Explain structs for tables. */
|
||||
Explain_table_access** join_tabs;
|
||||
uint n_join_tabs;
|
||||
@ -222,6 +225,9 @@ public:
|
||||
*/
|
||||
const char *message;
|
||||
|
||||
/* Expensive constant condition */
|
||||
Item *exec_const_cond;
|
||||
|
||||
/* Global join attributes. In tabular form, they are printed on the first row */
|
||||
bool using_temporary;
|
||||
bool using_filesort;
|
||||
|
@ -23768,6 +23768,8 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
|
||||
if (need_order)
|
||||
xpl_sel->using_filesort= true;
|
||||
|
||||
xpl_sel->exec_const_cond= exec_const_cond;
|
||||
|
||||
JOIN_TAB* const first_top_tab= first_breadth_first_tab(join, WALK_OPTIMIZATION_TABS);
|
||||
JOIN_TAB* prev_bush_root_tab= NULL;
|
||||
|
||||
|
Reference in New Issue
Block a user