diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2015-04-12 04:59:34 +0300 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2015-04-12 04:59:34 +0300 |
commit | 0719df781e5600bceeaaec0e97367f4420a491d0 (patch) | |
tree | 50fd2015cc044edfbf9e64fccfd16d9b5ce1aa18 /sql | |
parent | 4938b822634b173c0d7ef882f721b553b223fadd (diff) | |
parent | 37e87b587396319e607fb8626b6f2a74e66d25a4 (diff) | |
download | mariadb-git-0719df781e5600bceeaaec0e97367f4420a491d0.tar.gz |
Merge
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_delete.cc | 3 | ||||
-rw-r--r-- | sql/sql_explain.cc | 59 | ||||
-rw-r--r-- | sql/sql_explain.h | 8 | ||||
-rw-r--r-- | sql/sql_join_cache.cc | 2 | ||||
-rw-r--r-- | sql/sql_partition.cc | 11 | ||||
-rw-r--r-- | sql/sql_partition.h | 5 | ||||
-rw-r--r-- | sql/sql_select.cc | 5 | ||||
-rw-r--r-- | sql/sql_update.cc | 4 |
8 files changed, 57 insertions, 40 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index b149747649e..b72f552441b 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -121,7 +121,8 @@ void Update_plan::save_explain_data_intern(MEM_ROOT *mem_root, partition_info *part_info; if ((part_info= table->part_info)) { - make_used_partitions_str(part_info, &explain->used_partitions); + make_used_partitions_str(mem_root, part_info, &explain->used_partitions, + explain->used_partitions_list); explain->used_partitions_set= true; } else diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 3c1ebc288ab..89df39c180c 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -37,6 +37,18 @@ Explain_query::Explain_query(THD *thd_arg, MEM_ROOT *root) : { } +static void print_json_array(Json_writer *writer, + const char *title, String_list &list) +{ + List_iterator_fast<char> it(list); + const char *name; + writer->add_member(title).start_array(); + while ((name= it++)) + writer->add_str(name); + writer->end_array(); +} + + Explain_query::~Explain_query() { @@ -1276,17 +1288,9 @@ void add_json_keyset(Json_writer *writer, const char *elem_name, String_list *keyset) { if (!keyset->is_empty()) - { - List_iterator_fast<char> it(*keyset); - const char *name; - writer->add_member(elem_name).start_array(); - while ((name= it++)) - writer->add_str(name); - writer->end_array(); - } + print_json_array(writer, elem_name, *keyset); } - /* @param fs_tracker Normally NULL. When not NULL, it means that the join tab used filesort. @@ -1345,7 +1349,10 @@ void Explain_table_access::print_explain_json(Explain_query *query, writer->add_member("table").start_object(); writer->add_member("table_name").add_str(table_name); - // partitions + + if (used_partitions_set) + print_json_array(writer, "partitions", used_partitions_list); + writer->add_member("access_type").add_str(join_type_str[type]); add_json_keyset(writer, "possible_keys", &possible_keys); @@ -1374,14 +1381,7 @@ void Explain_table_access::print_explain_json(Explain_query *query, parts_list= &key.key_parts_list; if (parts_list && !parts_list->is_empty()) - { - List_iterator_fast<char> it(*parts_list); - const char *name; - writer->add_member("used_key_parts").start_array(); - while ((name= it++)) - writer->add_str(name); - writer->end_array(); - } + print_json_array(writer, "used_key_parts", *parts_list); if (quick_info && !quick_info->is_basic()) { @@ -1392,14 +1392,7 @@ void Explain_table_access::print_explain_json(Explain_query *query, /* `ref` */ if (!ref_list.is_empty()) - { - List_iterator_fast<char> it(ref_list); - const char *str; - writer->add_member("ref").start_array(); - while ((str= it++)) - writer->add_str(str); - writer->end_array(); - } + print_json_array(writer, "ref", ref_list); /* r_loops (not present in tabular output) */ if (is_analyze) @@ -1480,6 +1473,7 @@ void Explain_table_access::print_explain_json(Explain_query *query, writer->end_object(); // "block-nl-join" writer->add_member("buffer_type").add_str(bka_type.incremental? "incremental":"flat"); + writer->add_member("buffer_size").add_size(bka_type.join_buffer_size); writer->add_member("join_type").add_str(bka_type.join_alg); if (bka_type.mrr_type.length()) writer->add_member("mrr_type").add_str(bka_type.mrr_type); @@ -1673,13 +1667,8 @@ void Explain_quick_select::print_json(Json_writer *writer) writer->add_member("range").start_object(); writer->add_member("key").add_str(range.get_key_name()); - - List_iterator_fast<char> it(range.key_parts_list); - const char *name; - writer->add_member("used_key_parts").start_array(); - while ((name= it++)) - writer->add_str(name); - writer->end_array(); + + print_json_array(writer, "used_key_parts", range.key_parts_list); writer->end_object(); } @@ -1990,6 +1979,10 @@ void Explain_update::print_explain_json(Explain_query *query, writer->add_member("delete").add_ll(1); writer->add_member("table_name").add_str(table_name); + + if (used_partitions_set) + print_json_array(writer, "partitions", used_partitions_list); + writer->add_member("access_type").add_str(join_type_str[jtype]); if (!possible_keys.is_empty()) diff --git a/sql/sql_explain.h b/sql/sql_explain.h index 2513e03cf1c..61720ca8d76 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -51,6 +51,9 @@ it into the slow query log. */ +#ifndef SQL_EXPLAIN_INCLUDED +#define SQL_EXPLAIN_INCLUDED + class String_list: public List<char> { public: @@ -471,6 +474,8 @@ class EXPLAIN_BKA_TYPE public: EXPLAIN_BKA_TYPE() : join_alg(NULL) {} + size_t join_buffer_size; + bool incremental; /* @@ -609,6 +614,7 @@ public: /* id and 'select_type' are cared-of by the parent Explain_select */ StringBuffer<32> table_name; StringBuffer<32> used_partitions; + String_list used_partitions_list; // valid with ET_USING_MRR StringBuffer<32> mrr_type; StringBuffer<32> firstmatch_table_name; @@ -732,6 +738,7 @@ public: const char *select_type; StringBuffer<32> used_partitions; + String_list used_partitions_list; bool used_partitions_set; bool impossible_where; @@ -842,3 +849,4 @@ public: }; +#endif //SQL_EXPLAIN_INCLUDED diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index cec0755c9b0..23357ac871d 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -2582,6 +2582,8 @@ void JOIN_CACHE::save_explain_data(EXPLAIN_BKA_TYPE *explain) { explain->incremental= MY_TEST(prev_cache); + explain->join_buffer_size= get_join_buffer_size(); + switch (get_join_alg()) { case BNL_JOIN_ALG: explain->join_alg= "BNL"; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 555ee2a3f40..a930e983dd6 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -68,6 +68,7 @@ // mysql_*_alter_copy_data #include "opt_range.h" // store_key_image_to_rec #include "sql_alter.h" // Alter_table_ctx +#include "sql_select.h" #include <algorithm> using std::max; @@ -7290,8 +7291,10 @@ void mem_alloc_error(size_t size) /** Return comma-separated list of used partitions in the provided given string. + @param mem_root Where to allocate following list @param part_info Partitioning info @param[out] parts The resulting list of string to fill + @param[out] used_partitions_list result list to fill Generate a list of used partitions (from bits in part_info->read_partitions bitmap), and store it into the provided String object. @@ -7302,7 +7305,10 @@ void mem_alloc_error(size_t size) that was written or locked. */ -void make_used_partitions_str(partition_info *part_info, String *parts_str) +void make_used_partitions_str(MEM_ROOT *alloc, + partition_info *part_info, + String *parts_str, + String_list &used_partitions_list) { parts_str->length(0); partition_element *pe; @@ -7321,6 +7327,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str) { if (parts_str->length()) parts_str->append(','); + uint index= parts_str->length(); parts_str->append(head_pe->partition_name, strlen(head_pe->partition_name), system_charset_info); @@ -7328,6 +7335,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str) parts_str->append(pe->partition_name, strlen(pe->partition_name), system_charset_info); + used_partitions_list.append_str(alloc, parts_str->ptr() + index); } partition_id++; } @@ -7341,6 +7349,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str) { if (parts_str->length()) parts_str->append(','); + used_partitions_list.append_str(alloc, pe->partition_name); parts_str->append(pe->partition_name, strlen(pe->partition_name), system_charset_info); } diff --git a/sql/sql_partition.h b/sql/sql_partition.h index 5da132661c9..ff6596fffaa 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -74,6 +74,7 @@ typedef struct { uint32 end_part; } part_id_range; +class String_list; struct st_partition_iter; #define NOT_A_PARTITION_ID UINT_MAX32 @@ -114,7 +115,9 @@ bool mysql_unpack_partition(THD *thd, char *part_buf, TABLE *table, bool is_create_table_ind, handlerton *default_db_type, bool *work_part_info_used); -void make_used_partitions_str(partition_info *part_info, String *parts_str); +void make_used_partitions_str(MEM_ROOT *mem_root, + partition_info *part_info, String *parts_str, + String_list &used_partitions_list); uint32 get_list_array_idx_for_endpoint(partition_info *part_info, bool left_endpoint, bool include_endpoint); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e7c2e91a15c..a49d5b05bdd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -23503,8 +23503,9 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab partition_info *part_info; if (!table->derived_select_number && (part_info= table->part_info)) - { - make_used_partitions_str(part_info, &eta->used_partitions); + { //TODO: all thd->mem_root here should be fixed + make_used_partitions_str(thd->mem_root, part_info, &eta->used_partitions, + eta->used_partitions_list); eta->used_partitions_set= true; } else diff --git a/sql/sql_update.cc b/sql/sql_update.cc index cf6a0f0f140..830d26fd62e 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -517,7 +517,7 @@ int mysql_update(THD *thd, */ if (thd->lex->describe) goto produce_explain_and_leave; - explain= query_plan.save_explain_update_data(thd->mem_root, thd); + explain= query_plan.save_explain_update_data(query_plan.mem_root, thd); ANALYZE_START_TRACKING(&explain->command_tracker); @@ -1052,7 +1052,7 @@ produce_explain_and_leave: We come here for various "degenerate" query plans: impossible WHERE, no-partitions-used, impossible-range, etc. */ - query_plan.save_explain_update_data(thd->mem_root, thd); + query_plan.save_explain_update_data(query_plan.mem_root, thd); emit_explain_and_leave: int err2= thd->lex->explain->send_explain(thd); |