From 838eaec7097d5686866f823690f47b16647be982 Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Wed, 11 Aug 2004 16:40:46 +0400 Subject: [PATCH] Fix and testcase for BUG#4984 The crash is eliminated but still it is weird/inefficent that ROR-intersection is used when performing updates in empty table. --- mysql-test/r/index_merge_ror_cpk.result | 21 +++++++++++++++++++++ mysql-test/t/index_merge_ror_cpk.test | 24 ++++++++++++++++++++++++ sql/opt_range.cc | 24 +++++++++++++++--------- sql/opt_range.h | 1 + 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/index_merge_ror_cpk.result b/mysql-test/r/index_merge_ror_cpk.result index f4bef25045b..7acfb8dc93b 100644 --- a/mysql-test/r/index_merge_ror_cpk.result +++ b/mysql-test/r/index_merge_ror_cpk.result @@ -97,3 +97,24 @@ pk1 pk2 key1 key2 95 58 10 10 95 59 10 10 drop table t1; +create table t1 +( +RUNID varchar(22), +SUBMITNR varchar(5), +ORDERNR char(1) , +PROGRAMM varchar(8), +TESTID varchar(4), +UCCHECK char(1), +ETEXT varchar(80), +ETEXT_TYPE char(1), +INFO char(1), +SEVERITY tinyint(3), +TADIRFLAG char(1), +PRIMARY KEY (RUNID,SUBMITNR,ORDERNR,PROGRAMM,TESTID,UCCHECK), +KEY `TVERM~KEY` (PROGRAMM,TESTID,UCCHECK) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +update t1 set `ETEXT` = '', `ETEXT_TYPE`='', `INFO`='', `SEVERITY`='', `TADIRFLAG`='' +WHERE +`RUNID`= '' AND `SUBMITNR`= '' AND `ORDERNR`='' AND `PROGRAMM`='' AND +`TESTID`='' AND `UCCHECK`=''; +drop table t1; diff --git a/mysql-test/t/index_merge_ror_cpk.test b/mysql-test/t/index_merge_ror_cpk.test index 4ba5b1a0af3..bf8eb5b77c7 100644 --- a/mysql-test/t/index_merge_ror_cpk.test +++ b/mysql-test/t/index_merge_ror_cpk.test @@ -81,4 +81,28 @@ explain select pk1,pk2,key1,key2 from t1 where key1 = 10 and key2=10 limit 10; select pk1,pk2,key1,key2 from t1 where key1 = 10 and key2=10 limit 10; drop table t1; +# Testcase for BUG#4984 +create table t1 +( + RUNID varchar(22), + SUBMITNR varchar(5), + ORDERNR char(1) , + PROGRAMM varchar(8), + TESTID varchar(4), + UCCHECK char(1), + ETEXT varchar(80), + ETEXT_TYPE char(1), + INFO char(1), + SEVERITY tinyint(3), + TADIRFLAG char(1), + PRIMARY KEY (RUNID,SUBMITNR,ORDERNR,PROGRAMM,TESTID,UCCHECK), + KEY `TVERM~KEY` (PROGRAMM,TESTID,UCCHECK) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +update t1 set `ETEXT` = '', `ETEXT_TYPE`='', `INFO`='', `SEVERITY`='', `TADIRFLAG`='' +WHERE + `RUNID`= '' AND `SUBMITNR`= '' AND `ORDERNR`='' AND `PROGRAMM`='' AND + `TESTID`='' AND `UCCHECK`=''; + +drop table t1; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index e0192116853..df79824ed1e 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -749,16 +749,20 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT() DBUG_ENTER("QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT"); if (!dont_free) { - range_end(); - file->extra(HA_EXTRA_NO_KEYREAD); - delete_dynamic(&ranges); /* ranges are allocated in alloc */ - if (free_file) + /* file is NULL for CPK scan on covering ROR-intersection */ + if (file) { - DBUG_PRINT("info", ("Freeing separate handler %p (free=%d)", file, - free_file)); - file->reset(); - file->close(); + range_end(); + file->extra(HA_EXTRA_NO_KEYREAD); + if (free_file) + { + DBUG_PRINT("info", ("Freeing separate handler %p (free=%d)", file, + free_file)); + file->reset(); + file->close(); + } } + delete_dynamic(&ranges); /* ranges are allocated in alloc */ free_root(&alloc,MYF(0)); } DBUG_VOID_RETURN; @@ -1666,7 +1670,8 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, objects are not allowed so don't use ROR-intersection for table deletes. */ - if (thd->lex->sql_command != SQLCOM_DELETE) + if ((thd->lex->sql_command != SQLCOM_DELETE) )//&& +// (thd->lex->sql_command != SQLCOM_UPDATE)) { /* Get best non-covering ROR-intersection plan and prepare data for @@ -3096,6 +3101,7 @@ QUICK_SELECT_I *TRP_ROR_INTERSECT::make_quick(PARAM *param, delete quick_intrsect; DBUG_RETURN(NULL); } + quick->file= NULL; quick_intrsect->cpk_quick= quick; } quick_intrsect->records= records; diff --git a/sql/opt_range.h b/sql/opt_range.h index 8826705c9a7..974ed409a87 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -236,6 +236,7 @@ protected: bool free_file; protected: + friend class TRP_ROR_INTERSECT; friend QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, struct st_table_ref *ref);