From 18fec5128b6fd9712f63e306f03f16833f2599b2 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Tue, 12 Feb 2013 08:20:14 +0400 Subject: EXPLAIN DELETE for MariaDB - Backported the code to 10.0-base - Removed incorrect assert --- sql/sql_select.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 638de926d75..61a72357d84 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1804,6 +1804,28 @@ void eliminate_tables(JOIN *join); /* Index Condition Pushdown entry point function */ void push_index_cond(JOIN_TAB *tab, uint keyno); +/* EXPLAIN-related utility functions */ +int print_explain_message_line(select_result_sink *result, + uint8 options, + uint select_number, + const char *select_type, + const char *message); +void explain_append_mrr_info(QUICK_RANGE_SELECT *quick, String *res); +int print_explain_row(select_result_sink *result, + uint8 options, + uint select_number, + const char *select_type, + const char *table_name, + //const char *partitions, (todo) + enum join_type jtype, + const char *possible_keys, + const char *index, + const char *key_len, + const char *ref, + ha_rows rows, + const char *extra); +void make_possible_keys_line(TABLE *table, key_map possible_keys, String *line); + /**************************************************************************** Temporary table support for SQL Runtime ***************************************************************************/ -- cgit v1.2.1 From 03691a77718c781469b5675c6b03d6064255debb Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Mon, 17 Jun 2013 11:59:38 +0400 Subject: SHOW EXPLAIN UPDATE/DELETE - Introduce "Query Plan Footprints" (abbrev. QPFs) QPF is a part of query plan that is 1. sufficient to produce EXPLAIN output, 2. can be used to produce EXPLAIN output even after its subquery/union was executed and deleted 3. is cheap to save so that we can always save query plans - This patch doesn't fully address #2, we make/save strings for a number of EXPLAIN's columns. This will be fixed. --- sql/sql_select.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 5a3dbccb97f..5ec09fcfcb8 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -198,6 +198,12 @@ int rr_sequential(READ_RECORD *info); int rr_sequential_and_unpack(READ_RECORD *info); +#include "opt_qpf.h" + +/************************************************************************************** + * New EXPLAIN structures END + *************************************************************************************/ + class JOIN_CACHE; class SJ_TMP_TABLE; class JOIN_TAB_RANGE; @@ -252,7 +258,9 @@ typedef struct st_join_table { JOIN_TAB_RANGE *bush_children; /* Special content for EXPLAIN 'Extra' column or NULL if none */ - const char *info; + enum Extra_tag info; + //const char *info; + /* Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra' column, or 0 if there is no info. @@ -1454,11 +1462,14 @@ public: { return (unit->item && unit->item->is_in_predicate()); } - +/* int print_explain(select_result_sink *result, uint8 explain_flags, bool on_the_fly, bool need_tmp_table, bool need_order, bool distinct,const char *message); +*/ + int save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, + bool distinct, const char *message); private: /** TRUE if the query contains an aggregate function but has no GROUP -- cgit v1.2.1 From ab4a13b2b91e260d8c75a3c41b7ff5c24747cee0 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Thu, 20 Jun 2013 22:30:30 +0400 Subject: Switching [EXPLAIN] UPDATE/DELETE to rely on query plan footprints. This requires that subselect's footprints are saved before it is deleted. Attempt to save select's QPF exposes one to a variety of edge cases: - the select may be a UNION's "fake select" which has no valid id - optimization may fail in the middle (but subsequent JOIN::optimize() calls will succeed, despite the fact that there never was a query plan) --- sql/sql_select.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 5ec09fcfcb8..6d4dfed479e 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1462,12 +1462,6 @@ public: { return (unit->item && unit->item->is_in_predicate()); } -/* - int print_explain(select_result_sink *result, uint8 explain_flags, - bool on_the_fly, - bool need_tmp_table, bool need_order, - bool distinct,const char *message); -*/ int save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, bool distinct, const char *message); private: -- cgit v1.2.1 From 8b7bbcf4dca77690091360e5ae7d011fb74554d6 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Thu, 27 Jun 2013 16:41:12 +0400 Subject: [SHOW] EXPLAIN UPDATE/DELETE, code re-structuring - Make query plan be re-saved after the first join execution (saving it after JOIN::cleanup is too late because EXPLAIN output is currently produced before that) - Handle QPF allocation/deallocation for edge cases, like unsuccessful BINLOG command. - Work around the problem with UNION's direct subselects not being visible. - Update test results ("Using temporary; Using filesort" are now always printed last in the Extra column) - This cset gets rid of memory leaks/crashes. Some result mismatches still remain. --- sql/sql_select.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sql/sql_select.h') diff --git a/sql/sql_select.h b/sql/sql_select.h index 6d4dfed479e..b394ee40276 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1336,7 +1336,10 @@ public: pre_sort_join_tab= NULL; emb_sjm_nest= NULL; sjm_lookup_tables= 0; + + exec_qpf_saved= false; } + bool exec_qpf_saved; int prepare(Item ***rref_pointer_array, TABLE_LIST *tables, uint wind_num, COND *conds, uint og_num, ORDER *order, ORDER *group, -- cgit v1.2.1