From 18ce758819212e1f835b2e4c8e0c74dc7b7e21ce Mon Sep 17 00:00:00 2001 From: "antony@ppcg5.local" <> Date: Tue, 6 Feb 2007 15:19:01 -0800 Subject: [PATCH 1/4] thd_lib_detected moved so that it is correctly declared as a data section symbol and not a common symbol on gcc 4.0.1 on darwin 8.8.0 PowerPC MacOS X 10.4.8 --- mysys/my_pthread.c | 1 - mysys/my_thr_init.c | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index b9da9d4817a..49aab9230e8 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -29,7 +29,6 @@ #define SCHED_POLICY SCHED_OTHER #endif -uint thd_lib_detected; #ifndef my_pthread_setprio void my_pthread_setprio(pthread_t thread_id,int prior) diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 67ab1e4a38a..abacc7bc004 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -47,6 +47,8 @@ pthread_mutexattr_t my_fast_mutexattr; pthread_mutexattr_t my_errorcheck_mutexattr; #endif +uint thd_lib_detected; + #ifdef NPTL_PTHREAD_EXIT_BUG /* see my_pthread.h */ /* From a3c3cda915e6a854728ba53354cde8614278ecc5 Mon Sep 17 00:00:00 2001 From: "antony@ppcg5.local" <> Date: Wed, 7 Feb 2007 14:22:19 -0800 Subject: [PATCH 2/4] Bug#12204 "CONNECTION is a reserved keyword" Allow connection to be used as an ordinary identifier Tests included. --- mysql-test/r/keywords.result | 13 +++++++++++++ mysql-test/t/keywords.test | 22 ++++++++++++++++++++++ sql/sql_yacc.yy | 1 + 3 files changed, 36 insertions(+) diff --git a/mysql-test/r/keywords.result b/mysql-test/r/keywords.result index 88a0ab8abd5..c14ae584c86 100644 --- a/mysql-test/r/keywords.result +++ b/mysql-test/r/keywords.result @@ -16,3 +16,16 @@ select events.binlog from events; binlog 1 drop table events; +create table t1 (connection int, b int); +create procedure p1() +begin +declare connection int; +select max(t1.connection) into connection from t1; +select concat("max=",connection) 'p1'; +end| +insert into t1 (connection) values (1); +call p1(); +p1 +max=1 +drop procedure p1; +drop table t1; diff --git a/mysql-test/t/keywords.test b/mysql-test/t/keywords.test index de0159a950e..46933a230ee 100644 --- a/mysql-test/t/keywords.test +++ b/mysql-test/t/keywords.test @@ -19,3 +19,25 @@ select events.binlog from events; drop table events; # End of 4.1 tests + + +# +# Bug#12204 - CONNECTION should not be a reserved word +# + +create table t1 (connection int, b int); +delimiter |; +create procedure p1() +begin + declare connection int; + select max(t1.connection) into connection from t1; + select concat("max=",connection) 'p1'; +end| +delimiter ;| +insert into t1 (connection) values (1); +call p1(); +drop procedure p1; +drop table t1; + + +# End of 5.0 tests diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index b4147d2905c..37c591b4f4a 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -7926,6 +7926,7 @@ keyword_sp: | COMPACT_SYM {} | COMPRESSED_SYM {} | CONCURRENT {} + | CONNECTION_SYM {} | CONSISTENT_SYM {} | CUBE_SYM {} | DATA_SYM {} From be7804897de512f4459342a57ab4afeef8353b37 Mon Sep 17 00:00:00 2001 From: "antony@ppcg5.local" <> Date: Thu, 8 Feb 2007 15:17:27 -0800 Subject: [PATCH 3/4] remove symbol after merge --- mysys/my_thr_init.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index de926a1e969..853a2761224 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -46,8 +46,6 @@ pthread_mutexattr_t my_fast_mutexattr; pthread_mutexattr_t my_errorcheck_mutexattr; #endif -uint thd_lib_detected; - #ifdef NPTL_PTHREAD_EXIT_BUG /* see my_pthread.h */ /* From 1b35f192236db8c224d916634d014ae3bab4605f Mon Sep 17 00:00:00 2001 From: "istruewing@chilla.local" <> Date: Tue, 13 Feb 2007 16:33:32 +0100 Subject: [PATCH 4/4] Bug#25460 - High concurrency MyISAM access causes severe mysqld crash. Under high load it was possible that memory mapping was started on a table while other threads were working with the table. I fixed the start of memory mapping so that it is done at the first table open or when the requesting thread is using the table exclusively only. --- include/my_base.h | 1 + storage/myisam/ha_myisam.cc | 22 +++++++++++++++++++--- storage/myisam/mi_dynrec.c | 8 ++++++++ storage/myisam/mi_extra.c | 7 ++++++- storage/myisam/mi_open.c | 16 ++++++++++++++++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/include/my_base.h b/include/my_base.h index 14e4e3afb44..26d513ba2a7 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -47,6 +47,7 @@ #define HA_OPEN_ABORT_IF_CRASHED 16 #define HA_OPEN_FOR_REPAIR 32 /* open even if crashed */ #define HA_OPEN_FROM_SQL_LAYER 64 +#define HA_OPEN_MMAP 128 /* open memory mapped */ /* The following is parameter to ha_rkey() how to use key */ diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 764c53d2f75..06ec5c4b44e 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -598,15 +598,31 @@ bool ha_myisam::check_if_locking_is_allowed(uint sql_command, int ha_myisam::open(const char *name, int mode, uint test_if_locked) { uint i; + + /* + If the user wants to have memory mapped data files, add an + open_flag. Do not memory map temporary tables because they are + expected to be inserted and thus extended a lot. Memory mapping is + efficient for files that keep their size, but very inefficient for + growing files. Using an open_flag instead of calling mi_extra(... + HA_EXTRA_MMAP ...) after mi_open() has the advantage that the + mapping is not repeated for every open, but just done on the initial + open, when the MyISAM share is created. Everytime the server + requires to open a new instance of a table it calls this method. We + will always supply HA_OPEN_MMAP for a permanent table. However, the + MyISAM storage engine will ignore this flag if this is a secondary + open of a table that is in use by other threads already (if the + MyISAM share exists already). + */ + if (!(test_if_locked & HA_OPEN_TMP_TABLE) && opt_myisam_use_mmap) + test_if_locked|= HA_OPEN_MMAP; + if (!(file=mi_open(name, mode, test_if_locked | HA_OPEN_FROM_SQL_LAYER))) return (my_errno ? my_errno : -1); if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE)) VOID(mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0)); - if (!(test_if_locked & HA_OPEN_TMP_TABLE) && opt_myisam_use_mmap) - VOID(mi_extra(file, HA_EXTRA_MMAP, 0)); - info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST); if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED)) VOID(mi_extra(file, HA_EXTRA_WAIT_LOCK, 0)); diff --git a/storage/myisam/mi_dynrec.c b/storage/myisam/mi_dynrec.c index 642efbd4389..5342619c79b 100644 --- a/storage/myisam/mi_dynrec.c +++ b/storage/myisam/mi_dynrec.c @@ -71,6 +71,14 @@ my_bool mi_dynmap_file(MI_INFO *info, my_off_t size) DBUG_PRINT("warning", ("File is too large for mmap")); DBUG_RETURN(1); } + /* + I wonder if it is good to use MAP_NORESERVE. From the Linux man page: + MAP_NORESERVE + Do not reserve swap space for this mapping. When swap space is + reserved, one has the guarantee that it is possible to modify the + mapping. When swap space is not reserved one might get SIGSEGV + upon a write if no physical memory is available. + */ info->s->file_map= (byte*) my_mmap(0, (size_t)(size + MEMMAP_EXTRA_MARGIN), info->s->mode==O_RDONLY ? PROT_READ : diff --git a/storage/myisam/mi_extra.c b/storage/myisam/mi_extra.c index e1288fa6624..ae584b06173 100644 --- a/storage/myisam/mi_extra.c +++ b/storage/myisam/mi_extra.c @@ -349,7 +349,12 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) case HA_EXTRA_MMAP: #ifdef HAVE_MMAP pthread_mutex_lock(&share->intern_lock); - if (!share->file_map) + /* + Memory map the data file if it is not already mapped and if there + are no other threads using this table. intern_lock prevents other + threads from starting to use the table while we are mapping it. + */ + if (!share->file_map && (share->tot_locks == 1)) { if (mi_dynmap_file(info, share->state.state.data_file_length)) { diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c index 5e783bf7890..830332fe0c1 100644 --- a/storage/myisam/mi_open.c +++ b/storage/myisam/mi_open.c @@ -506,6 +506,22 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) share->data_file_type = DYNAMIC_RECORD; my_afree((gptr) disk_cache); mi_setup_functions(share); + if (open_flags & HA_OPEN_MMAP) + { + info.s= share; + if (mi_dynmap_file(&info, share->state.state.data_file_length)) + { + /* purecov: begin inspected */ + /* Ignore if mmap fails. Use file I/O instead. */ + DBUG_PRINT("warning", ("mmap failed: errno: %d", errno)); + /* purecov: end */ + } + else + { + share->file_read= mi_mmap_pread; + share->file_write= mi_mmap_pwrite; + } + } share->is_log_table= FALSE; #ifdef THREAD thr_lock_init(&share->lock);