diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2019-02-13 11:22:16 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2019-02-13 11:52:36 +0530 |
commit | be8709eb7bdf2a68a1c04fd8ab368113f5f39b63 (patch) | |
tree | 35585804a654ec75089a92e90d546f73e7f60b68 /sql/sql_prepare.cc | |
parent | 6b979416e0e4eac0a036ca5f2b81b748a3d2e680 (diff) | |
download | mariadb-git-be8709eb7bdf2a68a1c04fd8ab368113f5f39b63.tar.gz |
MDEV-6111 Optimizer Trace
This task involves the implementation for the optimizer trace.
This feature produces a trace for any SELECT/UPDATE/DELETE/,
which contains information about decisions taken by the optimizer during
the optimization phase (choice of table access method, various costs,
transformations, etc). This feature would help to tell why some decisions were
taken by the optimizer and why some were rejected.
Trace is session-local, controlled by the @@optimizer_trace variable.
To enable optimizer trace we need to write:
set @@optimizer_trace variable= 'enabled=on';
To display the trace one can run:
SELECT trace FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
This task also involves:
MDEV-18489: Limit the memory used by the optimizer trace
introduces a switch optimizer_trace_max_mem_size which limits
the memory used by the optimizer trace. This was implemented by
Sergei Petrunia.
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r-- | sql/sql_prepare.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index c8cc64dba7e..6c3ad9c6924 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -112,6 +112,7 @@ When one supplies long data for a placeholder: #include "sp_cache.h" #include "sql_handler.h" // mysql_ha_rm_tables #include "probes_mysql.h" +#include "opt_trace.h" #ifdef EMBEDDED_LIBRARY /* include MYSQL_BIND headers */ #include <mysql.h> @@ -2273,6 +2274,17 @@ static bool check_prepared_statement(Prepared_statement *stmt) lex->first_select_lex()->context.resolve_in_table_list_only(select_lex-> get_table_list()); + /* + For the optimizer trace, this is the symmetric, for statement preparation, + of what is done at statement execution (in mysql_execute_command()). + */ + Opt_trace_start ots(thd, tables, lex->sql_command, &lex->var_list, + thd->query(), thd->query_length(), + thd->variables.character_set_client); + + Json_writer_object trace_command(thd); + Json_writer_array trace_command_steps(thd, "steps"); + /* Reset warning count for each query that uses tables */ if (tables) thd->get_stmt_da()->opt_clear_warning_info(thd->query_id); |