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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
5621aa32
Commit
5621aa32
authored
Jun 03, 2014
by
Sergei Petrunia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-406: ANALYZE $stmt
- Support tracking for UNIONs, temporary-table based ORDER BYs, and both.
parent
0925ab9d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
17 deletions
+79
-17
mysql-test/r/ps.result
mysql-test/r/ps.result
+1
-0
mysql-test/t/ps.test
mysql-test/t/ps.test
+1
-0
sql/sql_explain.cc
sql/sql_explain.cc
+3
-3
sql/sql_explain.h
sql/sql_explain.h
+38
-9
sql/sql_select.cc
sql/sql_select.cc
+35
-4
sql/sql_select.h
sql/sql_select.h
+1
-1
No files found.
mysql-test/r/ps.result
View file @
5621aa32
call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.');
call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.');
drop table if exists t1,t2,t3,t4;
drop table if exists t1,t2,t3,t4;
drop database if exists mysqltest1;
drop database if exists client_test_db;
drop database if exists client_test_db;
create table t1
create table t1
(
(
...
...
mysql-test/t/ps.test
View file @
5621aa32
...
@@ -7,6 +7,7 @@ call mtr.add_suppression('Unsafe statement written to the binary log using state
...
@@ -7,6 +7,7 @@ call mtr.add_suppression('Unsafe statement written to the binary log using state
--
disable_warnings
--
disable_warnings
drop
table
if
exists
t1
,
t2
,
t3
,
t4
;
drop
table
if
exists
t1
,
t2
,
t3
,
t4
;
drop
database
if
exists
mysqltest1
;
# Avoid wrong warnings if mysql_client_test fails
# Avoid wrong warnings if mysql_client_test fails
drop
database
if
exists
client_test_db
;
drop
database
if
exists
client_test_db
;
--
enable_warnings
--
enable_warnings
...
...
sql/sql_explain.cc
View file @
5621aa32
...
@@ -542,7 +542,7 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
...
@@ -542,7 +542,7 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
/* `r_rows` */
/* `r_rows` */
if
(
is_analyze
)
if
(
is_analyze
)
{
{
ha_rows
avg_rows
=
r_scans
?
round
((
double
)
r_rows
/
r_scans
)
:
0
;
ha_rows
avg_rows
=
tracker
.
r_scans
?
round
((
double
)
tracker
.
r_rows
/
tracker
.
r_scans
)
:
0
;
item_list
.
push_back
(
new
Item_int
((
longlong
)
(
ulonglong
)
avg_rows
,
item_list
.
push_back
(
new
Item_int
((
longlong
)
(
ulonglong
)
avg_rows
,
MY_INT64_NUM_DECIMAL_DIGITS
));
MY_INT64_NUM_DECIMAL_DIGITS
));
}
}
...
@@ -562,8 +562,8 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
...
@@ -562,8 +562,8 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
if
(
is_analyze
)
if
(
is_analyze
)
{
{
double
r_filtered
;
double
r_filtered
;
if
(
r_rows
>
0
)
if
(
tracker
.
r_rows
>
0
)
r_filtered
=
100.0
*
(
double
)
r_rows_after_table_cond
/
r_rows
;
r_filtered
=
100.0
*
(
double
)
tracker
.
r_rows_after_table_cond
/
tracker
.
r_rows
;
else
else
r_filtered
=
100.0
;
r_filtered
=
100.0
;
item_list
.
push_back
(
new
Item_float
(
r_filtered
,
2
));
item_list
.
push_back
(
new
Item_float
(
r_filtered
,
2
));
...
...
sql/sql_explain.h
View file @
5621aa32
...
@@ -14,6 +14,21 @@
...
@@ -14,6 +14,21 @@
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Data structures for ANALYZE */
class
Table_access_tracker
{
public:
Table_access_tracker
()
:
r_scans
(
0
),
r_rows
(
0
),
r_rows_after_table_cond
(
0
),
r_rows_after_where
(
0
)
{}
ha_rows
r_scans
;
/* How many scans were ran on this join_tab */
ha_rows
r_rows
;
/* How many rows we've got after that */
ha_rows
r_rows_after_table_cond
;
/* Rows after applying the table condition */
ha_rows
r_rows_after_where
;
/* Rows after applying attached part of WHERE */
};
/**************************************************************************************
/**************************************************************************************
...
@@ -135,6 +150,13 @@ class Explain_select : public Explain_node
...
@@ -135,6 +150,13 @@ class Explain_select : public Explain_node
int
print_explain
(
Explain_query
*
query
,
select_result_sink
*
output
,
int
print_explain
(
Explain_query
*
query
,
select_result_sink
*
output
,
uint8
explain_flags
,
bool
is_analyze
);
uint8
explain_flags
,
bool
is_analyze
);
Table_access_tracker
*
get_using_temporary_read_tracker
()
{
return
&
using_temporary_read_tracker
;
}
private:
Table_access_tracker
using_temporary_read_tracker
;
};
};
...
@@ -176,6 +198,19 @@ class Explain_union : public Explain_node
...
@@ -176,6 +198,19 @@ class Explain_union : public Explain_node
const
char
*
fake_select_type
;
const
char
*
fake_select_type
;
bool
using_filesort
;
bool
using_filesort
;
Table_access_tracker
*
get_fake_select_lex_tracker
()
{
return
&
fake_select_lex_tracker
;
}
Table_access_tracker
*
get_tmptable_read_tracker
()
{
return
&
tmptable_read_tracker
;
}
private:
Table_access_tracker
fake_select_lex_tracker
;
/* This one is for reading after ORDER BY */
Table_access_tracker
tmptable_read_tracker
;
};
};
...
@@ -183,6 +218,7 @@ class Explain_update;
...
@@ -183,6 +218,7 @@ class Explain_update;
class
Explain_delete
;
class
Explain_delete
;
class
Explain_insert
;
class
Explain_insert
;
/*
/*
Explain structure for a query (i.e. a statement).
Explain structure for a query (i.e. a statement).
...
@@ -389,6 +425,7 @@ class Explain_quick_select : public Sql_alloc
...
@@ -389,6 +425,7 @@ class Explain_quick_select : public Sql_alloc
/*
/*
EXPLAIN data structure for a single JOIN_TAB.
EXPLAIN data structure for a single JOIN_TAB.
*/
*/
class
Explain_table_access
:
public
Sql_alloc
class
Explain_table_access
:
public
Sql_alloc
{
{
public:
public:
...
@@ -467,15 +504,7 @@ class Explain_table_access : public Sql_alloc
...
@@ -467,15 +504,7 @@ class Explain_table_access : public Sql_alloc
bool
using_temporary
,
bool
using_filesort
);
bool
using_temporary
,
bool
using_filesort
);
/* ANALYZE members*/
/* ANALYZE members*/
ha_rows
r_scans
;
/* How many scans were ran on this join_tab */
Table_access_tracker
tracker
;
ha_rows
r_rows
;
/* How many rows we've got after that */
ha_rows
r_rows_after_table_cond
;
/* Rows after applying the table condition */
ha_rows
r_rows_after_where
;
/* Rows after applying attached part of WHERE */
Explain_table_access
()
:
r_scans
(
0
),
r_rows
(
0
),
r_rows_after_table_cond
(
0
),
r_rows_after_where
(
0
)
{}
private:
private:
void
append_tag_name
(
String
*
str
,
enum
explain_extra_tag
tag
);
void
append_tag_name
(
String
*
str
,
enum
explain_extra_tag
tag
);
...
...
sql/sql_select.cc
View file @
5621aa32
...
@@ -1032,6 +1032,9 @@ int JOIN::optimize()
...
@@ -1032,6 +1032,9 @@ int JOIN::optimize()
subquery), returns 1
subquery), returns 1
- another JOIN::optimize() call made, and now join->optimize() will
- another JOIN::optimize() call made, and now join->optimize() will
return 0, even though we never had a query plan.
return 0, even though we never had a query plan.
Can have QEP_NOT_PRESENT_YET for degenerate queries (for example,
SELECT * FROM tbl LIMIT 0)
*/
*/
if
(
was_optimized
!=
optimized
&&
!
res
&&
have_query_plan
!=
QEP_DELETED
)
if
(
was_optimized
!=
optimized
&&
!
res
&&
have_query_plan
!=
QEP_DELETED
)
{
{
...
@@ -2350,6 +2353,20 @@ void JOIN::save_explain_data(Explain_query *output, bool can_overwrite,
...
@@ -2350,6 +2353,20 @@ void JOIN::save_explain_data(Explain_query *output, bool can_overwrite,
}
}
save_explain_data_intern
(
thd
->
lex
->
explain
,
need_tmp_table
,
need_order
,
save_explain_data_intern
(
thd
->
lex
->
explain
,
need_tmp_table
,
need_order
,
distinct
,
message
);
distinct
,
message
);
return
;
}
/*
Can have join_tab==NULL for degenerate cases (e.g. SELECT .. UNION ... SELECT LIMIT 0)
*/
if
(
select_lex
==
select_lex
->
master_unit
()
->
fake_select_lex
&&
join_tab
)
{
/*
This is fake_select_lex. It has no query plan, but we need to set up a
tracker for ANALYZE
*/
Explain_union
*
eu
=
output
->
get_union
(
select_lex
->
master_unit
()
->
first_select
()
->
select_number
);
join_tab
[
0
].
tracker
=
eu
->
get_fake_select_lex_tracker
();
}
}
}
}
...
@@ -8958,6 +8975,20 @@ JOIN::make_simple_join(JOIN *parent, TABLE *temp_table)
...
@@ -8958,6 +8975,20 @@ JOIN::make_simple_join(JOIN *parent, TABLE *temp_table)
join_tab
->
read_first_record
=
join_init_read_record
;
join_tab
->
read_first_record
=
join_init_read_record
;
join_tab
->
join
=
this
;
join_tab
->
join
=
this
;
join_tab
->
ref
.
key_parts
=
0
;
join_tab
->
ref
.
key_parts
=
0
;
uint
select_nr
=
select_lex
->
select_number
;
if
(
select_nr
==
INT_MAX
)
{
/* this is a fake_select_lex of a union */
select_nr
=
select_lex
->
master_unit
()
->
first_select
()
->
select_number
;
join_tab
->
tracker
=
thd
->
lex
->
explain
->
get_union
(
select_nr
)
->
get_tmptable_read_tracker
();
}
else
{
join_tab
->
tracker
=
thd
->
lex
->
explain
->
get_select
(
select_nr
)
->
get_using_temporary_read_tracker
();
}
bzero
((
char
*
)
&
join_tab
->
read_record
,
sizeof
(
join_tab
->
read_record
));
bzero
((
char
*
)
&
join_tab
->
read_record
,
sizeof
(
join_tab
->
read_record
));
temp_table
->
status
=
0
;
temp_table
->
status
=
0
;
temp_table
->
null_row
=
0
;
temp_table
->
null_row
=
0
;
...
@@ -17532,7 +17563,7 @@ sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
...
@@ -17532,7 +17563,7 @@ sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
(
*
join_tab
->
next_select
)(
join
,
join_tab
+
1
,
end_of_records
);
(
*
join_tab
->
next_select
)(
join
,
join_tab
+
1
,
end_of_records
);
DBUG_RETURN
(
nls
);
DBUG_RETURN
(
nls
);
}
}
join_tab
->
explain
->
r_scans
++
;
join_tab
->
tracker
->
r_scans
++
;
int
error
;
int
error
;
enum_nested_loop_state
rc
=
NESTED_LOOP_OK
;
enum_nested_loop_state
rc
=
NESTED_LOOP_OK
;
...
@@ -17669,7 +17700,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
...
@@ -17669,7 +17700,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
DBUG_RETURN
(
NESTED_LOOP_KILLED
);
/* purecov: inspected */
DBUG_RETURN
(
NESTED_LOOP_KILLED
);
/* purecov: inspected */
}
}
join_tab
->
explain
->
r_rows
++
;
join_tab
->
tracker
->
r_rows
++
;
if
(
join_tab
->
table
->
vfield
)
if
(
join_tab
->
table
->
vfield
)
update_virtual_fields
(
join
->
thd
,
join_tab
->
table
);
update_virtual_fields
(
join
->
thd
,
join_tab
->
table
);
...
@@ -17689,7 +17720,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
...
@@ -17689,7 +17720,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
There is no select condition or the attached pushed down
There is no select condition or the attached pushed down
condition is true => a match is found.
condition is true => a match is found.
*/
*/
join_tab
->
explain
->
r_rows_after_table_cond
++
;
join_tab
->
tracker
->
r_rows_after_table_cond
++
;
bool
found
=
1
;
bool
found
=
1
;
while
(
join_tab
->
first_unmatched
&&
found
)
while
(
join_tab
->
first_unmatched
&&
found
)
{
{
...
@@ -23315,7 +23346,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
...
@@ -23315,7 +23346,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
eta
->
key
.
set
(
thd
->
mem_root
,
NULL
,
(
uint
)
-
1
);
eta
->
key
.
set
(
thd
->
mem_root
,
NULL
,
(
uint
)
-
1
);
eta
->
quick_info
=
NULL
;
eta
->
quick_info
=
NULL
;
tab
->
explain
=
eta
;
tab
->
tracker
=
&
eta
->
tracker
;
/* id */
/* id */
if
(
tab
->
bush_root_tab
)
if
(
tab
->
bush_root_tab
)
...
...
sql/sql_select.h
View file @
5621aa32
...
@@ -251,7 +251,7 @@ typedef struct st_join_table {
...
@@ -251,7 +251,7 @@ typedef struct st_join_table {
/* Special content for EXPLAIN 'Extra' column or NULL if none */
/* Special content for EXPLAIN 'Extra' column or NULL if none */
enum
explain_extra_tag
info
;
enum
explain_extra_tag
info
;
Explain_table_access
*
explain
;
Table_access_tracker
*
tracker
;
/*
/*
Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
column, or 0 if there is no info.
column, or 0 if there is no info.
...
...
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