From 31569172ee204a74bbecbd65d35d7b7c56025297 Mon Sep 17 00:00:00 2001 From: "jcole@tetra.spaceapes.com" <> Date: Sat, 27 Jan 2001 03:24:05 -0600 Subject: [PATCH] Added --temp-pool option to mysqld. This will cause temporary files created to use a small set of filenames, to try and avoid problems in the Linux kernel. --- include/my_bitmap.h | 35 ++++++++++++++++++++++++++ mysys/Makefile.am | 2 +- mysys/my_bitmap.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ mysys/my_init.c | 10 +++++++- mysys/mysys_priv.h | 1 + sql/mysql_priv.h | 4 ++- sql/mysqld.cc | 14 ++++++++++- sql/sql_select.cc | 29 +++++++++++++++++++--- sql/table.h | 2 ++ 9 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 include/my_bitmap.h create mode 100644 mysys/my_bitmap.c diff --git a/include/my_bitmap.h b/include/my_bitmap.h new file mode 100644 index 00000000000..6c86a79fe45 --- /dev/null +++ b/include/my_bitmap.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#ifndef _my_bitmap_h_ +#define _my_bitmap_h_ + +#define MY_BIT_NONE ~(uint)0 + +#ifdef __cplusplus +extern "C" { +#endif + + extern void bitmap_set_bit(uchar *bitmap, uint bitmap_size, uint bitmap_bit); + extern uint bitmap_set_next(uchar *bitmap, uint bitmap_size); + extern void bitmap_clear_bit(uchar *bitmap,uint bitmap_size,uint bitmap_bit); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 7615b85fa29..6674132bdca 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -44,7 +44,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\ my_quick.c my_lockmem.c my_static.c \ getopt.c getopt1.c getvar.c my_mkdir.c \ default.c my_compress.c checksum.c raid.cc my_net.c \ - my_vsnprintf.c charset.c + my_vsnprintf.c charset.c my_bitmap.c EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \ thr_mutex.c thr_rwlock.c libmysys_a_LIBADD = @THREAD_LOBJECTS@ diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c new file mode 100644 index 00000000000..1434f472f98 --- /dev/null +++ b/mysys/my_bitmap.c @@ -0,0 +1,60 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +/* + Handling of uchar arrays as large bitmaps. +*/ + +#include "mysys_priv.h" +#include + +pthread_mutex_t LOCK_bitmap; + +void bitmap_set_bit(uchar *bitmap, uint bitmap_size, uint bitmap_bit) { + if((bitmap_bit != MY_BIT_NONE) && (bitmap_bit < bitmap_size*8)) { + pthread_mutex_lock(&LOCK_bitmap); + bitmap[bitmap_bit / 8] |= (1 << bitmap_bit % 8); + pthread_mutex_unlock(&LOCK_bitmap); + }; +}; + +uint bitmap_set_next(uchar *bitmap, uint bitmap_size) { + uint bit_found = MY_BIT_NONE; + int i, b; + + pthread_mutex_lock(&LOCK_bitmap); + for(i=0; (i threads,thread_cache; time_t start_time; +uchar temp_pool[TEMP_POOL_SIZE]; +bool use_temp_pool; + pthread_key(MEM_ROOT*,THR_MALLOC); pthread_key(THD*, THR_THD); pthread_key(NET*, THR_NET); @@ -1498,6 +1501,9 @@ int main(int argc, char **argv) if (!mysql_tmpdir || !mysql_tmpdir[0]) mysql_tmpdir=(char*) P_tmpdir; /* purecov: inspected */ + bzero(temp_pool, TEMP_POOL_SIZE); + use_temp_pool = 0; + set_options(); #ifdef __WIN__ /* service parameters can be overwritten by options */ @@ -2370,7 +2376,8 @@ enum options { OPT_INNOBASE_LOG_GROUP_HOME_DIR, OPT_INNOBASE_LOG_ARCH_DIR, OPT_INNOBASE_LOG_ARCHIVE, OPT_INNOBASE_FLUSH_LOG_AT_TRX_COMMIT, OPT_SAFE_SHOW_DB, - OPT_GEMINI_SKIP + OPT_GEMINI_SKIP, + OPT_TEMP_POOL }; static struct option long_options[] = { @@ -2501,6 +2508,7 @@ static struct option long_options[] = { #ifdef __WIN__ {"standalone", no_argument, 0, (int) OPT_STANDALONE}, #endif + {"temp-pool", no_argument, 0, (int) OPT_TEMP_POOL}, {"tmpdir", required_argument, 0, 't'}, {"use-locking", no_argument, 0, (int) OPT_USE_LOCKING}, #ifdef USE_SYMDIR @@ -2874,6 +2882,7 @@ static void usage(void) Don't give threads different priorities.\n\ --socket=... Socket file to use for connection\n\ -t, --tmpdir=path Path for temporary files\n\ + --temp-pool Use a pool of temporary files\n\ -u, --user=user_name Run mysqld daemon as user\n\ -V, --version output version information and exit"); #ifdef __WIN__ @@ -3049,6 +3058,9 @@ static void get_options(int argc,char **argv) case 't': mysql_tmpdir=optarg; break; + case OPT_TEMP_POOL: + use_temp_pool=1; + break; case 'u': mysqld_user=optarg; break; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2d8373ec067..16d525f0ea7 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -30,6 +30,7 @@ #include #include #include +#include const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref", "MAYBE_REF","ALL","range","index","fulltext" }; @@ -3276,14 +3277,28 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, KEY_PART_INFO *key_part_info; Item_result_field **copy_func; MI_COLUMNDEF *recinfo; + uint temp_pool_slot; + DBUG_ENTER("create_tmp_table"); DBUG_PRINT("enter",("distinct: %d save_sum_fields: %d allow_distinct_limit: %d group: %d", (int) distinct, (int) save_sum_fields, (int) allow_distinct_limit,test(group))); statistic_increment(created_tmp_tables, &LOCK_status); - sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid, - thd->thread_id, thd->tmp_table++); + + if(use_temp_pool) { + temp_pool_slot = bitmap_set_next(temp_pool, TEMP_POOL_SIZE); + if(temp_pool_slot != MY_BIT_NONE) // we got a slot + sprintf(path, "%s%s_%lx_%i", mysql_tmpdir, tmp_file_prefix, + current_pid, temp_pool_slot); + else // if we run out of slots in the pool, fall back to old behavior + sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid, + thd->thread_id, thd->tmp_table++); + } else { + sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid, + thd->thread_id, thd->tmp_table++); + }; + if (group) { if (!param->quick_group) @@ -3310,10 +3325,12 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, param->group_length : 0, NullS)) { + bitmap_clear_bit(temp_pool, TEMP_POOL_SIZE, temp_pool_slot); DBUG_RETURN(NULL); /* purecov: inspected */ } if (!(param->copy_field=copy=new Copy_field[field_count])) { + bitmap_clear_bit(temp_pool, TEMP_POOL_SIZE, temp_pool_slot); my_free((gptr) table,MYF(0)); /* purecov: inspected */ DBUG_RETURN(NULL); /* purecov: inspected */ } @@ -3333,6 +3350,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, table->map=1; table->tmp_table=1; table->db_low_byte_first=1; // True for HEAP and MyISAM + table->temp_pool_slot = temp_pool_slot; + /* Calculate with type of fields we will need in heap table */ @@ -3626,7 +3645,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, DBUG_RETURN(table); err: - free_tmp_table(thd,table); /* purecov: inspected */ + free_tmp_table(thd,table); /* purecov: inspected */ + bitmap_clear_bit(temp_pool, TEMP_POOL_SIZE, temp_pool_slot); DBUG_RETURN(NULL); /* purecov: inspected */ } @@ -3773,6 +3793,9 @@ free_tmp_table(THD *thd, TABLE *entry) delete *ptr; my_free((gptr) entry->record[0],MYF(0)); free_io_cache(entry); + + bitmap_clear_bit(temp_pool, TEMP_POOL_SIZE, entry->temp_pool_slot); + my_free((gptr) entry,MYF(0)); thd->proc_info=save_proc_info; diff --git a/sql/table.h b/sql/table.h index 8121271b479..c709be6a08c 100644 --- a/sql/table.h +++ b/sql/table.h @@ -119,6 +119,8 @@ struct st_table { key_part_map const_key_parts[MAX_KEY]; ulong query_id; + uint temp_pool_slot; + THD *in_use; /* Which thread uses this */ struct st_table *next,*prev; };