diff options
author | Igor Babaev <igor@askmonty.org> | 2011-02-04 19:06:35 -0800 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2011-02-04 19:06:35 -0800 |
commit | 4b24105df8c53ad1d432d7033b3e606ae4c24196 (patch) | |
tree | a6d5f824e078e83ed3eb61f1581591a2d271bebf /sql | |
parent | 7e206872128d891fffa5238c093c8d6506da8dbb (diff) | |
download | mariadb-git-4b24105df8c53ad1d432d7033b3e606ae4c24196.tar.gz |
Introduced optimizer switch flag 'optimize_join_buffer_size'.
When this flag is 'off' the size of the used join buffer
is taken directly from the system variable 'join_buffer_size'.
When this flag is 'on' then the size of the buffer depends
on the estimated number of rows in the partial join whose
records are to be stored in the buffer.
By default this flag is set 'on'.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/mysql_priv.h | 13 | ||||
-rw-r--r-- | sql/mysqld.cc | 7 | ||||
-rw-r--r-- | sql/sql_join_cache.cc | 47 | ||||
-rw-r--r-- | sql/sql_join_cache.h | 2 |
4 files changed, 44 insertions, 25 deletions
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index b324a059aad..6ecbb1fe1df 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -580,11 +580,12 @@ protected: #define OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL (1<<16) #define OPTIMIZER_SWITCH_JOIN_CACHE_HASHED (1<<17) #define OPTIMIZER_SWITCH_JOIN_CACHE_BKA (1<<18) +#define OPTIMIZER_SWITCH_OPTIMIZE_JOIN_BUFFER_SIZE (1<<19) #ifdef DBUG_OFF -# define OPTIMIZER_SWITCH_LAST (1<<19) -#else -# define OPTIMIZER_SWITCH_TABLE_ELIMINATION (1<<19) # define OPTIMIZER_SWITCH_LAST (1<<20) +#else +# define OPTIMIZER_SWITCH_TABLE_ELIMINATION (1<<20) +# define OPTIMIZER_SWITCH_LAST (1<<21) #endif #ifdef DBUG_OFF @@ -605,7 +606,8 @@ protected: OPTIMIZER_SWITCH_SUBQUERY_CACHE | \ OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL | \ OPTIMIZER_SWITCH_JOIN_CACHE_HASHED | \ - OPTIMIZER_SWITCH_JOIN_CACHE_BKA) + OPTIMIZER_SWITCH_JOIN_CACHE_BKA | \ + OPTIMIZER_SWITCH_OPTIMIZE_JOIN_BUFFER_SIZE) #else # define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \ OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \ @@ -623,7 +625,8 @@ protected: OPTIMIZER_SWITCH_MRR_SORT_KEYS|\ OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL | \ OPTIMIZER_SWITCH_JOIN_CACHE_HASHED | \ - OPTIMIZER_SWITCH_JOIN_CACHE_BKA) + OPTIMIZER_SWITCH_JOIN_CACHE_BKA | \ + OPTIMIZER_SWITCH_OPTIMIZE_JOIN_BUFFER_SIZE) #endif /* diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 67d4f811efa..7bd16724d22 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -351,6 +351,7 @@ static const char *optimizer_switch_names[]= "join_cache_incremental", "join_cache_hashed", "join_cache_bka", + "optimize_join_buffer_size", #ifndef DBUG_OFF "table_elimination", #endif @@ -379,6 +380,7 @@ static const unsigned int optimizer_switch_names_len[]= sizeof("join_cache_incremental") - 1, sizeof("join_cache_hashed") - 1, sizeof("join_cache_bka") - 1, + sizeof("optimize_join_buffer_size") - 1, #ifndef DBUG_OFF sizeof("table_elimination") - 1, #endif @@ -482,7 +484,8 @@ static const char *optimizer_switch_str="index_merge=on,index_merge_union=on," "mrr_sort_keys=on," "join_cache_incremental=on," "join_cache_hashed=on," - "join_cache_bka=on" + "join_cache_bka=on," + "optimize_join_buffer_size=on" #ifndef DBUG_OFF ",table_elimination=on"; #else @@ -7115,7 +7118,7 @@ thread is in the relay logs.", "The limit of the space for all join buffers used by a query.", &global_system_variables.join_buff_space_limit, &max_system_variables.join_buff_space_limit, 0, GET_ULL, - REQUIRED_ARG, 8*128*1024L, 2048+MALLOC_OVERHEAD, (longlong) ULONGLONG_MAX, + REQUIRED_ARG, 16*128*1024L, 2048+MALLOC_OVERHEAD, (longlong) ULONGLONG_MAX, MALLOC_OVERHEAD, 2048, 0}, {"join_cache_level", OPT_JOIN_CACHE_LEVEL, "Controls what join operations can be executed with join buffers. Odd numbers are used for plain join buffers while even numbers are used for linked buffers", diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 3edf51df64e..294a2845517 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -747,6 +747,7 @@ ulong JOIN_CACHE::get_min_join_buffer_size() avg_aux_buffer_incr= add_sz/min_records; min_sz+= add_sz; min_sz+= pack_length_with_blob_ptrs; + set_if_bigger(min_sz, 1); min_buff_size= min_sz; } return min_buff_size; @@ -759,16 +760,20 @@ ulong JOIN_CACHE::get_min_join_buffer_size() SYNOPSIS get_max_join_buffer_size() + optimize_buff_size FALSE <-> do not take more memory than needed for + the estimated number of records in the partial join + DESCRIPTION At the first its invocation for the cache the function calculates the - maximum possible size of join buffer for the cache. This value does not - exceed the estimate of the number of records 'max_records' in the partial - join that joins tables from the first one through join_tab. This value - is also capped off by the value of join_tab->join_buffer_size_limit, if it - has been set a to non-zero value, and by the value of the system parameter - join_buffer_size - otherwise. After the calculation of the interesting size - the function saves the value in the field 'max_buff_size' in order to use - it directly at the next invocations of the function. + maximum possible size of join buffer for the cache. If the parameter + optimize_buff_size true then this value does not exceed the size of the + space needed for the estimated number of records 'max_records' in the + partial join that joins tables from the first one through join_tab. This + value is also capped off by the value of join_tab->join_buffer_size_limit, + if it has been set a to non-zero value, and by the value of the system + parameter join_buffer_size - otherwise. After the calculation of the + interesting size the function saves the value in the field 'max_buff_size' + in order to use it directly at the next invocations of the function. NOTES Currently the value of join_tab->join_buffer_size_limit is initialized @@ -778,7 +783,7 @@ ulong JOIN_CACHE::get_min_join_buffer_size() The maximum possible size of the join buffer of this cache */ -ulong JOIN_CACHE::get_max_join_buffer_size() +ulong JOIN_CACHE::get_max_join_buffer_size(bool optimize_buff_size) { if (!max_buff_size) { @@ -795,12 +800,17 @@ ulong JOIN_CACHE::get_max_join_buffer_size() ulong limit_sz= join->thd->variables.join_buff_size; if (join_tab->join_buffer_size_limit) set_if_smaller(limit_sz, join_tab->join_buffer_size_limit); - if (limit_sz / max_records > space_per_record) - max_sz= space_per_record * max_records; - else + if (!optimize_buff_size) max_sz= limit_sz; - max_sz+= pack_length_with_blob_ptrs; - set_if_smaller(max_sz, limit_sz); + else + { + if (limit_sz / max_records > space_per_record) + max_sz= space_per_record * max_records; + else + max_sz= limit_sz; + max_sz+= pack_length_with_blob_ptrs; + set_if_smaller(max_sz, limit_sz); + } set_if_bigger(max_sz, min_sz); max_buff_size= max_sz; } @@ -843,6 +853,8 @@ int JOIN_CACHE::alloc_buffer() ulonglong curr_min_buff_space_sz= 0; ulonglong join_buff_space_limit= join->thd->variables.join_buff_space_limit; + bool optimize_buff_size= + optimizer_flag(join->thd, OPTIMIZER_SWITCH_OPTIMIZE_JOIN_BUFFER_SIZE); double partial_join_cardinality= (join_tab-1)->get_partial_join_cardinality(); buff= NULL; min_buff_size= 0; @@ -852,7 +864,7 @@ int JOIN_CACHE::alloc_buffer() (ulonglong) partial_join_cardinality : join_buff_space_limit; set_if_bigger(max_records, 10); min_buff_size= get_min_join_buffer_size(); - buff_size= get_max_join_buffer_size(); + buff_size= get_max_join_buffer_size(optimize_buff_size); for (tab= join->join_tab+join->const_tables; tab <= join_tab; tab++) { cache= tab->cache; @@ -865,8 +877,9 @@ int JOIN_CACHE::alloc_buffer() if (curr_min_buff_space_sz > join_buff_space_limit || (curr_buff_space_sz > join_buff_space_limit && - join->shrink_join_buffers(join_tab, curr_buff_space_sz, - join_buff_space_limit))) + (!optimize_buff_size || + join->shrink_join_buffers(join_tab, curr_buff_space_sz, + join_buff_space_limit)))) goto fail; for (ulong buff_size_decr= (buff_size-min_buff_size)/4 + 1; ; ) diff --git a/sql/sql_join_cache.h b/sql/sql_join_cache.h index 546067fad24..45aded46de4 100644 --- a/sql/sql_join_cache.h +++ b/sql/sql_join_cache.h @@ -583,7 +583,7 @@ public: /* Get the minimum possible size of the cache join buffer */ virtual ulong get_min_join_buffer_size(); /* Get the maximum possible size of the cache join buffer */ - virtual ulong get_max_join_buffer_size(); + virtual ulong get_max_join_buffer_size(bool optimize_buff_size); /* Shrink the size if the cache join buffer in a given ratio */ bool shrink_join_buffer_in_ratio(ulonglong n, ulonglong d); |