Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
dc259324
Commit
dc259324
authored
Dec 06, 2014
by
Sergei Petrunia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EXPLAIN JSON: Print out the "expensive constant condition" attached to joins.
parent
5ee1c25f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
104 additions
and
5 deletions
+104
-5
mysql-test/r/explain_json.result
mysql-test/r/explain_json.result
+52
-0
mysql-test/t/explain_json.test
mysql-test/t/explain_json.test
+19
-1
sql/sql_explain.cc
sql/sql_explain.cc
+25
-4
sql/sql_explain.h
sql/sql_explain.h
+6
-0
sql/sql_select.cc
sql/sql_select.cc
+2
-0
No files found.
mysql-test/r/explain_json.result
View file @
dc259324
...
...
@@ -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;
mysql-test/t/explain_json.test
View file @
dc259324
...
...
@@ -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
;
sql/sql_explain.cc
View file @
dc259324
...
...
@@ -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
();
}
...
...
sql/sql_explain.h
View file @
dc259324
...
...
@@ -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
;
...
...
sql/sql_select.cc
View file @
dc259324
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment