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
ff40705f
Commit
ff40705f
authored
Apr 26, 2012
by
Sergey Petrunya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make SHOW EXPLAIN FOR produce a warning with the original text of query
that the EXPLAIN is for.
parent
9b269ea1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
5 deletions
+46
-5
mysql-test/r/show_explain.result
mysql-test/r/show_explain.result
+28
-0
sql/sql_class.cc
sql/sql_class.cc
+11
-5
sql/sql_class.h
sql/sql_class.h
+2
-0
sql/sql_show.cc
sql/sql_show.cc
+5
-0
No files found.
mysql-test/r/show_explain.result
View file @
ff40705f
...
...
@@ -20,12 +20,16 @@ select count(*) from t1 where a < 100000;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 5 NULL 1000 Using where; Using index
Warnings:
Note 1003 select count(*) from t1 where a < 100000
count(*)
1000
select max(c) from t1 where a < 10;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 10 Using index condition
Warnings:
Note 1003 select max(c) from t1 where a < 10
max(c)
9
# We can catch EXPLAIN, too.
...
...
@@ -35,6 +39,8 @@ explain select max(c) from t1 where a < 10;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 10 Using index condition; Rowid-ordered scan
Warnings:
Note 1003 explain select max(c) from t1 where a < 10
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 10 Using index condition; Rowid-ordered scan
set optimizer_switch= @show_expl_tmp;
...
...
@@ -47,6 +53,8 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 10
2 UNION B ALL NULL NULL NULL NULL 10
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
Warnings:
Note 1003 explain select a from t0 A union select a+1 from t0 B
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 10
2 UNION B ALL NULL NULL NULL NULL 10
...
...
@@ -60,6 +68,8 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 10
2 UNION B ALL NULL NULL NULL NULL 10
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
Warnings:
Note 1003 explain select a from t0 A union select a+1 from t0 B
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 10
2 UNION B ALL NULL NULL NULL NULL 10
...
...
@@ -72,6 +82,8 @@ show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 10 Using where
2 SUBQUERY B ALL NULL NULL NULL NULL 10
Warnings:
Note 1003 select a, (select max(a) from t0 B) from t0 A where a<1
a (select max(a) from t0 B)
0 9
# Uncorrelated subquery, explain
...
...
@@ -82,6 +94,8 @@ show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 10 Using where
2 SUBQUERY B ALL NULL NULL NULL NULL 10
Warnings:
Note 1003 explain select a, (select max(a) from t0 B) from t0 A where a<1
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 10 Using where
2 SUBQUERY B ALL NULL NULL NULL NULL 10
...
...
@@ -93,6 +107,8 @@ show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY a ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY b ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1
a (select max(a) from t0 b where b.a+a.a<10)
0 9
# correlated subquery, explain
...
...
@@ -103,6 +119,8 @@ show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY a ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY b ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1
a (select max(a) from t0 b where b.a+a.a<10)
0 9
# correlated subquery, select, while inside the subquery
...
...
@@ -113,6 +131,8 @@ show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY a ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY b ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1
a (select max(a) from t0 b where b.a+a.a<10)
0 9
# correlated subquery, explain, while inside the subquery
...
...
@@ -123,6 +143,8 @@ show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY a ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY b ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1
a (select max(a) from t0 b where b.a+a.a<10)
0 9
# Try to do SHOW EXPLAIN for a query that runs a SET command:
...
...
@@ -168,14 +190,20 @@ show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3
2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3
2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3
2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
a SUBQ
0 0
1 0
...
...
sql/sql_class.cc
View file @
ff40705f
...
...
@@ -3030,14 +3030,20 @@ void Show_explain_request::get_explain_data(void *arg)
//TODO: change mem_root to point to request_thd->mem_root.
// Actually, change the ARENA, because we're going to allocate items!
Query_arena
backup_arena
;
req
->
target_thd
->
set_n_backup_active_arena
((
Query_arena
*
)
req
->
request_thd
,
&
backup_arena
);
THD
*
target_thd
=
req
->
target_thd
;
if
(
req
->
target_thd
->
lex
->
unit
.
print_explain
(
req
->
explain_buf
))
target_thd
->
set_n_backup_active_arena
((
Query_arena
*
)
req
->
request_thd
,
&
backup_arena
);
req
->
query_str
.
copy
(
target_thd
->
query
(),
target_thd
->
query_length
(),
&
my_charset_bin
);
if
(
target_thd
->
lex
->
unit
.
print_explain
(
req
->
explain_buf
))
req
->
failed_to_produce
=
TRUE
;
req
->
target_thd
->
restore_active_arena
((
Query_arena
*
)
req
->
request_thd
,
&
backup_arena
);
target_thd
->
restore_active_arena
((
Query_arena
*
)
req
->
request_thd
,
&
backup_arena
);
}
...
...
sql/sql_class.h
View file @
ff40705f
...
...
@@ -1471,6 +1471,8 @@ public:
select_result_explain_buffer
*
explain_buf
;
String
query_str
;
static
void
get_explain_data
(
void
*
arg
);
};
...
...
sql/sql_show.cc
View file @
ff40705f
...
...
@@ -2126,6 +2126,11 @@ void mysqld_show_explain(THD *thd, ulong thread_id)
"Target is not running EXPLAINable command"
);
bres
=
TRUE
;
}
else
{
push_warning
(
thd
,
MYSQL_ERROR
::
WARN_LEVEL_NOTE
,
ER_YES
,
explain_req
.
query_str
.
c_ptr_safe
());
}
pthread_mutex_unlock
(
&
tmp
->
LOCK_thd_data
);
if
(
!
bres
)
{
...
...
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