From 4b760fcb94cd06a9e344c829075043c7b8bc2898 Mon Sep 17 00:00:00 2001 From: "igor@rurik.mysql.com" <> Date: Fri, 20 Aug 2004 23:48:30 -0700 Subject: [PATCH 1/5] null.test, null.result: Added test case for bug #4256. join_outer.result: Fixed bug #4256. item_cmpfunc.h: Fixed inconsistency of values of used_tables_cache and const_item_cache for Item_func_isnull objects. This inconsistency caused bug #4256. --- mysql-test/r/join_outer.result | 2 +- mysql-test/r/null.result | 19 +++++++++++++++++++ mysql-test/t/null.test | 23 +++++++++++++++++++++++ sql/item_cmpfunc.h | 1 + 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index ae4d99e6241..5778b2f9b72 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -91,7 +91,7 @@ grp a c id a c d NULL NULL NULL NULL NULL NULL explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; Comment -Impossible WHERE noticed after reading const tables +Impossible WHERE explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; table type possible_keys key key_len ref rows Extra t1 ALL NULL NULL NULL NULL 7 diff --git a/mysql-test/r/null.result b/mysql-test/r/null.result index ba2161d3147..41a1a06aebe 100644 --- a/mysql-test/r/null.result +++ b/mysql-test/r/null.result @@ -109,3 +109,22 @@ a b c d 0 0000-00-00 00:00:00 0 0 0000-00-00 00:00:00 0 drop table t1; +CREATE TABLE t1(i int, KEY(i)); +INSERT INTO t1 VALUES(1); +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +EXPLAIN SELECT * FROM t1 WHERE i=2 OR i IS NULL; +table type possible_keys key key_len ref rows Extra +t1 range i i 5 NULL 10 Using where; Using index +ALTER TABLE t1 CHANGE i i int NOT NULL; +EXPLAIN SELECT * FROM t1 WHERE i=2 OR i IS NULL; +table type possible_keys key key_len ref rows Extra +t1 range i i 4 NULL 7 Using where; Using index +DROP TABLE t1; diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test index 6fea7f0d10d..fc9b0a8aff2 100644 --- a/mysql-test/t/null.test +++ b/mysql-test/t/null.test @@ -79,3 +79,26 @@ INSERT INTO t1 (d) values (null),(null); select * from t1; drop table t1; +# Test case for bug #4256 + +CREATE TABLE t1(i int, KEY(i)); + +INSERT INTO t1 VALUES(1); + +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; +INSERT INTO t1 SELECT i*2 FROM t1; + +EXPLAIN SELECT * FROM t1 WHERE i=2 OR i IS NULL; + +ALTER TABLE t1 CHANGE i i int NOT NULL; + +EXPLAIN SELECT * FROM t1 WHERE i=2 OR i IS NULL; + +DROP TABLE t1; diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index a0bcd864d4b..236ebb8d28b 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -469,6 +469,7 @@ public: if (!args[0]->maybe_null) { used_tables_cache= 0; /* is always false */ + const_item_cache= 1; cached_value= (longlong) 0; } else From 566344b42e34f7137537cff89ec4ad3f3808737e Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Sat, 21 Aug 2004 23:53:42 +0200 Subject: [PATCH 2/5] libedit safety fix: account for closing \0 --- cmd-line-utils/libedit/history.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd-line-utils/libedit/history.c b/cmd-line-utils/libedit/history.c index 457c8f4a768..bae50787b94 100644 --- a/cmd-line-utils/libedit/history.c +++ b/cmd-line-utils/libedit/history.c @@ -647,7 +647,7 @@ history_save(History *h, const char *fname) for (retval = HLAST(h, &ev); retval != -1; retval = HPREV(h, &ev), i++) { - len = strlen(ev.str) * 4; + len = strlen(ev.str) * 4 + 1; if (len >= max_size) { max_size = (len + 1023) & ~1023; ptr = h_realloc(ptr, max_size); From ca351277392a66ef458c8e70162570ec70a5993d Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Sun, 22 Aug 2004 09:36:17 +0200 Subject: [PATCH 3/5] bug#2408 - Multiple threads altering MERGE table UNIONs hang/crash. Abandoned improper use of MyISAM data. Thanks Ingo! --- myisammrg/myrg_open.c | 101 ++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 52 deletions(-) diff --git a/myisammrg/myrg_open.c b/myisammrg/myrg_open.c index df94fb680cb..ad89d109b85 100644 --- a/myisammrg/myrg_open.c +++ b/myisammrg/myrg_open.c @@ -35,86 +35,86 @@ const char *name, int mode, int handle_locking) { - int save_errno,i,errpos; + int save_errno,errpos; uint files,dir_length,length; ulonglong file_offset; char name_buff[FN_REFLEN*2],buff[FN_REFLEN],*end; - MYRG_INFO info,*m_info; + MYRG_INFO *m_info; File fd; IO_CACHE file; - MI_INFO *isam,*last_isam; + MI_INFO *isam; DBUG_ENTER("myrg_open"); - LINT_INIT(last_isam); LINT_INIT(m_info); isam=0; errpos=files=0; - bzero((gptr) &info,sizeof(info)); bzero((char*) &file,sizeof(file)); if ((fd=my_open(fn_format(name_buff,name,"",MYRG_NAME_EXT,4), - O_RDONLY | O_SHARE,MYF(0))) < 0 || - init_io_cache(&file, fd, IO_SIZE, READ_CACHE, 0, 0, - MYF(MY_WME | MY_NABP))) + O_RDONLY | O_SHARE,MYF(0))) < 0) goto err; errpos=1; + if (init_io_cache(&file, fd, 4*IO_SIZE, READ_CACHE, 0, 0, + MYF(MY_WME | MY_NABP))) + goto err; + errpos=2; dir_length=dirname_part(name_buff,name); - info.reclength=0; while ((length=my_b_gets(&file,buff,FN_REFLEN-1))) { if ((end=buff+length)[-1] == '\n') end[-1]='\0'; if (buff[0] && buff[0] != '#') /* Skipp empty lines and comments */ { - if (!test_if_hard_path(buff)) - { - VOID(strmake(name_buff+dir_length,buff, - sizeof(name_buff)-1-dir_length)); - VOID(cleanup_dirname(buff,name_buff)); - } - if (!(isam=mi_open(buff,mode,test(handle_locking)))) - goto err; files++; - last_isam=isam; - if (info.reclength && info.reclength != isam->s->base.reclength) - { - my_errno=HA_ERR_WRONG_IN_RECORD; - goto err; - } - info.reclength=isam->s->base.reclength; } } + if (!(m_info= (MYRG_INFO*) my_malloc(sizeof(MYRG_INFO)+ files*sizeof(MYRG_TABLE), - MYF(MY_WME)))) + MYF(MY_WME|MY_ZEROFILL)))) goto err; - *m_info=info; + errpos=3; m_info->open_tables=(files) ? (MYRG_TABLE *) (m_info+1) : 0; m_info->tables=files; - errpos=2; - - for (i=files ; i-- > 0 ; ) - { - m_info->open_tables[i].table=isam; - m_info->options|=isam->s->options; - m_info->records+=isam->state->records; - m_info->del+=isam->state->del; - m_info->data_file_length+=isam->state->data_file_length; - if (i) - isam=(MI_INFO*) (isam->open_list.next->data); - } - /* Fix fileinfo for easyer debugging (actually set by rrnd) */ + files=0; file_offset=0; - for (i=0 ; (uint) i < files ; i++) + + my_b_seek(&file, 0); + while ((length=my_b_gets(&file,buff,FN_REFLEN-1))) { - m_info->open_tables[i].file_offset=(my_off_t) file_offset; - file_offset+=m_info->open_tables[i].table->state->data_file_length; + if ((end=buff+length)[-1] == '\n') + end[-1]='\0'; + if (buff[0] && buff[0] == '#') /* Skipp empty lines and comments */ + continue; + if (!test_if_hard_path(buff)) + { + VOID(strmake(name_buff+dir_length,buff, + sizeof(name_buff)-1-dir_length)); + VOID(cleanup_dirname(buff,name_buff)); + } + if (!(isam=mi_open(buff,mode,test(handle_locking)))) + goto err; + m_info->open_tables[files].table= isam; + m_info->open_tables[files].file_offset=(my_off_t) file_offset; + file_offset+=isam->state->data_file_length; + files++; + if (m_info->reclength && (m_info->reclength != isam->s->base.reclength)) + { + my_errno=HA_ERR_WRONG_IN_RECORD; + goto err; + } + m_info->reclength=isam->s->base.reclength; + m_info->options|= isam->s->options; + m_info->records+= isam->state->records; + m_info->del+= isam->state->del; + m_info->data_file_length+= isam->state->data_file_length; } + if (sizeof(my_off_t) == 4 && file_offset > (ulonglong) (ulong) ~0L) { my_errno=HA_ERR_RECORD_FILE_FULL; goto err; } - m_info->keys=(files) ? m_info->open_tables->table->s->base.keys : 0; + m_info->keys=(files) ? isam->s->base.keys : 0; bzero((char*) &m_info->by_key,sizeof(m_info->by_key)); /* this works ok if the table list is empty */ @@ -132,19 +132,16 @@ int handle_locking) err: save_errno=my_errno; switch (errpos) { - case 2: + case 3: + while (files) + mi_close(m_info->open_tables[--files].table); my_free((char*) m_info,MYF(0)); /* Fall through */ + case 2: + end_io_cache(&file); + /* Fall through */ case 1: VOID(my_close(fd,MYF(0))); - end_io_cache(&file); - for (i=files ; i-- > 0 ; ) - { - isam=last_isam; - if (i) - last_isam=(MI_INFO*) (isam->open_list.next->data); - mi_close(isam); - } } my_errno=save_errno; DBUG_RETURN (NULL); From d5bf903e4d05260a596c512efba2412c0807a30b Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Sun, 22 Aug 2004 12:43:26 +0200 Subject: [PATCH 4/5] after merge fixes --- myisammrg/myrg_open.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/myisammrg/myrg_open.c b/myisammrg/myrg_open.c index 35b5adc8770..2d6b6dcf167 100644 --- a/myisammrg/myrg_open.c +++ b/myisammrg/myrg_open.c @@ -43,6 +43,7 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) DBUG_ENTER("myrg_open"); LINT_INIT(m_info); + m_info=0; isam=0; errpos=files=0; bzero((char*) &file,sizeof(file)); @@ -75,7 +76,7 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) if( !strncmp(buff+1,"INSERT_METHOD=",14)) { /* Lookup insert method */ int tmp=find_type(buff+15,&merge_insert_method,2); - m_info.merge_insert_method = (uint) (tmp >= 0 ? tmp : 0); + m_info->merge_insert_method = (uint) (tmp >= 0 ? tmp : 0); } continue; /* Skip comments */ } @@ -115,7 +116,7 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) m_info->open_tables[files].file_offset=(my_off_t) file_offset; file_offset+=isam->state->data_file_length; files++; - if (m_info.reclength != isam->s->base.reclength) + if (m_info->reclength != isam->s->base.reclength) { my_errno=HA_ERR_WRONG_MRG_TABLE_DEF; goto err; @@ -128,6 +129,9 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) m_info->rec_per_key_part[i]+=isam->s->state.rec_per_key_part[i] / m_info->tables; } + if (!m_info && !(m_info= (MYRG_INFO*) my_malloc(sizeof(MYRG_INFO), + MYF(MY_WME|MY_ZEROFILL)))) + goto err; /* Don't mark table readonly, for ALTER TABLE ... UNION=(...) to work */ m_info->options&= ~(HA_OPTION_COMPRESS_RECORD | HA_OPTION_READ_ONLY_DATA); @@ -136,7 +140,7 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking) my_errno=HA_ERR_RECORD_FILE_FULL; goto err; } - m_info->keys=(files) ? m_info->open_tables->table->s->base.keys : 0; + m_info->keys= files ? isam->s->base.keys : 0; bzero((char*) &m_info->by_key,sizeof(m_info->by_key)); /* this works ok if the table list is empty */ From 326992430f660b8b1f76d22eb849b937fa0465b9 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Sun, 22 Aug 2004 14:23:52 +0200 Subject: [PATCH 5/5] check for mysql_bin_log.is_open() before my_b_tell(&thd->transaction.trans_log in ha_commit_trans - why it didn't crash earlier ? --- mysql-test/r/null.result | 19 +++++++++++++++++++ sql/handler.cc | 22 +++++++++++----------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/mysql-test/r/null.result b/mysql-test/r/null.result index 1d76fbf2fb3..bd90b3fe3f3 100644 --- a/mysql-test/r/null.result +++ b/mysql-test/r/null.result @@ -156,3 +156,22 @@ drop table t1; select cast(NULL as signed); cast(NULL as signed) NULL +create table t1(i int, key(i)); +insert into t1 values(1); +insert into t1 select i*2 from t1; +insert into t1 select i*2 from t1; +insert into t1 select i*2 from t1; +insert into t1 select i*2 from t1; +insert into t1 select i*2 from t1; +insert into t1 select i*2 from t1; +insert into t1 select i*2 from t1; +insert into t1 select i*2 from t1; +insert into t1 select i*2 from t1; +explain select * from t1 where i=2 or i is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref_or_null i i 5 const 10 Using where; Using index +alter table t1 change i i int not null; +explain select * from t1 where i=2 or i is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref i i 4 const 7 Using where; Using index +drop table t1; diff --git a/sql/handler.cc b/sql/handler.cc index 119e29a6a03..15f30b25eb8 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -472,7 +472,7 @@ int ha_release_temporary_latches(THD *thd) int ha_commit_trans(THD *thd, THD_TRANS* trans) { int error=0; - DBUG_ENTER("ha_commit"); + DBUG_ENTER("ha_commit_trans"); #ifdef USING_TRANSACTIONS if (opt_using_transactions) { @@ -480,8 +480,8 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) bool operation_done= 0, need_start_waiters= 0; /* If transaction has done some updates to tables */ - if (trans == &thd->transaction.all && - my_b_tell(&thd->transaction.trans_log)) + if (trans == &thd->transaction.all && mysql_bin_log.is_open() && + my_b_tell(&thd->transaction.trans_log)) { if (error= wait_if_global_read_lock(thd, 0, 0)) { @@ -576,7 +576,7 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) int ha_rollback_trans(THD *thd, THD_TRANS *trans) { int error=0; - DBUG_ENTER("ha_rollback"); + DBUG_ENTER("ha_rollback_trans"); #ifdef USING_TRANSACTIONS if (opt_using_transactions) { @@ -587,7 +587,7 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) if ((error=ndbcluster_rollback(thd, trans->ndb_tid))) { if (error == -1) - my_error(ER_ERROR_DURING_ROLLBACK, MYF(0)); + my_error(ER_ERROR_DURING_ROLLBACK, MYF(0)); error=1; } trans->ndb_tid = 0; @@ -768,12 +768,12 @@ bool ha_flush_logs() { bool result=0; #ifdef HAVE_BERKELEY_DB - if ((have_berkeley_db == SHOW_OPTION_YES) && + if ((have_berkeley_db == SHOW_OPTION_YES) && berkeley_flush_logs()) result=1; #endif #ifdef HAVE_INNOBASE_DB - if ((have_innodb == SHOW_OPTION_YES) && + if ((have_innodb == SHOW_OPTION_YES) && innobase_flush_logs()) result=1; #endif @@ -868,7 +868,7 @@ my_off_t ha_get_ptr(byte *ptr, uint pack_length) int handler::ha_open(const char *name, int mode, int test_if_locked) { int error; - DBUG_ENTER("handler::open"); + DBUG_ENTER("handler::ha_open"); DBUG_PRINT("enter",("name: %s db_type: %d db_stat: %d mode: %d lock_test: %d", name, table->db_type, table->db_stat, mode, test_if_locked)); @@ -967,7 +967,7 @@ void handler::update_auto_increment() { longlong nr; THD *thd; - DBUG_ENTER("update_auto_increment"); + DBUG_ENTER("handler::update_auto_increment"); if (table->next_number_field->val_int() != 0 || table->auto_increment_field_not_null && current_thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) @@ -1025,7 +1025,7 @@ longlong handler::get_auto_increment() void handler::print_error(int error, myf errflag) { - DBUG_ENTER("print_error"); + DBUG_ENTER("handler::print_error"); DBUG_PRINT("enter",("error: %d",error)); int textno=ER_GET_ERRNO; @@ -1164,7 +1164,7 @@ bool handler::get_error_message(int error, String* buf) uint handler::get_dup_key(int error) { - DBUG_ENTER("get_dup_key"); + DBUG_ENTER("handler::get_dup_key"); table->file->errkey = (uint) -1; if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOUND_DUPP_UNIQUE) info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);