summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/handler.h1
-rw-r--r--sql/mysqld.cc1
-rw-r--r--sql/privilege.h1
-rw-r--r--sql/share/errmsg-utf8.txt4
-rw-r--r--sql/sp_head.cc1
-rw-r--r--sql/sql_cmd.h3
-rw-r--r--sql/sql_parse.cc2
-rw-r--r--sql/sql_show.cc65
-rw-r--r--sql/sql_show.h19
-rw-r--r--sql/sql_yacc.yy7
10 files changed, 81 insertions, 23 deletions
diff --git a/sql/handler.h b/sql/handler.h
index c21080f3815..a4c54b3a260 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -1025,6 +1025,7 @@ enum enum_schema_tables
SCH_EVENTS,
SCH_EXPLAIN_TABULAR,
SCH_EXPLAIN_JSON,
+ SCH_ANALYZE,
SCH_FILES,
SCH_GLOBAL_STATUS,
SCH_GLOBAL_VARIABLES,
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 9c75564d7dd..00a7b23b085 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -3507,6 +3507,7 @@ SHOW_VAR com_status_vars[]= {
{"show_errors", STMT_STATUS(SQLCOM_SHOW_ERRORS)},
{"show_events", STMT_STATUS(SQLCOM_SHOW_EVENTS)},
{"show_explain", STMT_STATUS(SQLCOM_SHOW_EXPLAIN)},
+ {"show_analyze", STMT_STATUS(SQLCOM_SHOW_ANALYZE)},
{"show_fields", STMT_STATUS(SQLCOM_SHOW_FIELDS)},
#ifndef DBUG_OFF
{"show_function_code", STMT_STATUS(SQLCOM_SHOW_FUNC_CODE)},
diff --git a/sql/privilege.h b/sql/privilege.h
index c1233102522..7676a9ac5e0 100644
--- a/sql/privilege.h
+++ b/sql/privilege.h
@@ -634,6 +634,7 @@ constexpr privilege_t PRIV_STMT_DROP_SERVER= FEDERATED_ADMIN_ACL | SUPER_ACL;
/* Privileges related to processes */
constexpr privilege_t PRIV_COM_PROCESS_INFO= PROCESS_ACL;
+// This privilege applies both for SHOW EXPLAIN and SHOW ANALYZE
constexpr privilege_t PRIV_STMT_SHOW_EXPLAIN= PROCESS_ACL;
constexpr privilege_t PRIV_STMT_SHOW_ENGINE_STATUS= PROCESS_ACL;
constexpr privilege_t PRIV_STMT_SHOW_ENGINE_MUTEX= PROCESS_ACL;
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 5ec1ba3d0a8..94cfd41c799 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -8725,9 +8725,9 @@ ER_NO_SUCH_TABLE_IN_ENGINE 42S02
spa "La tabla '%-.192s.%-.192s' no existe en el motor"
swe "Det finns ingen tabell som heter '%-.192s.%-.192s' i handlern"
ER_TARGET_NOT_EXPLAINABLE
+ eng "Target is not executing an operation with a query plan"
chi "目标未运行可解释的命令"
- eng "Target is not running an EXPLAINable command"
- spa "El objetivo no está ejecutando un comando EXPLAINable"
+ spa "El objetivo no está ejecutando una operación con un plan de consulta (query)"
ER_CONNECTION_ALREADY_EXISTS
chi "连接'%.*s'与现有连接'%.*s'冲突"
eng "Connection '%.*s' conflicts with existing connection '%.*s'"
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index baf4d7d1d82..fab72fd0c6f 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -221,6 +221,7 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_SHOW_DATABASES:
case SQLCOM_SHOW_ERRORS:
case SQLCOM_SHOW_EXPLAIN:
+ case SQLCOM_SHOW_ANALYZE:
case SQLCOM_SHOW_FIELDS:
case SQLCOM_SHOW_FUNC_CODE:
case SQLCOM_SHOW_GENERIC:
diff --git a/sql/sql_cmd.h b/sql/sql_cmd.h
index 430afadb491..1a01caa77dd 100644
--- a/sql/sql_cmd.h
+++ b/sql/sql_cmd.h
@@ -88,7 +88,8 @@ enum enum_sql_command {
SQLCOM_SHOW_RELAYLOG_EVENTS,
SQLCOM_GET_DIAGNOSTICS,
SQLCOM_SLAVE_ALL_START, SQLCOM_SLAVE_ALL_STOP,
- SQLCOM_SHOW_EXPLAIN, SQLCOM_SHUTDOWN,
+ SQLCOM_SHOW_EXPLAIN,
+ SQLCOM_SHOW_ANALYZE, SQLCOM_SHUTDOWN,
SQLCOM_CREATE_ROLE, SQLCOM_DROP_ROLE, SQLCOM_GRANT_ROLE, SQLCOM_REVOKE_ROLE,
SQLCOM_COMPOUND,
SQLCOM_SHOW_GENERIC,
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 677f5b614ad..b7b5d0492ab 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -665,6 +665,7 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_SHOW_ENGINE_MUTEX]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_ENGINE_LOGS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_EXPLAIN]= CF_STATUS_COMMAND;
+ sql_command_flags[SQLCOM_SHOW_ANALYZE]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_PROCESSLIST]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_GRANTS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_CREATE_USER]= CF_STATUS_COMMAND;
@@ -3879,6 +3880,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
break;
}
case SQLCOM_SHOW_EXPLAIN:
+ case SQLCOM_SHOW_ANALYZE:
{
if (!thd->security_ctx->priv_user[0] &&
check_global_access(thd, PRIV_STMT_SHOW_EXPLAIN))
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 2603cea6f55..7fa55913262 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -3000,8 +3000,8 @@ void Show_explain_request::call_in_target_thread()
DBUG_ASSERT(current_thd == target_thd);
set_current_thd(request_thd);
if (target_thd->lex->print_explain(explain_buf, 0 /* explain flags*/,
- false /*TODO: analyze? */,
- is_json_format, &printed_anything))
+ is_analyze, is_json_format,
+ &printed_anything))
{
failed_to_produce= TRUE;
}
@@ -3119,16 +3119,16 @@ void select_result_text_buffer::save_to(String *res)
/*
- Store the SHOW EXPLAIN output in the temporary table.
+ Store the SHOW EXPLAIN/SHOW ANALYZE output in the temporary table.
*/
-int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond,
- bool json_format)
+int fill_show_explain_or_analyze(THD *thd, TABLE_LIST *table, COND *cond,
+ bool json_format, bool is_analyze)
{
const char *calling_user;
THD *tmp;
my_thread_id thread_id;
- DBUG_ENTER("fill_show_explain");
+ DBUG_ENTER("fill_show_explain_or_analyze");
DBUG_ASSERT(cond==NULL);
thread_id= thd->lex->value_list.head()->val_int();
@@ -3140,10 +3140,10 @@ int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond,
Security_context *tmp_sctx= tmp->security_ctx;
/*
If calling_user==NULL, calling thread has SUPER or PROCESS
- privilege, and so can do SHOW EXPLAIN on any user.
+ privilege, and so can do SHOW EXPLAIN/SHOW ANALYZE on any user.
- if calling_user!=NULL, he's only allowed to view SHOW EXPLAIN on
- his own threads.
+ if calling_user!=NULL, he's only allowed to view
+ SHOW EXPLAIN/SHOW ANALYZE on his own threads.
*/
if (calling_user && (!tmp_sctx->user || strcmp(calling_user,
tmp_sctx->user)))
@@ -3163,7 +3163,7 @@ int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond,
bool bres;
/*
Ok we've found the thread of interest and it won't go away because
- we're holding its LOCK_thd_kill. Post it a SHOW EXPLAIN request.
+ we're holding its LOCK_thd_kill. Post it a SHOW EXPLAIN/SHOW ANALYZE request.
*/
bool timed_out;
int timeout_sec= 30;
@@ -3173,6 +3173,7 @@ int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond,
explain_buf= new select_result_explain_buffer(thd, table->table);
+ explain_req.is_analyze= is_analyze;
explain_req.explain_buf= explain_buf;
explain_req.target_thd= tmp;
explain_req.request_thd= thd;
@@ -3233,13 +3234,28 @@ int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond,
int fill_show_explain_tabular(THD *thd, TABLE_LIST *table, COND *cond)
{
- return fill_show_explain(thd, table, cond, false /*json_format*/);
+ return fill_show_explain_or_analyze(
+ thd, table, cond, FALSE /* json_format */, FALSE /* is_analyze */);
}
int fill_show_explain_json(THD *thd, TABLE_LIST *table, COND *cond)
{
- return fill_show_explain(thd, table, cond, true /*json_format*/);
+ return fill_show_explain_or_analyze(
+ thd, table, cond, TRUE /* json_format */, TRUE /* is_analyze */);
+
+
+int fill_show_analyze_tabular(THD * thd, TABLE_LIST * table, COND * cond)
+{
+ return fill_show_explain_or_analyze(
+ thd, table, cond, FALSE /* json_format */, TRUE /* is_analyze */);
+}
+
+
+int fill_show_analyze_json(THD * thd, TABLE_LIST * table, COND * cond)
+{
+ return fill_show_explain_or_analyze(
+ thd, table, cond, TRUE /* json_format */, TRUE /* is_analyze */);
}
@@ -9660,6 +9676,29 @@ ST_FIELD_INFO show_explain_json_fields_info[]=
};
+ST_FIELD_INFO show_analyze_fields_info[]=
+{
+ Column("id", SLonglong(3), NULLABLE, "id"),
+ Column("select_type", Varchar(19), NOT_NULL, "select_type"),
+ Column("table", Name(), NULLABLE, "table"),
+ Column("type", Varchar(15), NULLABLE, "type"),
+ Column("possible_keys",Varchar(NAME_CHAR_LEN*MAX_KEY), NULLABLE, "possible_keys"),
+ Column("key", Varchar(NAME_CHAR_LEN*MAX_KEY), NULLABLE, "key"),
+ Column("key_len", Varchar(NAME_CHAR_LEN*MAX_KEY), NULLABLE, "key_len"),
+ Column("ref", Varchar(NAME_CHAR_LEN*MAX_REF_PARTS),NULLABLE, "ref"),
+ Column("rows", SLonglong(10), NULLABLE, "rows"),
+ Column("r_rows", Varchar(NAME_CHAR_LEN), NULLABLE, "r_rows"),
+
+ /* Fields of type DECIMAL(5,2) to represent percentage.
+ See Show::Type::decimal_precision() and Show::Type::decimal_scale() to learn
+ how 502 converts to precision and scale (5 and 2)*/
+ Column("filtered", Decimal(502), NULLABLE, "filtered"),
+ Column("r_filtered", Decimal(502), NULLABLE, "r_filtered"),
+ Column("Extra", Varchar(255), NOT_NULL, "Extra"),
+ CEnd()
+};
+
+
ST_FIELD_INFO check_constraints_fields_info[]=
{
Column("CONSTRAINT_CATALOG", Catalog(), NOT_NULL, OPEN_FULL_TABLE),
@@ -9723,6 +9762,8 @@ ST_SCHEMA_TABLE schema_tables[]=
{"EXPLAIN", Show::show_explain_tabular_fields_info, 0, fill_show_explain_tabular,
make_old_format, 0, -1, -1, TRUE /*hidden*/ , 0},
{"EXPLAIN_JSON", Show::show_explain_json_fields_info, 0, fill_show_explain_json,
+ make_old_format, 0, -1, -1, TRUE /*hidden*/, 0},
+ {"ANALYZE", Show::show_analyze_fields_info, 0, fill_show_analyze_tabular,
make_old_format, 0, -1, -1, TRUE /*hidden*/, 0},
{"FILES", Show::files_fields_info, 0,
hton_fill_schema_table, 0, 0, -1, -1, 0, 0},
diff --git a/sql/sql_show.h b/sql/sql_show.h
index ccdfca50ac2..9a269b49f11 100644
--- a/sql/sql_show.h
+++ b/sql/sql_show.h
@@ -155,34 +155,37 @@ THD *find_thread_by_id(longlong id, bool query_id= false);
class select_result_explain_buffer;
/*
- SHOW EXPLAIN request object.
+ SHOW EXPLAIN/SHOW ANALYZE request object.
*/
class Show_explain_request : public Apc_target::Apc_call
{
public:
- THD *target_thd; /* thd that we're running SHOW EXPLAIN for */
- THD *request_thd; /* thd that run SHOW EXPLAIN command */
-
+ THD *target_thd; /* thd that we're running SHOW EXPLAIN/ANALYZE for */
+ THD *request_thd; /* thd that run SHOW EXPLAIN/ANALYZE command */
+
/*
Set to TRUE if you need the result in JSON format,
FALSE - in traditional tabular
*/
bool is_json_format= false;
+ /* FALSE for SHOW EXPLAIN, TRUE - for SHOW ANALYZE*/
+ bool is_analyze;
+
/* If true, there was some error when producing EXPLAIN output. */
bool failed_to_produce;
- /* SHOW EXPLAIN will be stored here */
+ /* SHOW EXPLAIN/ANALYZE will be stored here */
select_result_explain_buffer *explain_buf;
- /* Query that we've got SHOW EXPLAIN for */
+ /* Query that we've got SHOW EXPLAIN/ANALYZE for */
String query_str;
- /* Overloaded virtual function */
- void call_in_target_thread();
+ void call_in_target_thread() override;
};
+
/**
Condition pushdown used for INFORMATION_SCHEMA / SHOW queries.
This structure is to implement an optimization when
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index b3abdf158dd..b81a4ad606c 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -13948,6 +13948,13 @@ show_param:
MYSQL_YYABORT;
add_value_to_list(thd, $4);
}
+ | ANALYZE_SYM FOR_SYM expr
+ {
+ Lex->sql_command= SQLCOM_SHOW_ANALYZE;
+ if (unlikely(prepare_schema_table(thd, Lex, 0, SCH_ANALYZE)))
+ MYSQL_YYABORT;
+ add_value_to_list(thd, $3);
+ }
| IDENT_sys remember_tok_start wild_and_where
{
LEX *lex= Lex;