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.txt2
-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.cc64
-rw-r--r--sql/sql_show.h17
-rw-r--r--sql/sql_yacc.yy7
10 files changed, 79 insertions, 20 deletions
diff --git a/sql/handler.h b/sql/handler.h
index fe61666bf20..082000ac234 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -1007,6 +1007,7 @@ enum enum_schema_tables
SCH_ENGINES,
SCH_EVENTS,
SCH_EXPLAIN,
+ SCH_ANALYZE,
SCH_FILES,
SCH_GLOBAL_STATUS,
SCH_GLOBAL_VARIABLES,
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 808e590435a..f02ea57bcba 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -3492,6 +3492,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 f31f21faeb0..cb4f0470b33 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -7224,7 +7224,7 @@ ER_NO_SUCH_TABLE_IN_ENGINE 42S02
hindi "टेबल '%-.192s.%-.192s' इंजन में मौजूद नहीं है"
swe "Det finns ingen tabell som heter '%-.192s.%-.192s' i handlern"
ER_TARGET_NOT_EXPLAINABLE
- eng "Target is not running an EXPLAINable command"
+ eng "Target is not executing an operation with a query plan"
ER_CONNECTION_ALREADY_EXISTS
eng "Connection '%.*s' conflicts with existing connection '%.*s'"
ER_MASTER_LOG_PREFIX
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 641c88de826..dcf6233afb6 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 b9d3eec5a60..613de8105af 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;
@@ -3864,6 +3865,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 d01f84fe7d1..b64b93997a7 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2998,7 +2998,7 @@ 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? */, &printed_anything))
+ is_analyze, &printed_anything))
{
failed_to_produce= TRUE;
}
@@ -3115,16 +3115,13 @@ void select_result_text_buffer::save_to(String *res)
}
-/*
- Store the SHOW EXPLAIN output in the temporary table.
-*/
-
-int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond)
+int fill_show_explain_or_analyze(THD *thd, TABLE_LIST *table, COND *cond,
+ 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();
@@ -3136,10 +3133,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)))
@@ -3159,7 +3156,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;
@@ -3168,6 +3165,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;
@@ -3226,6 +3224,26 @@ int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond)
}
+/*
+ Store the SHOW EXPLAIN output in the temporary table.
+*/
+
+int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond)
+{
+ return fill_show_explain_or_analyze(thd, table, cond, FALSE);
+}
+
+
+/*
+ Store the SHOW ANALYZE output in the temporary table.
+*/
+
+int fill_show_analyze(THD *thd, TABLE_LIST *table, COND *cond)
+{
+ return fill_show_explain_or_analyze(thd, table, cond, TRUE);
+}
+
+
struct processlist_callback_arg
{
processlist_callback_arg(THD *thd_arg, TABLE *table_arg):
@@ -9631,6 +9649,28 @@ ST_FIELD_INFO show_explain_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),
@@ -9693,6 +9733,8 @@ ST_SCHEMA_TABLE schema_tables[]=
#endif
{"EXPLAIN", Show::show_explain_fields_info, 0, fill_show_explain,
make_old_format, 0, -1, -1, TRUE /*hidden*/ , 0},
+ {"ANALYZE", Show::show_analyze_fields_info, 0, fill_show_analyze,
+ 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},
{"GLOBAL_STATUS", Show::variables_fields_info, 0,
diff --git a/sql/sql_show.h b/sql/sql_show.h
index 3d7a4d1146c..89fbcd1a547 100644
--- a/sql/sql_show.h
+++ b/sql/sql_show.h
@@ -155,28 +155,31 @@ 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 */
+ /* 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 442644eddd6..1b1edd4e522 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -13951,6 +13951,13 @@ show_param:
MYSQL_YYABORT;
add_value_to_list(thd, $3);
}
+ | 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;