MCPcopy Create free account
hub / github.com/MariaDB/server / alloc_buffer

Method alloc_buffer

sql/sql_join_cache.cc:906–990  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

904*/
905
906int JOIN_CACHE::alloc_buffer()
907{
908 JOIN_TAB *tab;
909 JOIN_CACHE *cache;
910 ulonglong curr_buff_space_sz= 0;
911 ulonglong curr_min_buff_space_sz= 0;
912 ulonglong join_buff_space_limit=
913 join->thd->variables.join_buff_space_limit;
914 bool optimize_buff_size=
915 optimizer_flag(join->thd, OPTIMIZER_SWITCH_OPTIMIZE_JOIN_BUFFER_SIZE);
916 buff= NULL;
917 buff_size= get_max_join_buffer_size(optimize_buff_size, min_buff_size);
918
919 /*
920 Compute the total buffer usage for all join buffers up to
921 and including the current one.
922 */
923 for (tab= first_linear_tab(join, WITHOUT_BUSH_ROOTS, WITHOUT_CONST_TABLES);
924 tab != join_tab;
925 tab= next_linear_tab(join, tab, WITHOUT_BUSH_ROOTS))
926 {
927 cache= tab->cache;
928 if (cache)
929 {
930 curr_min_buff_space_sz+= cache->get_min_join_buffer_size();
931 curr_buff_space_sz+= cache->get_join_buffer_size();
932 }
933 }
934 curr_min_buff_space_sz+= min_buff_size;
935 curr_buff_space_sz+= buff_size;
936
937 if (optimize_buff_size)
938 {
939 /*
940 optimize_join_buffer_size=on used. We should limit the join
941 buffer space to join_buff_space_limit if possible.
942 */
943 if (curr_min_buff_space_sz > join_buff_space_limit)
944 {
945 /*
946 Increase buffer size to minimum needed, to be able to use the
947 join buffer.
948 */
949 join_buff_space_limit= curr_min_buff_space_sz;
950 }
951 if (curr_buff_space_sz > join_buff_space_limit &&
952 join->shrink_join_buffers(join_tab, curr_buff_space_sz,
953 join_buff_space_limit))
954 goto fail; // Fatal error
955 }
956 else if (curr_min_buff_space_sz > buff_size)
957 goto fail;
958
959 if (for_explain_only)
960 return 0;
961
962 for (size_t buff_size_decr= (buff_size-min_buff_size)/4 + 1; ; )
963 {

Callers

nothing calls this directly

Calls 7

optimizer_flagFunction · 0.85
first_linear_tabFunction · 0.85
next_linear_tabFunction · 0.85
my_mallocFunction · 0.85
get_join_buffer_sizeMethod · 0.80
shrink_join_buffersMethod · 0.80

Tested by

no test coverage detected