diff options
Diffstat (limited to 'sql/sql_show.cc')
-rw-r--r-- | sql/sql_show.cc | 64 |
1 files changed, 53 insertions, 11 deletions
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, |