From 7c16fd2c0f9eb167b841b94241d8083ec1d6c984 Mon Sep 17 00:00:00 2001 From: "mattiasj@mattiasj-laptop.(none)" <> Date: Wed, 17 Oct 2007 20:40:23 +0200 Subject: [PATCH 01/33] Bug #30878: Crashing when alter an auto_increment non partitioned table to partitioned Problem: Crashed because usage of an uninitialised mutex when auto_incrementing a partitioned temporary table Fix: Only locking (using the mutex) if not temporary table. --- mysql-test/r/partition.result | 12 ++++++++++++ mysql-test/t/partition.test | 18 ++++++++++++++++++ sql/ha_partition.cc | 20 +++++++++++++++----- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index f90f3b07d70..753a2e31632 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1,4 +1,16 @@ drop table if exists t1; +create table t1 (id int auto_increment, s1 int, primary key (id)); +insert into t1 values (null,1); +insert into t1 values (null,6); +select * from t1; +id s1 +1 1 +2 6 +alter table t1 partition by range (id) ( +partition p0 values less than (3), +partition p1 values less than maxvalue +); +drop table t1; create table t1 (a int) partition by key(a) partitions 0.2+e1; diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index f391237a4db..929d3ecce9e 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -9,6 +9,24 @@ drop table if exists t1; --enable_warnings +# +# Bug 30878: crashing when alter an auto_increment non partitioned +# table to partitioned + +create table t1 (id int auto_increment, s1 int, primary key (id)); + +insert into t1 values (null,1); +insert into t1 values (null,6); + +select * from t1; + +alter table t1 partition by range (id) ( + partition p0 values less than (3), + partition p1 values less than maxvalue +); + +drop table t1; + # # Bug 15890: Strange number of partitions accepted # diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 1150cf41417..81d75c58d05 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -2678,7 +2678,8 @@ int ha_partition::write_row(uchar * buf) uint32 part_id; int error; longlong func_value; - bool autoincrement_lock= false; + bool autoincrement_lock= FALSE; + my_bitmap_map *old_map; #ifdef NOT_NEEDED uchar *rec0= m_rec0; #endif @@ -2705,8 +2706,17 @@ int ha_partition::write_row(uchar * buf) use autoincrement_lock variable to avoid unnecessary locks. Probably not an ideal solution. */ - autoincrement_lock= true; - pthread_mutex_lock(&table_share->mutex); + if (table_share->tmp_table == NO_TMP_TABLE) + { + /* + Bug#30878 crash when alter table from non partitioned table + to partitioned. + Checking if tmp table then there is no need to lock, + and the table_share->mutex may not be initialised. + */ + autoincrement_lock= TRUE; + pthread_mutex_lock(&table_share->mutex); + } error= update_auto_increment(); /* @@ -2715,10 +2725,10 @@ int ha_partition::write_row(uchar * buf) the correct partition. We must check and fail if neccessary. */ if (error) - DBUG_RETURN(error); + goto exit; } - my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set); + old_map= dbug_tmp_use_all_columns(table, table->read_set); #ifdef NOT_NEEDED if (likely(buf == rec0)) #endif From f733ea5a06862d32725a2153a01d137eed54ee77 Mon Sep 17 00:00:00 2001 From: "mattiasj@mattiasj-laptop.(none)" <> Date: Tue, 23 Oct 2007 22:04:09 +0200 Subject: [PATCH 02/33] Bug #30695: An apostrophe ' in the comment of the ADD PARTITION causes the Server to crash. Accessing partitioned table with an apostrophe in partition options like DATA DIRECTORY, INDEX DIRECTORY or COMMENT causes server crash. Partition options were saved in .frm file without escaping. When accessing such table it is not possible to properly restore partition information. Crashed because there was no check for partition info parser failure. Fixed by escaping quoted text in the partition info when writing it to the frm-file and added a check that it was able to parse the partition info before using it NOTE: If the comment is written by an earlier version of the server, the corrupted frm-file is not fixed, but left corrupted, you have to manually drop the table and recreate it. --- mysql-test/r/partition.result | 16 ++++++++++++++++ mysql-test/t/partition.test | 26 ++++++++++++++++++++++++++ sql/sql_partition.cc | 21 +++++++++++++++++---- sql/table.cc | 3 ++- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 5d985d053fc..2057b18de3d 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1,4 +1,20 @@ drop table if exists t1; +CREATE TABLE t1 ( +d DATE NOT NULL +) +PARTITION BY RANGE( YEAR(d) ) ( +PARTITION p0 VALUES LESS THAN (1960), +PARTITION p1 VALUES LESS THAN (1970), +PARTITION p2 VALUES LESS THAN (1980), +PARTITION p3 VALUES LESS THAN (1990) +); +ALTER TABLE t1 ADD PARTITION ( +PARTITION `p5` VALUES LESS THAN (2010) +COMMENT 'APSTART \' APEND' +); +SELECT * FROM t1 LIMIT 1; +d +DROP TABLE t1; create table t1 (a int) partition by key(a) partitions 0.2+e1; diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 42db23dadef..53454b132e9 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -9,6 +9,32 @@ drop table if exists t1; --enable_warnings +# +# Bug #30695: An apostrophe ' in the comment of the ADD PARTITION causes the Server to crash. +# +# To verify the fix for crashing (on unix-type OS) +# uncomment the exec and error rows! + +CREATE TABLE t1 ( + d DATE NOT NULL +) +PARTITION BY RANGE( YEAR(d) ) ( + PARTITION p0 VALUES LESS THAN (1960), + PARTITION p1 VALUES LESS THAN (1970), + PARTITION p2 VALUES LESS THAN (1980), + PARTITION p3 VALUES LESS THAN (1990) +); + +ALTER TABLE t1 ADD PARTITION ( +PARTITION `p5` VALUES LESS THAN (2010) +COMMENT 'APSTART \' APEND' +); +#--exec sed 's/APSTART \\/APSTART /' var/master-data/test/t1.frm > tmpt1.frm && mv tmpt1.frm var/master-data/test/t1.frm +#--error 1064 +SELECT * FROM t1 LIMIT 1; + +DROP TABLE t1; + # # Bug 15890: Strange number of partitions accepted # diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 8a8a03cb4e4..3ad2cbfb284 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1849,6 +1849,20 @@ static int add_uint(File fptr, ulonglong number) return add_string(fptr, buff); } +/* + Must escape strings in partitioned tables frm-files, + parsing it later with mysql_unpack_partition will fail otherwise. +*/ +static int add_quoted_string(File fptr, const char *quotestr) +{ + String orgstr(quotestr, system_charset_info); + String escapedstr; + int err= add_string(fptr, "'"); + err+= append_escaped(&escapedstr, &orgstr); + err+= add_string(fptr, escapedstr.c_ptr()); + return err + add_string(fptr, "'"); +} + static int add_keyword_string(File fptr, const char *keyword, bool should_use_quotes, const char *keystr) @@ -1859,10 +1873,9 @@ static int add_keyword_string(File fptr, const char *keyword, err+= add_equal(fptr); err+= add_space(fptr); if (should_use_quotes) - err+= add_string(fptr, "'"); - err+= add_string(fptr, keystr); - if (should_use_quotes) - err+= add_string(fptr, "'"); + err+= add_quoted_string(fptr, keystr); + else + err+= add_string(fptr, keystr); return err + add_space(fptr); } diff --git a/sql/table.cc b/sql/table.cc index ccddbf8134b..7cf5eeaaad6 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1782,7 +1782,8 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, outparam, is_create_table, share->default_part_db_type, &work_part_info_used); - outparam->part_info->is_auto_partitioned= share->auto_partitioned; + if (!tmp) + outparam->part_info->is_auto_partitioned= share->auto_partitioned; DBUG_PRINT("info", ("autopartitioned: %u", share->auto_partitioned)); /* we should perform the fix_partition_func in either local or caller's arena depending on work_part_info_used value From 5d1ccce58ac10b2abff245734cd8e3f5ed2e9f67 Mon Sep 17 00:00:00 2001 From: "svoj@mysql.com/june.mysql.com" <> Date: Wed, 24 Oct 2007 16:09:30 +0500 Subject: [PATCH 03/33] BUG#31159 - fulltext search on ucs2 column crashes server ucs2 doesn't provide required by fulltext ctype array. Crash happens because fulltext attempts to use unitialized ctype array. Fixed by converting ucs2 fields to compatible utf8 analogue. --- include/my_sys.h | 2 ++ mysql-test/r/ctype_ucs.result | 6 ++++++ mysql-test/t/ctype_ucs.test | 8 +++++++ mysys/charset.c | 40 +++++++++++++++++++++++++++++++++++ sql/item_func.cc | 33 ++++++++++++++++++++++++++++- 5 files changed, 88 insertions(+), 1 deletion(-) diff --git a/include/my_sys.h b/include/my_sys.h index 759531fa649..4a0586b9f2d 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -784,6 +784,8 @@ extern CHARSET_INFO *get_charset(uint cs_number, myf flags); extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags); extern CHARSET_INFO *get_charset_by_csname(const char *cs_name, uint cs_flags, myf my_flags); +extern CHARSET_INFO *get_compatible_charset_with_ctype(CHARSET_INFO + *original_cs); extern void free_charsets(void); extern char *get_charsets_dir(char *buf); extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2); diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index bf827209795..fef13b19ae8 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -803,4 +803,10 @@ quote(name) ???????? ???????????????? drop table bug20536; +CREATE TABLE t1(a TEXT CHARSET ucs2 COLLATE ucs2_unicode_ci); +INSERT INTO t1 VALUES('abcd'); +SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abcd' IN BOOLEAN MODE); +a +abcd +DROP TABLE t1; End of 4.1 tests diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test index 10559d33eb3..57f741597e0 100644 --- a/mysql-test/t/ctype_ucs.test +++ b/mysql-test/t/ctype_ucs.test @@ -535,4 +535,12 @@ select quote(name) from bug20536; drop table bug20536; +# +# BUG#31159 - fulltext search on ucs2 column crashes server +# +CREATE TABLE t1(a TEXT CHARSET ucs2 COLLATE ucs2_unicode_ci); +INSERT INTO t1 VALUES('abcd'); +SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abcd' IN BOOLEAN MODE); +DROP TABLE t1; + --echo End of 4.1 tests diff --git a/mysys/charset.c b/mysys/charset.c index 6f2d4d3c347..f0ac61ceed5 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -673,3 +673,43 @@ CHARSET_INFO *fs_character_set() return fs_cset_cache; } #endif + + +/** + @brief Find compatible character set with ctype. + + @param[in] original_cs Original character set + + @note + 128 my_charset_ucs2_general_uca ->192 my_charset_utf8_general_uca_ci + 129 my_charset_ucs2_icelandic_uca_ci ->193 my_charset_utf8_icelandic_uca_ci + 130 my_charset_ucs2_latvian_uca_ci ->194 my_charset_utf8_latvian_uca_ci + 131 my_charset_ucs2_romanian_uca_ci ->195 my_charset_utf8_romanian_uca_ci + 132 my_charset_ucs2_slovenian_uca_ci ->196 my_charset_utf8_slovenian_uca_ci + 133 my_charset_ucs2_polish_uca_ci ->197 my_charset_utf8_polish_uca_ci + 134 my_charset_ucs2_estonian_uca_ci ->198 my_charset_utf8_estonian_uca_ci + 135 my_charset_ucs2_spanish_uca_ci ->199 my_charset_utf8_spanish_uca_ci + 136 my_charset_ucs2_swedish_uca_ci ->200 my_charset_utf8_swedish_uca_ci + 137 my_charset_ucs2_turkish_uca_ci ->201 my_charset_utf8_turkish_uca_ci + 138 my_charset_ucs2_czech_uca_ci ->202 my_charset_utf8_czech_uca_ci + 139 my_charset_ucs2_danish_uca_ci ->203 my_charset_utf8_danish_uca_ci + 140 my_charset_ucs2_lithuanian_uca_ci->204 my_charset_utf8_lithuanian_uca_ci + 141 my_charset_ucs2_slovak_uca_ci ->205 my_charset_utf8_slovak_uca_ci + 142 my_charset_ucs2_spanish2_uca_ci ->206 my_charset_utf8_spanish2_uca_ci + 143 my_charset_ucs2_roman_uca_ci ->207 my_charset_utf8_roman_uca_ci + 144 my_charset_ucs2_persian_uca_ci ->208 my_charset_utf8_persian_uca_ci + + @return Compatible character set or NULL. +*/ + +CHARSET_INFO *get_compatible_charset_with_ctype(CHARSET_INFO *original_cs) +{ + CHARSET_INFO *compatible_cs= 0; + DBUG_ENTER("get_compatible_charset_with_ctype"); + if (!strcmp(original_cs->csname, "ucs2") && + (compatible_cs= get_charset(original_cs->number + 64, MYF(0))) && + (!compatible_cs->ctype || + strcmp(original_cs->name + 4, compatible_cs->name + 4))) + compatible_cs= 0; + DBUG_RETURN(compatible_cs); +} diff --git a/sql/item_func.cc b/sql/item_func.cc index f71297515d6..6bfb920d7c8 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3135,13 +3135,44 @@ bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref) my_error(ER_WRONG_ARGUMENTS,MYF(0),"MATCH"); return 1; } - table=((Item_field *)item)->field->table; + /* + With prepared statements Item_func_match::fix_fields is called twice. + When it is called first time we have original item tree here and add + conversion layer for character sets that do not have ctype array a few + lines below. When it is called second time, we already have conversion + layer in item tree. + */ + table= (item->type() == Item::FIELD_ITEM) ? + ((Item_field *)item)->field->table : + ((Item_field *)((Item_func_conv *)item)->key_item())->field->table; if (!(table->file->table_flags() & HA_CAN_FULLTEXT)) { my_error(ER_TABLE_CANT_HANDLE_FT, MYF(0)); return 1; } table->fulltext_searched=1; + /* A workaround for ucs2 character set */ + if (!args[1]->collation.collation->ctype) + { + CHARSET_INFO *compatible_cs= + get_compatible_charset_with_ctype(args[1]->collation.collation); + bool rc= 1; + if (compatible_cs) + { + Item_string *conv_item= new Item_string("", 0, compatible_cs, + DERIVATION_EXPLICIT); + item= args[0]; + args[0]= conv_item; + rc= agg_item_charsets(cmp_collation, func_name(), args, arg_count, + MY_COLL_ALLOW_SUPERSET_CONV | + MY_COLL_ALLOW_COERCIBLE_CONV | + MY_COLL_DISALLOW_NONE); + args[0]= item; + } + else + my_error(ER_WRONG_ARGUMENTS, MYF(0), "MATCH"); + return rc; + } return agg_arg_collations_for_comparison(cmp_collation, args+1, arg_count-1); } From f9fc31f9675c518a265be9009226bbab6701700c Mon Sep 17 00:00:00 2001 From: "antony@pcg5ppc.xiphis.org" <> Date: Thu, 25 Oct 2007 17:23:12 -0700 Subject: [PATCH 04/33] protect bug31473 from regressing into 5.0 --- mysql-test/r/csv.result | 42 +++++++++++++++++++++++++++++++++++++++++ mysql-test/t/csv.test | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/mysql-test/r/csv.result b/mysql-test/r/csv.result index 3900597d2a6..dca4e349c8a 100644 --- a/mysql-test/r/csv.result +++ b/mysql-test/r/csv.result @@ -5029,4 +5029,46 @@ F7 FE þ LATIN SMALL LETTER THORN FF ÿ LATIN SMALL LETTER Y WITH DIAERESIS drop table t1; +create table t1(a datetime) engine=csv; +insert into t1 values(); +select * from t1; +a +0000-00-00 00:00:00 +drop table t1; +create table t1(a set('foo','bar')) engine=csv; +insert into t1 values(); +select * from t1; +a + +drop table t1; +create table t1(a varchar(32)) engine=csv; +insert into t1 values(); +select * from t1; +a + +drop table t1; +create table t1(a int) engine=csv; +insert into t1 values(); +select * from t1; +a +0 +drop table t1; +create table t1(a blob) engine=csv; +insert into t1 values(); +select * from t1; +a + +drop table t1; +create table t1(a bit(1)) engine=csv; +insert into t1 values(); +select BIN(a) from t1; +BIN(a) +0 +drop table t1; +create table t1(a enum('foo','bar') default 'foo') engine=csv; +insert into t1 values(); +select * from t1; +a +foo +drop table t1; End of 5.0 tests diff --git a/mysql-test/t/csv.test b/mysql-test/t/csv.test index b724b4ce47c..db5cb92c3e6 100644 --- a/mysql-test/t/csv.test +++ b/mysql-test/t/csv.test @@ -1427,4 +1427,37 @@ insert into t1 values (0xFF,'LATIN SMALL LETTER Y WITH DIAERESIS'); select hex(c), c, name from t1 order by 1; drop table t1; +# +# Bug #31473: does not work with NULL value in datetime field +# This bug is a 5.1 but is here to prevent 5.0 regression. +# +create table t1(a datetime) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a set('foo','bar')) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a varchar(32)) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a int) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a blob) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a bit(1)) engine=csv; +insert into t1 values(); +select BIN(a) from t1; +drop table t1; +create table t1(a enum('foo','bar') default 'foo') engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; + --echo End of 5.0 tests From ada0b493285392baa63650294be59cbcf9748f00 Mon Sep 17 00:00:00 2001 From: "antony@pcg5ppc.xiphis.org" <> Date: Thu, 25 Oct 2007 21:19:28 -0700 Subject: [PATCH 05/33] Bug#30296 "Dynamic plugins fail to load on FreeBSD" ELF executables need to be linked using the -export-dynamic option to ld(1) for symbols defined in the executable to become visible to dlsym(). Also, do not build plugins on an all-static build. --- config/ac-macros/plugins.m4 | 11 +++++++++++ configure.in | 13 ++++++++++++- sql/sql_yacc.yy | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4 index 48754563992..8dfb698709f 100644 --- a/config/ac-macros/plugins.m4 +++ b/config/ac-macros/plugins.m4 @@ -360,6 +360,17 @@ AC_DEFUN([__MYSQL_EMIT_CHECK_PLUGIN],[ AC_MSG_ERROR([cannot disable mandatory plugin]) fi [mysql_plugin_]$2=yes + ],[ + case "$with_mysqld_ldflags " in + *"-all-static "*) + # No need to build shared plugins when mysqld is linked with + # -all-static as it won't be able to load them. + if test "X[$mysql_plugin_]$2" != Xyes -a \ + "X[$with_plugin_]$2" != Xyes; then + [with_plugin_]$2=no + fi + ;; + esac ]) if test "X[$with_plugin_]$2" = Xno; then AC_MSG_RESULT([no]) diff --git a/configure.in b/configure.in index 0fe2f1b5510..0c5fe692edf 100644 --- a/configure.in +++ b/configure.in @@ -1745,7 +1745,18 @@ then LDFLAGS="$LDFLAGS -rdynamic" AC_MSG_RESULT("-rdynamic") else - AC_MSG_RESULT("none") + case "$SYSTEM_TYPE$with_mysqld_ldflags " in + *freebsd*"-all-static "*|*dragonfly*"-all-static "*) + AC_MSG_RESULT("none") + ;; + *freebsd*|*dragonfly*) + MYSQLD_EXTRA_LDFLAGS="$MYSQLD_EXTRA_LDFLAGS -export-dynamic" + AC_MSG_RESULT("-export-dynamic") + ;; + *) + AC_MSG_RESULT("none") + ;; + esac fi dnl Checks for typedefs, structures, and compiler characteristics. diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 30e62c5d7b5..16fda2886f8 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -6492,7 +6492,7 @@ bool_pri: { $$= (*$2)(0)->create($1,$3); } | bool_pri comp_op all_or_any '(' subselect ')' %prec EQ { $$= all_any_subquery_creator($1, $2, $3, $5); } - | predicate ; + | predicate ; predicate: From 8cc5fe116f85763a25634c67040d093b175aaca1 Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Fri, 26 Oct 2007 15:29:06 +0200 Subject: [PATCH 06/33] Bug#4692 - DISABLE/ENABLE KEYS waste a space Disabling and enabling indexes on a non-empty table grows the index file. Disabling indexes just sets a flag per non-unique index and does not free the index blocks of the affected indexes. Re-enabling indexes creates new indexes with new blocks. The old blocks remain unused in the index file. Fixed by dropping and re-creating all indexes if non-empty disabled indexes exist when enabling indexes. Dropping all indexes resets the internal end-of-file marker to the end of the index file header. It also clears the root block pointers of every index and clears the deleted blocks chains. This way all blocks are declared as free. --- myisam/mi_check.c | 222 +++++++++++++++++++++------- mysql-test/r/bdb_notembedded.result | 35 ----- mysql-test/r/myisam.result | 25 ++++ mysql-test/t/bdb_notembedded.test | 38 ----- mysql-test/t/myisam.test | 26 ++++ 5 files changed, 216 insertions(+), 130 deletions(-) delete mode 100644 mysql-test/r/bdb_notembedded.result delete mode 100644 mysql-test/t/bdb_notembedded.test diff --git a/myisam/mi_check.c b/myisam/mi_check.c index ed0a84e737d..c225e2bdb5c 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -1375,6 +1375,139 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) } /* chk_data_link */ +/** + @brief Drop all indexes + + @param[in] param check parameters + @param[in] info MI_INFO handle + @param[in] force if to force drop all indexes + + @return status + @retval 0 OK + @retval != 0 Error + + @note + Once allocated, index blocks remain part of the key file forever. + When indexes are disabled, no block is freed. When enabling indexes, + no block is freed either. The new indexes are create from new + blocks. (Bug #4692) + + Before recreating formerly disabled indexes, the unused blocks + must be freed. There are two options to do this: + - Follow the tree of disabled indexes, add all blocks to the + deleted blocks chain. Would require a lot of random I/O. + - Drop all blocks by clearing all index root pointers and all + delete chain pointers and resetting key_file_length to the end + of the index file header. This requires to recreate all indexes, + even those that may still be intact. + The second method is probably faster in most cases. + + When disabling indexes, MySQL disables either all indexes or all + non-unique indexes. When MySQL [re-]enables disabled indexes + (T_CREATE_MISSING_KEYS), then we either have "lost" blocks in the + index file, or there are no non-unique indexes. In the latter case, + mi_repair*() would not be called as there would be no disabled + indexes. + + If there would be more unique indexes than disabled (non-unique) + indexes, we could do the first method. But this is not implemented + yet. By now we drop and recreate all indexes when repair is called. + + However, there is an exception. Sometimes MySQL disables non-unique + indexes when the table is empty (e.g. when copying a table in + mysql_alter_table()). When enabling the non-unique indexes, they + are still empty. So there is no index block that can be lost. This + optimization is implemented in this function. + + Note that in normal repair (T_CREATE_MISSING_KEYS not set) we + recreate all enabled indexes unconditonally. We do not change the + key_map. Otherwise we invert the key map temporarily (outside of + this function) and recreate the then "seemingly" enabled indexes. + When we cannot use the optimization, and drop all indexes, we + pretend that all indexes were disabled. By the inversion, we will + then recrate all indexes. +*/ + +static int mi_drop_all_indexes(MI_CHECK *param, MI_INFO *info, my_bool force) +{ + MYISAM_SHARE *share= info->s; + MI_STATE_INFO *state= &share->state; + uint i; + int error; + DBUG_ENTER("mi_drop_all_indexes"); + + /* + If any of the disabled indexes has a key block assigned, we must + drop and recreate all indexes to avoid losing index blocks. + + If we want to recreate disabled indexes only _and_ all of these + indexes are empty, we don't need to recreate the existing indexes. + */ + if (!force && (param->testflag & T_CREATE_MISSING_KEYS)) + { + DBUG_PRINT("repair", ("creating missing indexes")); + for (i= 0; i < share->base.keys; i++) + { + DBUG_PRINT("repair", ("index #: %u key_root: 0x%lx active: %d", + i, (long) state->key_root[i], + mi_is_key_active(state->key_map, i))); + if ((state->key_root[i] != HA_OFFSET_ERROR) && + !mi_is_key_active(state->key_map, i)) + { + /* + This index has at least one key block and it is disabled. + We would lose its block(s) if would just recreate it. + So we need to drop and recreate all indexes. + */ + DBUG_PRINT("repair", ("nonempty and disabled: recreate all")); + break; + } + } + if (i >= share->base.keys) + { + /* + All of the disabled indexes are empty. We can just recreate them. + Flush dirty blocks of this index file from key cache and remove + all blocks of this index file from key cache. + */ + DBUG_PRINT("repair", ("all disabled are empty: create missing")); + error= flush_key_blocks(share->key_cache, share->kfile, + FLUSH_FORCE_WRITE); + goto end; + } + /* + We do now drop all indexes and declare them disabled. With the + T_CREATE_MISSING_KEYS flag, mi_repair*() will recreate all + disabled indexes and enable them. + */ + mi_clear_all_keys_active(state->key_map); + DBUG_PRINT("repair", ("declared all indexes disabled")); + } + + /* Remove all key blocks of this index file from key cache. */ + if ((error= flush_key_blocks(share->key_cache, share->kfile, + FLUSH_IGNORE_CHANGED))) + goto end; + + /* Clear index root block pointers. */ + for (i= 0; i < share->base.keys; i++) + state->key_root[i]= HA_OFFSET_ERROR; + + /* Clear the delete chains. */ + for (i= 0; i < state->header.max_block_size; i++) + state->key_del[i]= HA_OFFSET_ERROR; + + /* Reset index file length to end of index file header. */ + info->state->key_file_length= share->base.keystart; + + DBUG_PRINT("repair", ("dropped all indexes")); + /* error= 0; set by last (error= flush_key_bocks()). */ + + end: + DBUG_RETURN(error); +} + + /* Recover old table by reading each record and writing all keys */ /* Save new datafile-name in temp_filename */ @@ -1382,7 +1515,6 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, my_string name, int rep_quick) { int error,got_error; - uint i; ha_rows start_records,new_header_length; my_off_t del; File new_file; @@ -1486,25 +1618,10 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, info->update= (short) (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); - /* - Clear all keys. Note that all key blocks allocated until now remain - "dead" parts of the key file. (Bug #4692) - */ - for (i=0 ; i < info->s->base.keys ; i++) - share->state.key_root[i]= HA_OFFSET_ERROR; - - /* Drop the delete chain. */ - for (i=0 ; i < share->state.header.max_block_size ; i++) - share->state.key_del[i]= HA_OFFSET_ERROR; - - /* - If requested, activate (enable) all keys in key_map. In this case, - all indexes will be (re-)built. - */ + /* This function always recreates all enabled indexes. */ if (param->testflag & T_CREATE_MISSING_KEYS) mi_set_all_keys_active(share->state.key_map, share->base.keys); - - info->state->key_file_length=share->base.keystart; + mi_drop_all_indexes(param, info, TRUE); lock_memory(param); /* Everything is alloced */ @@ -2105,7 +2222,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, ulong *rec_per_key_part; char llbuff[22]; SORT_INFO sort_info; - ulonglong key_map=share->state.key_map; + ulonglong key_map; DBUG_ENTER("mi_repair_by_sort"); start_records=info->state->records; @@ -2179,25 +2296,14 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, } info->update= (short) (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); - if (!(param->testflag & T_CREATE_MISSING_KEYS)) + + /* Optionally drop indexes and optionally modify the key_map. */ + mi_drop_all_indexes(param, info, FALSE); + key_map= share->state.key_map; + if (param->testflag & T_CREATE_MISSING_KEYS) { - /* - Flush key cache for this file if we are calling this outside - myisamchk - */ - flush_key_blocks(share->key_cache,share->kfile, FLUSH_IGNORE_CHANGED); - /* Clear the pointers to the given rows */ - for (i=0 ; i < share->base.keys ; i++) - share->state.key_root[i]= HA_OFFSET_ERROR; - for (i=0 ; i < share->state.header.max_block_size ; i++) - share->state.key_del[i]= HA_OFFSET_ERROR; - info->state->key_file_length=share->base.keystart; - } - else - { - if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_FORCE_WRITE)) - goto err; - key_map= ~key_map; /* Create the missing keys */ + /* Invert the copied key_map to recreate all disabled indexes. */ + key_map= ~key_map; } sort_info.info=info; @@ -2240,6 +2346,10 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, sort_param.read_cache=param->read_cache; sort_param.keyinfo=share->keyinfo+sort_param.key; sort_param.seg=sort_param.keyinfo->seg; + /* + Skip this index if it is marked disabled in the copied + (and possibly inverted) key_map. + */ if (! mi_is_key_active(key_map, sort_param.key)) { /* Remember old statistics for key */ @@ -2247,6 +2357,8 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, (char*) (share->state.rec_per_key_part + (uint) (rec_per_key_part - param->rec_per_key_part)), sort_param.keyinfo->keysegs*sizeof(*rec_per_key_part)); + DBUG_PRINT("repair", ("skipping seemingly disabled index #: %u", + sort_param.key)); continue; } @@ -2302,8 +2414,11 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_STATISTICS) update_key_parts(sort_param.keyinfo, rec_per_key_part, sort_param.unique, param->stats_method == MI_STATS_METHOD_IGNORE_NULLS? - sort_param.notnull: NULL,(ulonglong) info->state->records); + sort_param.notnull: NULL, + (ulonglong) info->state->records); + /* Enable this index in the permanent (not the copied) key_map. */ mi_set_key_active(share->state.key_map, sort_param.key); + DBUG_PRINT("repair", ("set enabled index #: %u", sort_param.key)); if (sort_param.fix_datafile) { @@ -2504,7 +2619,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, IO_CACHE new_data_cache; /* For non-quick repair. */ IO_CACHE_SHARE io_share; SORT_INFO sort_info; - ulonglong key_map=share->state.key_map; + ulonglong key_map; pthread_attr_t thr_attr; DBUG_ENTER("mi_repair_parallel"); @@ -2608,25 +2723,14 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, } info->update= (short) (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); - if (!(param->testflag & T_CREATE_MISSING_KEYS)) + + /* Optionally drop indexes and optionally modify the key_map. */ + mi_drop_all_indexes(param, info, FALSE); + key_map= share->state.key_map; + if (param->testflag & T_CREATE_MISSING_KEYS) { - /* - Flush key cache for this file if we are calling this outside - myisamchk - */ - flush_key_blocks(share->key_cache,share->kfile, FLUSH_IGNORE_CHANGED); - /* Clear the pointers to the given rows */ - for (i=0 ; i < share->base.keys ; i++) - share->state.key_root[i]= HA_OFFSET_ERROR; - for (i=0 ; i < share->state.header.max_block_size ; i++) - share->state.key_del[i]= HA_OFFSET_ERROR; - info->state->key_file_length=share->base.keystart; - } - else - { - if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_FORCE_WRITE)) - goto err; - key_map= ~key_map; /* Create the missing keys */ + /* Invert the copied key_map to recreate all disabled indexes. */ + key_map= ~key_map; } sort_info.info=info; @@ -2682,6 +2786,10 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, sort_param[i].key=key; sort_param[i].keyinfo=share->keyinfo+key; sort_param[i].seg=sort_param[i].keyinfo->seg; + /* + Skip this index if it is marked disabled in the copied + (and possibly inverted) key_map. + */ if (! mi_is_key_active(key_map, key)) { /* Remember old statistics for key */ diff --git a/mysql-test/r/bdb_notembedded.result b/mysql-test/r/bdb_notembedded.result deleted file mode 100644 index 14cb5fad915..00000000000 --- a/mysql-test/r/bdb_notembedded.result +++ /dev/null @@ -1,35 +0,0 @@ -set autocommit=1; -reset master; -create table bug16206 (a int); -insert into bug16206 values(1); -start transaction; -insert into bug16206 values(2); -commit; -show binlog events; -Log_name Pos Event_type Server_id End_log_pos Info -f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 -f n Query 1 n use `test`; create table bug16206 (a int) -f n Query 1 n use `test`; insert into bug16206 values(1) -f n Query 1 n use `test`; insert into bug16206 values(2) -drop table bug16206; -reset master; -create table bug16206 (a int) engine= bdb; -insert into bug16206 values(0); -insert into bug16206 values(1); -start transaction; -insert into bug16206 values(2); -commit; -insert into bug16206 values(3); -show binlog events; -Log_name Pos Event_type Server_id End_log_pos Info -f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 -f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb -f n Query 1 n use `test`; insert into bug16206 values(0) -f n Query 1 n use `test`; insert into bug16206 values(1) -f n Query 1 n use `test`; BEGIN -f n Query 1 n use `test`; insert into bug16206 values(2) -f n Query 1 n use `test`; COMMIT -f n Query 1 n use `test`; insert into bug16206 values(3) -drop table bug16206; -set autocommit=0; -End of 5.0 tests diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 7fc29cd13ca..176d0e97012 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -1806,4 +1806,29 @@ SELECT a FROM t1 FORCE INDEX (inx) WHERE a=1; a 1 DROP TABLE t1; +CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE INDEX (c1), INDEX (c2)) ENGINE=MYISAM; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 0 # # # 1024 # # # # # # # +INSERT INTO t1 VALUES (1,1); +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 DISABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 ENABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 DISABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 ENABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/bdb_notembedded.test b/mysql-test/t/bdb_notembedded.test deleted file mode 100644 index 24e64ebbfb2..00000000000 --- a/mysql-test/t/bdb_notembedded.test +++ /dev/null @@ -1,38 +0,0 @@ --- source include/not_embedded.inc --- source include/have_bdb.inc - -# -# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode -# -set autocommit=1; - -let $VERSION=`select version()`; - -reset master; -create table bug16206 (a int); -insert into bug16206 values(1); -start transaction; -insert into bug16206 values(2); -commit; ---replace_result $VERSION VERSION ---replace_column 1 f 2 n 5 n -show binlog events; -drop table bug16206; - -reset master; -create table bug16206 (a int) engine= bdb; -insert into bug16206 values(0); -insert into bug16206 values(1); -start transaction; -insert into bug16206 values(2); -commit; -insert into bug16206 values(3); ---replace_result $VERSION VERSION ---replace_column 1 f 2 n 5 n -show binlog events; -drop table bug16206; - -set autocommit=0; - - ---echo End of 5.0 tests diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index d5f403616c8..ad223dc2664 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -1161,4 +1161,30 @@ ALTER TABLE t1 ENABLE KEYS; SELECT a FROM t1 FORCE INDEX (inx) WHERE a=1; DROP TABLE t1; +# +# Bug#4692 - DISABLE/ENABLE KEYS waste a space +# +CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE INDEX (c1), INDEX (c2)) ENGINE=MYISAM; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +INSERT INTO t1 VALUES (1,1); +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 DISABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 ENABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 DISABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 ENABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +#--exec ls -log var/master-data/test/t1.MYI +#--exec myisamchk -dvv var/master-data/test/t1.MYI +#--exec myisamchk -iev var/master-data/test/t1.MYI +DROP TABLE t1; + --echo End of 5.0 tests From cbd3dfbbcb85ffd4c3aecbf238857e9dc0a95be8 Mon Sep 17 00:00:00 2001 From: "svoj@mysql.com/june.mysql.com" <> Date: Tue, 30 Oct 2007 14:46:43 +0400 Subject: [PATCH 07/33] BUG#11392 - fulltext search bug Fulltext boolean mode phrase search may crash server on platforms where size of pointer is not equal to size of unsigned integer (in other words some 64-bit platforms). The problem was integer overflow. Affects 4.1 only. --- myisam/ft_boolean_search.c | 3 ++- mysql-test/r/fulltext.result | 6 ++++++ mysql-test/t/fulltext.test | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/myisam/ft_boolean_search.c b/myisam/ft_boolean_search.c index f1ff8f6d886..fad25abcc6c 100644 --- a/myisam/ft_boolean_search.c +++ b/myisam/ft_boolean_search.c @@ -446,7 +446,8 @@ static int _ftb_strstr(const byte *s0, const byte *e0, { if (cs->coll->instr(cs, p0, e0 - p0, s1, e1 - s1, m, 2) != 2) return(0); - if ((!s_after || p0 + m[1].beg == s0 || !true_word_char(cs, p0[m[1].beg-1])) && + if ((!s_after || p0 + m[1].beg == s0 || + !true_word_char(cs, p0[(int) m[1].beg - 1])) && (!e_before || p0 + m[1].end == e0 || !true_word_char(cs, p0[m[1].end]))) return(1); p0+= m[1].beg; diff --git a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result index 3700ace4b19..af41adf3a24 100644 --- a/mysql-test/r/fulltext.result +++ b/mysql-test/r/fulltext.result @@ -454,3 +454,9 @@ ALTER TABLE t1 DISABLE KEYS; SELECT * FROM t1 WHERE MATCH(a) AGAINST('test'); ERROR HY000: Can't find FULLTEXT index matching the column list DROP TABLE t1; +CREATE TABLE t1(a TEXT); +INSERT INTO t1 VALUES(' aaaaa aaaa'); +SELECT * FROM t1 WHERE MATCH(a) AGAINST ('"aaaa"' IN BOOLEAN MODE); +a + aaaaa aaaa +DROP TABLE t1; diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test index 1a9a6b578dc..661e93d8d87 100644 --- a/mysql-test/t/fulltext.test +++ b/mysql-test/t/fulltext.test @@ -379,4 +379,12 @@ ALTER TABLE t1 DISABLE KEYS; SELECT * FROM t1 WHERE MATCH(a) AGAINST('test'); DROP TABLE t1; +# +# BUG#11392 - fulltext search bug +# +CREATE TABLE t1(a TEXT); +INSERT INTO t1 VALUES(' aaaaa aaaa'); +SELECT * FROM t1 WHERE MATCH(a) AGAINST ('"aaaa"' IN BOOLEAN MODE); +DROP TABLE t1; + # End of 4.1 tests From 250f5769bf37d5de5c02b25e08567e7814a37f6d Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Tue, 30 Oct 2007 12:03:44 +0100 Subject: [PATCH 08/33] Post-merge fix --- mysql-test/t/variables.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index f474d166fae..9fa14ba3907 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -161,7 +161,7 @@ select * from information_schema.session_variables where variable_name like 'net set net_buffer_length=1; show variables like 'net_buffer_length'; select * from information_schema.session_variables where variable_name like 'net_buffer_length'; ---warning 1292 +#warning 1292 set net_buffer_length=2000000000; show variables like 'net_buffer_length'; select * from information_schema.session_variables where variable_name like 'net_buffer_length'; From f8c2f9d195a9aa0fd0ba53f1ed0fec6589e19749 Mon Sep 17 00:00:00 2001 From: "svoj@mysql.com/june.mysql.com" <> Date: Thu, 1 Nov 2007 16:27:01 +0400 Subject: [PATCH 09/33] BUG#31950 - repair table hangs while processing multicolumn utf8 fulltext index Having a table with broken multibyte characters may cause fulltext parser dead-loop. Since normally it is not possible to insert broken multibyte sequence into a table, this problem may arise only if table is damaged. Affected statements are: - CHECK/REPAIR against damaged table with fulltext index; - boolean mode phrase search against damaged table with or without fulltext inex; - boolean mode searches without index; - nlq searches. No test case for this fix. Affects 5.0 only. --- myisam/ft_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/myisam/ft_parser.c b/myisam/ft_parser.c index 6d68542e4e2..1d3a19dd8c6 100644 --- a/myisam/ft_parser.c +++ b/myisam/ft_parser.c @@ -188,7 +188,7 @@ byte ft_simple_get_word(CHARSET_INFO *cs, byte **start, const byte *end, do { - for (;; doc+= mbl) + for (;; doc+= (mbl ? mbl : 1)) { if (doc >= end) DBUG_RETURN(0); if (true_word_char(cs, *doc)) break; From 382f62b10b63894faa739cc61d18e3d5a268713a Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Thu, 1 Nov 2007 15:03:09 +0100 Subject: [PATCH 10/33] Bug#31909 - New gis.test creates warnings files Comment sign of -- at line begin in test files lead to warnings from mysqltest. Changed -- to #. --- mysql-test/include/gis_keys.inc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mysql-test/include/gis_keys.inc b/mysql-test/include/gis_keys.inc index 295e0c48234..c75311f062a 100644 --- a/mysql-test/include/gis_keys.inc +++ b/mysql-test/include/gis_keys.inc @@ -13,20 +13,20 @@ CREATE TABLE t2 (p POINT, INDEX(p)); INSERT INTO t1 VALUES (POINTFROMTEXT('POINT(1 2)')); INSERT INTO t2 VALUES (POINTFROMTEXT('POINT(1 2)')); --- no index, returns 1 as expected +# no index, returns 1 as expected SELECT COUNT(*) FROM t1 WHERE p=POINTFROMTEXT('POINT(1 2)'); --- with index, returns 1 as expected --- EXPLAIN shows that the index is not used though --- due to the "most rows covered anyway, so a scan is more effective" rule +# with index, returns 1 as expected +# EXPLAIN shows that the index is not used though +# due to the "most rows covered anyway, so a scan is more effective" rule EXPLAIN SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)'); SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)'); --- adding another row to the table so that --- the "most rows covered" rule doesn't kick in anymore --- now EXPLAIN shows the index used on the table --- and we're getting the wrong result again +# adding another row to the table so that +# the "most rows covered" rule doesn't kick in anymore +# now EXPLAIN shows the index used on the table +# and we're getting the wrong result again INSERT INTO t1 VALUES (POINTFROMTEXT('POINT(1 2)')); INSERT INTO t2 VALUES (POINTFROMTEXT('POINT(1 2)')); EXPLAIN From 1b165ef41f8ef2283264ff1ef6c5e719fea60e4e Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Thu, 1 Nov 2007 15:04:23 +0100 Subject: [PATCH 11/33] Post-merge fix --- mysql-test/t/variables.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 63bc3c5e273..b661d0e8ae7 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -139,7 +139,7 @@ show global variables like 'net_%'; show session variables like 'net_%'; set net_buffer_length=1; show variables like 'net_buffer_length'; ---warning 1292 +#warning 1292 set net_buffer_length=2000000000; show variables like 'net_buffer_length'; From bcfe0fa67eb32df9ab3df117c9ff11f1d271da5b Mon Sep 17 00:00:00 2001 From: "antony@pcg5ppc.xiphis.org" <> Date: Thu, 1 Nov 2007 12:30:03 -0700 Subject: [PATCH 12/33] Bug#30671 "ALTER SERVER can cause server to crash" While retrieving values, it would erronously set the socket value to NULL and attempt to use it in strcmp(). Ensure it is correctly set to "" so that strcmp may not crash. --- mysql-test/r/federated_server.result | 10 +++++++++- mysql-test/t/federated_server.test | 14 +++++++++++++- sql/sql_servers.cc | 4 ++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/federated_server.result b/mysql-test/r/federated_server.result index 0905aabb075..32717b4f0e3 100644 --- a/mysql-test/r/federated_server.result +++ b/mysql-test/r/federated_server.result @@ -253,6 +253,14 @@ drop user guest_usage@localhost; drop user guest_select@localhost; drop table federated.t1; drop server 's1'; +create server 's1' foreign data wrapper 'mysql' options (port 3306); +alter server 's1' options +(host 'localhost', database '', user '', +password '', socket '', owner '', port 3306); +alter server 's1' options +(host 'localhost', database 'database1', user '', +password '', socket '', owner '', port 3306); +drop server 's1'; # End of 5.1 tests use test; create procedure p1 () @@ -262,7 +270,7 @@ DECLARE e INT DEFAULT 0; DECLARE i INT; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET e = e + 1; SET i = sleep(5); -WHILE v < 20000 do +WHILE v < 10000 do CREATE SERVER s FOREIGN DATA WRAPPER mysql OPTIONS (USER 'Remote', HOST '192.168.1.106', DATABASE 'test'); diff --git a/mysql-test/t/federated_server.test b/mysql-test/t/federated_server.test index 87b67720104..444285ac045 100644 --- a/mysql-test/t/federated_server.test +++ b/mysql-test/t/federated_server.test @@ -2,7 +2,7 @@ # if federated can utilise the servers table # should work with embedded server after mysqltest is fixed -- source include/not_embedded.inc --- source include/federated.inc; +-- source include/federated.inc -- source include/big_test.inc connection slave; @@ -282,6 +282,18 @@ drop user guest_select@localhost; drop table federated.t1; drop server 's1'; +# +# Bug#30671 - ALTER SERVER causes the server to crash +# +create server 's1' foreign data wrapper 'mysql' options (port 3306); +alter server 's1' options + (host 'localhost', database '', user '', + password '', socket '', owner '', port 3306); +# The next statement would crash unpatched server +alter server 's1' options + (host 'localhost', database 'database1', user '', + password '', socket '', owner '', port 3306); +drop server 's1'; --echo # End of 5.1 tests diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index a780c561ffe..543884fdfa6 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -289,7 +289,7 @@ get_server_from_table_to_cache(TABLE *table) { /* alloc a server struct */ char *ptr; - char *blank= (char*)""; + char * const blank= (char*)""; FOREIGN_SERVER *server= (FOREIGN_SERVER *)alloc_root(&mem, sizeof(FOREIGN_SERVER)); DBUG_ENTER("get_server_from_table_to_cache"); @@ -312,7 +312,7 @@ get_server_from_table_to_cache(TABLE *table) server->port= server->sport ? atoi(server->sport) : 0; ptr= get_field(&mem, table->field[6]); - server->socket= ptr && strlen(ptr) ? ptr : NULL; + server->socket= ptr && strlen(ptr) ? ptr : blank; ptr= get_field(&mem, table->field[7]); server->scheme= ptr ? ptr : blank; ptr= get_field(&mem, table->field[8]); From 3afce4aa2ca1bd0dcf694e23163d05ff8a9d96ce Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Fri, 2 Nov 2007 09:58:29 +0100 Subject: [PATCH 13/33] Bug#32048 - innodb_mysql.test produces warnings files Typo --#echo at line begin in test files lead to warnings from mysqltest. Changed to --echo #. --- mysql-test/include/mix1.inc | 2 +- mysql-test/r/innodb_mysql.result | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mysql-test/include/mix1.inc b/mysql-test/include/mix1.inc index c8d3ba79e39..211bd0b4908 100644 --- a/mysql-test/include/mix1.inc +++ b/mysql-test/include/mix1.inc @@ -1163,7 +1163,7 @@ CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256)) ENGINE = $engine_type; INSERT INTO t1 VALUES (1,2); ---#echo 1. test for locking: +--echo # 1. test for locking: BEGIN; --enable_info diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index 44d874ef018..2332056ec39 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1426,6 +1426,7 @@ SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256)) ENGINE = InnoDB; INSERT INTO t1 VALUES (1,2); +# 1. test for locking: BEGIN; UPDATE t1 SET b = 12 WHERE a = 1; affected rows: 1 From 8d4b8423f71d0fe64e4ed293470698c4ac6f60dc Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Fri, 2 Nov 2007 10:11:26 +0100 Subject: [PATCH 14/33] Bug#31030 - rpl000015.test fails if $MYSQL_TCP_PORT != 3306 Preliminarily disabled test case --- mysql-test/t/disabled.def | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index 9bfe9567d83..80b28e11da6 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -10,3 +10,4 @@ # ############################################################################## +rpl000015 : Bug#31030 - rpl000015.test fails if $MYSQL_TCP_PORT != 3306 From 626e12624e15a2fd2e7c61eb8bbcf3e6497bc57d Mon Sep 17 00:00:00 2001 From: "antony@pcg5ppc.xiphis.org" <> Date: Fri, 2 Nov 2007 14:25:48 -0700 Subject: [PATCH 15/33] fix for 2.4.6 bug should be properly enclosed to not break other versions. --- sql/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 299f4ae4285..77abc4e6fa5 100755 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -90,12 +90,14 @@ TARGET_LINK_LIBRARIES(mysqld SET_TARGET_PROPERTIES(mysqld PROPERTIES OUTPUT_NAME mysqld${MYSQLD_EXE_SUFFIX}) +IF(cmake_version EQUAL 20406) # Work around for 2.4.6 bug, OUTPUT_NAME will not set the right .PDB # file name. Note that COMPILE_FLAGS set some temporary pdb during build, # LINK_FLAGS sets the real one. SET_TARGET_PROPERTIES(mysqld PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/mysqld${MYSQLD_EXE_SUFFIX}.pdb" LINK_FLAGS "/PDB:${CMAKE_CFG_INTDIR}/mysqld${MYSQLD_EXE_SUFFIX}.pdb") +ENDIF(cmake_version EQUAL 20406) IF(EMBED_MANIFESTS) MYSQL_EMBED_MANIFEST("mysqld" "asInvoker") From 241cd5f969e04c0b9e294f7c2d7c3c7e708d86b8 Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Mon, 5 Nov 2007 10:57:52 +0100 Subject: [PATCH 16/33] Bug#4692 - DISABLE/ENABLE KEYS waste a space Fixed absurd compiler warnings of a Suse 10.1 system. --- storage/myisam/mi_check.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index feb639d48f9..7cd35295cb0 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -2225,6 +2225,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, SORT_INFO sort_info; ulonglong key_map; DBUG_ENTER("mi_repair_by_sort"); + LINT_INIT(key_map); start_records=info->state->records; got_error=1; @@ -2649,6 +2650,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, ulonglong key_map; pthread_attr_t thr_attr; DBUG_ENTER("mi_repair_parallel"); + LINT_INIT(key_map); start_records=info->state->records; got_error=1; From aac68041eff685f94d8a88bfb86d2d45e6116504 Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Mon, 5 Nov 2007 14:37:00 +0100 Subject: [PATCH 17/33] Bug#32107 - ctype_uca.test produces warnings files Comment sign of -- at line begin in test files lead to warnings from mysqltest. Changed -- to #. --- mysql-test/t/ctype_uca.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/t/ctype_uca.test b/mysql-test/t/ctype_uca.test index 17632e7c8fc..695a21adbf5 100644 --- a/mysql-test/t/ctype_uca.test +++ b/mysql-test/t/ctype_uca.test @@ -530,7 +530,7 @@ create table t1 ( a varchar(255), key a(a) ) character set utf8 collate utf8_czech_ci; --- In Czech 'ch' is a single letter between 'h' and 'i' +# In Czech 'ch' is a single letter between 'h' and 'i' insert into t1 values ('b'),('c'),('d'),('e'),('f'),('g'),('h'),('ch'),('i'),('j'); select * from t1 where a like 'c%'; From 2481d2c1e30b07640c2c45af56e08a89acd79b96 Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Mon, 5 Nov 2007 14:44:38 +0100 Subject: [PATCH 18/33] Bug#32108 - subselect.test produces warnings files Comment sign of -- at line begin in test files lead to warnings from mysqltest. Changed -- to #. --- mysql-test/t/subselect.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index d076ca6bd33..86d2aec870c 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -2970,7 +2970,7 @@ DROP TABLE t1,t2; CREATE TABLE t1 (a INT, b INT); INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2); --- returns no rows, when it should +# returns no rows, when it should SELECT a1.a, COUNT(*) FROM t1 a1 WHERE a1.a = 1 AND EXISTS( SELECT a2.a FROM t1 a2 WHERE a2.a = a1.a) GROUP BY a1.a; From 3eaf82a17504158aa29b1f39360f365428943de4 Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Mon, 5 Nov 2007 16:25:40 +0100 Subject: [PATCH 19/33] Bug#31210 - INSERT DELAYED crashes server when used on partitioned table Trying INSERT DELAYED on a partitioned table, that has not been used right before, crashes the server. When a table is used for select or update, it is kept open for some time. This period I mean with "right before". Information about partitioning of a table is stored in form of a string in the .frm file. Parsing of this string requires a correctly set up lexical analyzer (lex). The partitioning code uses a new temporary instance of a lex. But it does still refer to the previously active lex. The delayd insert thread does not initialize its lex though... Added initialization for thd->lex before open table in the delayed thread and at all other places where it is necessary to call lex_start() if all tables would be partitioned and need to parse the .frm file. --- mysql-test/r/partition_hash.result | 4 ++++ mysql-test/t/partition_hash.test | 8 ++++++++ sql/event_scheduler.cc | 1 + sql/events.cc | 1 + sql/ha_ndbcluster_binlog.cc | 1 + sql/slave.cc | 1 + sql/sql_acl.cc | 2 ++ sql/sql_base.cc | 3 +++ sql/sql_connect.cc | 1 + sql/sql_insert.cc | 7 ++++++- sql/sql_lex.cc | 3 ++- sql/sql_lex.h | 1 + sql/sql_plugin.cc | 1 + sql/sql_servers.cc | 1 + sql/sql_udf.cc | 1 + sql/table.cc | 3 +++ sql/tztime.cc | 1 + 17 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/partition_hash.result b/mysql-test/r/partition_hash.result index 9a82a36d902..3ebbd020db4 100644 --- a/mysql-test/r/partition_hash.result +++ b/mysql-test/r/partition_hash.result @@ -183,3 +183,7 @@ c1 c2 c3 182 abc 2002-11-09 184 abc 2002-11-22 drop table t1; +CREATE TABLE t1 (c1 INT) ENGINE=MyISAM PARTITION BY HASH(c1) PARTITIONS 1; +INSERT DELAYED INTO t1 VALUES (1); +ERROR HY000: Table storage engine for 't1' doesn't have this option +DROP TABLE t1; diff --git a/mysql-test/t/partition_hash.test b/mysql-test/t/partition_hash.test index 98add060a76..16c3e2b3b9b 100644 --- a/mysql-test/t/partition_hash.test +++ b/mysql-test/t/partition_hash.test @@ -144,3 +144,11 @@ select * from t1 where c3 between '2002-01-01' and '2002-12-31'; drop table t1; +# +# Bug#31210 - INSERT DELAYED crashes server when used on partitioned table +# +CREATE TABLE t1 (c1 INT) ENGINE=MyISAM PARTITION BY HASH(c1) PARTITIONS 1; +--error ER_ILLEGAL_HA +INSERT DELAYED INTO t1 VALUES (1); +DROP TABLE t1; + diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index b03b51f1134..52c7d291da7 100644 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -127,6 +127,7 @@ post_init_event_thread(THD *thd) thd->cleanup(); return TRUE; } + lex_start(thd); pthread_mutex_lock(&LOCK_thread_count); threads.append(thd); diff --git a/sql/events.cc b/sql/events.cc index 5246bccc388..84301d811f0 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -884,6 +884,7 @@ Events::init(my_bool opt_noacl) */ thd->thread_stack= (char*) &thd; thd->store_globals(); + lex_start(thd); /* We will need Event_db_repository anyway, even if the scheduler is diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc index 5d5c8a26447..5f67c6f73ea 100644 --- a/sql/ha_ndbcluster_binlog.cc +++ b/sql/ha_ndbcluster_binlog.cc @@ -3621,6 +3621,7 @@ pthread_handler_t ndb_binlog_thread_func(void *arg) pthread_exit(0); DBUG_RETURN(NULL); } + lex_start(thd); thd->init_for_queries(); thd->command= COM_DAEMON; diff --git a/sql/slave.cc b/sql/slave.cc index fcbd4eb841b..a89d5262cbf 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1510,6 +1510,7 @@ static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type) delete thd; DBUG_RETURN(-1); } + lex_start(thd); if (thd_type == SLAVE_THD_SQL) thd->proc_info= "Waiting for the next event in relay log"; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 7e017d7d028..495b7e06c8a 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -277,6 +277,7 @@ my_bool acl_init(bool dont_read_acl_tables) DBUG_RETURN(1); /* purecov: inspected */ thd->thread_stack= (char*) &thd; thd->store_globals(); + lex_start(thd); /* It is safe to call acl_reload() since acl_* arrays and hashes which will be freed there are global static objects and thus are initialized @@ -3493,6 +3494,7 @@ my_bool grant_init() DBUG_RETURN(1); /* purecov: deadcode */ thd->thread_stack= (char*) &thd; thd->store_globals(); + lex_start(thd); return_val= grant_reload(thd); delete thd; /* Remember that we don't have a THD */ diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 337fde53dac..119da29c316 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2248,6 +2248,9 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, HASH_SEARCH_STATE state; DBUG_ENTER("open_table"); + /* Parsing of partitioning information from .frm needs thd->lex set up. */ + DBUG_ASSERT(thd->lex->is_lex_started); + /* find a unused table in the open table cache */ if (refresh) *refresh=0; diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 6bb0f62d843..225a54448ac 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -1087,6 +1087,7 @@ pthread_handler_t handle_one_connection(void *arg) { NET *net= &thd->net; + lex_start(thd); if (login_connection(thd)) goto end_thread; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index ebbf4cafb19..fb4a563c4d6 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2264,7 +2264,12 @@ pthread_handler_t handle_delayed_insert(void *arg) goto err; } - /* open table */ + /* + Open table requires an initialized lex in case the table is + partitioned. The .frm file contains a partial SQL string which is + parsed using a lex, that depends on initialized thd->lex. + */ + lex_start(thd); if (!(di->table=open_ltable(thd, &di->table_list, TL_WRITE_DELAYED, 0))) { thd->fatal_error(); // Abort waiting inserts diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 0a5f83af400..26c9790923a 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -362,6 +362,7 @@ void lex_start(THD *thd) lex->server_options.owner= 0; lex->server_options.port= -1; + lex->is_lex_started= TRUE; DBUG_VOID_RETURN; } @@ -2138,7 +2139,7 @@ void Query_tables_list::destroy_query_tables_list() st_lex::st_lex() :result(0), yacc_yyss(0), yacc_yyvs(0), - sql_command(SQLCOM_END), option_type(OPT_DEFAULT) + sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0) { my_init_dynamic_array2(&plugins, sizeof(plugin_ref), diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 08104769704..d0822fed3c2 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1703,6 +1703,7 @@ typedef struct st_lex : public Query_tables_list st_alter_tablespace *alter_tablespace_info; bool escape_used; + bool is_lex_started; /* If lex_start() did run. For debugging. */ st_lex(); diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 2af528f6699..c8d9116f196 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1329,6 +1329,7 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv) } new_thd->thread_stack= (char*) &tables; new_thd->store_globals(); + lex_start(new_thd); new_thd->db= my_strdup("mysql", MYF(0)); new_thd->db_length= 5; bzero((uchar*)&tables, sizeof(tables)); diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index a780c561ffe..d1d7801538c 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -140,6 +140,7 @@ bool servers_init(bool dont_read_servers_table) DBUG_RETURN(TRUE); thd->thread_stack= (char*) &thd; thd->store_globals(); + lex_start(thd); /* It is safe to call servers_reload() since servers_* arrays and hashes which will be freed there are global static objects and thus are initialized diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 19582af38f4..112280a10b2 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -135,6 +135,7 @@ void udf_init() initialized = 1; new_thd->thread_stack= (char*) &new_thd; new_thd->store_globals(); + lex_start(new_thd); new_thd->set_db(db, sizeof(db)-1); bzero((uchar*) &tables,sizeof(tables)); diff --git a/sql/table.cc b/sql/table.cc index ccddbf8134b..26008f0aa19 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1608,6 +1608,9 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, DBUG_PRINT("enter",("name: '%s.%s' form: 0x%lx", share->db.str, share->table_name.str, (long) outparam)); + /* Parsing of partitioning information from .frm needs thd->lex set up. */ + DBUG_ASSERT(thd->lex->is_lex_started); + error= 1; bzero((char*) outparam, sizeof(*outparam)); outparam->in_use= thd; diff --git a/sql/tztime.cc b/sql/tztime.cc index 9eb38e97827..920f8e87d13 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1575,6 +1575,7 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) DBUG_RETURN(1); thd->thread_stack= (char*) &thd; thd->store_globals(); + lex_start(thd); /* Init all memory structures that require explicit destruction */ if (hash_init(&tz_names, &my_charset_latin1, 20, From 30b409bd6fc66c5c2cfde023810c837a72fb2b50 Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Tue, 6 Nov 2007 13:41:32 +0100 Subject: [PATCH 20/33] Bug#4692 - DISABLE/ENABLE KEYS waste a space Disabling and enabling indexes on a non-empty table grows the index file. Disabling indexes just sets a flag per non-unique index and does not free the index blocks of the affected indexes. Re-enabling indexes creates new indexes with new blocks. The old blocks remain unused in the index file. Fixed by dropping and re-creating all indexes if non-empty disabled indexes exist when enabling indexes. Dropping all indexes resets the internal end-of-file marker to the end of the index file header. It also clears the root block pointers of every index and clears the deleted blocks chains. This way all blocks are declared as free. --- myisam/mi_check.c | 224 +++++++++++++++++++++++++++---------- mysql-test/r/myisam.result | 25 +++++ mysql-test/t/myisam.test | 26 +++++ 3 files changed, 218 insertions(+), 57 deletions(-) diff --git a/myisam/mi_check.c b/myisam/mi_check.c index ed0a84e737d..ba308f75d24 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -1375,6 +1375,139 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) } /* chk_data_link */ +/** + @brief Drop all indexes + + @param[in] param check parameters + @param[in] info MI_INFO handle + @param[in] force if to force drop all indexes + + @return status + @retval 0 OK + @retval != 0 Error + + @note + Once allocated, index blocks remain part of the key file forever. + When indexes are disabled, no block is freed. When enabling indexes, + no block is freed either. The new indexes are create from new + blocks. (Bug #4692) + + Before recreating formerly disabled indexes, the unused blocks + must be freed. There are two options to do this: + - Follow the tree of disabled indexes, add all blocks to the + deleted blocks chain. Would require a lot of random I/O. + - Drop all blocks by clearing all index root pointers and all + delete chain pointers and resetting key_file_length to the end + of the index file header. This requires to recreate all indexes, + even those that may still be intact. + The second method is probably faster in most cases. + + When disabling indexes, MySQL disables either all indexes or all + non-unique indexes. When MySQL [re-]enables disabled indexes + (T_CREATE_MISSING_KEYS), then we either have "lost" blocks in the + index file, or there are no non-unique indexes. In the latter case, + mi_repair*() would not be called as there would be no disabled + indexes. + + If there would be more unique indexes than disabled (non-unique) + indexes, we could do the first method. But this is not implemented + yet. By now we drop and recreate all indexes when repair is called. + + However, there is an exception. Sometimes MySQL disables non-unique + indexes when the table is empty (e.g. when copying a table in + mysql_alter_table()). When enabling the non-unique indexes, they + are still empty. So there is no index block that can be lost. This + optimization is implemented in this function. + + Note that in normal repair (T_CREATE_MISSING_KEYS not set) we + recreate all enabled indexes unconditonally. We do not change the + key_map. Otherwise we invert the key map temporarily (outside of + this function) and recreate the then "seemingly" enabled indexes. + When we cannot use the optimization, and drop all indexes, we + pretend that all indexes were disabled. By the inversion, we will + then recrate all indexes. +*/ + +static int mi_drop_all_indexes(MI_CHECK *param, MI_INFO *info, my_bool force) +{ + MYISAM_SHARE *share= info->s; + MI_STATE_INFO *state= &share->state; + uint i; + int error; + DBUG_ENTER("mi_drop_all_indexes"); + + /* + If any of the disabled indexes has a key block assigned, we must + drop and recreate all indexes to avoid losing index blocks. + + If we want to recreate disabled indexes only _and_ all of these + indexes are empty, we don't need to recreate the existing indexes. + */ + if (!force && (param->testflag & T_CREATE_MISSING_KEYS)) + { + DBUG_PRINT("repair", ("creating missing indexes")); + for (i= 0; i < share->base.keys; i++) + { + DBUG_PRINT("repair", ("index #: %u key_root: 0x%lx active: %d", + i, (long) state->key_root[i], + mi_is_key_active(state->key_map, i))); + if ((state->key_root[i] != HA_OFFSET_ERROR) && + !mi_is_key_active(state->key_map, i)) + { + /* + This index has at least one key block and it is disabled. + We would lose its block(s) if would just recreate it. + So we need to drop and recreate all indexes. + */ + DBUG_PRINT("repair", ("nonempty and disabled: recreate all")); + break; + } + } + if (i >= share->base.keys) + { + /* + All of the disabled indexes are empty. We can just recreate them. + Flush dirty blocks of this index file from key cache and remove + all blocks of this index file from key cache. + */ + DBUG_PRINT("repair", ("all disabled are empty: create missing")); + error= flush_key_blocks(share->key_cache, share->kfile, + FLUSH_FORCE_WRITE); + goto end; + } + /* + We do now drop all indexes and declare them disabled. With the + T_CREATE_MISSING_KEYS flag, mi_repair*() will recreate all + disabled indexes and enable them. + */ + mi_clear_all_keys_active(state->key_map); + DBUG_PRINT("repair", ("declared all indexes disabled")); + } + + /* Remove all key blocks of this index file from key cache. */ + if ((error= flush_key_blocks(share->key_cache, share->kfile, + FLUSH_IGNORE_CHANGED))) + goto end; + + /* Clear index root block pointers. */ + for (i= 0; i < share->base.keys; i++) + state->key_root[i]= HA_OFFSET_ERROR; + + /* Clear the delete chains. */ + for (i= 0; i < state->header.max_block_size; i++) + state->key_del[i]= HA_OFFSET_ERROR; + + /* Reset index file length to end of index file header. */ + info->state->key_file_length= share->base.keystart; + + DBUG_PRINT("repair", ("dropped all indexes")); + /* error= 0; set by last (error= flush_key_bocks()). */ + + end: + DBUG_RETURN(error); +} + + /* Recover old table by reading each record and writing all keys */ /* Save new datafile-name in temp_filename */ @@ -1382,7 +1515,6 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, my_string name, int rep_quick) { int error,got_error; - uint i; ha_rows start_records,new_header_length; my_off_t del; File new_file; @@ -1486,25 +1618,10 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, info->update= (short) (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); - /* - Clear all keys. Note that all key blocks allocated until now remain - "dead" parts of the key file. (Bug #4692) - */ - for (i=0 ; i < info->s->base.keys ; i++) - share->state.key_root[i]= HA_OFFSET_ERROR; - - /* Drop the delete chain. */ - for (i=0 ; i < share->state.header.max_block_size ; i++) - share->state.key_del[i]= HA_OFFSET_ERROR; - - /* - If requested, activate (enable) all keys in key_map. In this case, - all indexes will be (re-)built. - */ + /* This function always recreates all enabled indexes. */ if (param->testflag & T_CREATE_MISSING_KEYS) mi_set_all_keys_active(share->state.key_map, share->base.keys); - - info->state->key_file_length=share->base.keystart; + mi_drop_all_indexes(param, info, TRUE); lock_memory(param); /* Everything is alloced */ @@ -2105,8 +2222,9 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, ulong *rec_per_key_part; char llbuff[22]; SORT_INFO sort_info; - ulonglong key_map=share->state.key_map; + ulonglong key_map; DBUG_ENTER("mi_repair_by_sort"); + LINT_INIT(key_map); start_records=info->state->records; got_error=1; @@ -2179,25 +2297,14 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, } info->update= (short) (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); - if (!(param->testflag & T_CREATE_MISSING_KEYS)) + + /* Optionally drop indexes and optionally modify the key_map. */ + mi_drop_all_indexes(param, info, FALSE); + key_map= share->state.key_map; + if (param->testflag & T_CREATE_MISSING_KEYS) { - /* - Flush key cache for this file if we are calling this outside - myisamchk - */ - flush_key_blocks(share->key_cache,share->kfile, FLUSH_IGNORE_CHANGED); - /* Clear the pointers to the given rows */ - for (i=0 ; i < share->base.keys ; i++) - share->state.key_root[i]= HA_OFFSET_ERROR; - for (i=0 ; i < share->state.header.max_block_size ; i++) - share->state.key_del[i]= HA_OFFSET_ERROR; - info->state->key_file_length=share->base.keystart; - } - else - { - if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_FORCE_WRITE)) - goto err; - key_map= ~key_map; /* Create the missing keys */ + /* Invert the copied key_map to recreate all disabled indexes. */ + key_map= ~key_map; } sort_info.info=info; @@ -2240,6 +2347,10 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, sort_param.read_cache=param->read_cache; sort_param.keyinfo=share->keyinfo+sort_param.key; sort_param.seg=sort_param.keyinfo->seg; + /* + Skip this index if it is marked disabled in the copied + (and possibly inverted) key_map. + */ if (! mi_is_key_active(key_map, sort_param.key)) { /* Remember old statistics for key */ @@ -2247,6 +2358,8 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, (char*) (share->state.rec_per_key_part + (uint) (rec_per_key_part - param->rec_per_key_part)), sort_param.keyinfo->keysegs*sizeof(*rec_per_key_part)); + DBUG_PRINT("repair", ("skipping seemingly disabled index #: %u", + sort_param.key)); continue; } @@ -2302,8 +2415,11 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_STATISTICS) update_key_parts(sort_param.keyinfo, rec_per_key_part, sort_param.unique, param->stats_method == MI_STATS_METHOD_IGNORE_NULLS? - sort_param.notnull: NULL,(ulonglong) info->state->records); + sort_param.notnull: NULL, + (ulonglong) info->state->records); + /* Enable this index in the permanent (not the copied) key_map. */ mi_set_key_active(share->state.key_map, sort_param.key); + DBUG_PRINT("repair", ("set enabled index #: %u", sort_param.key)); if (sort_param.fix_datafile) { @@ -2504,9 +2620,10 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, IO_CACHE new_data_cache; /* For non-quick repair. */ IO_CACHE_SHARE io_share; SORT_INFO sort_info; - ulonglong key_map=share->state.key_map; + ulonglong key_map; pthread_attr_t thr_attr; DBUG_ENTER("mi_repair_parallel"); + LINT_INIT(key_map); start_records=info->state->records; got_error=1; @@ -2608,25 +2725,14 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, } info->update= (short) (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); - if (!(param->testflag & T_CREATE_MISSING_KEYS)) + + /* Optionally drop indexes and optionally modify the key_map. */ + mi_drop_all_indexes(param, info, FALSE); + key_map= share->state.key_map; + if (param->testflag & T_CREATE_MISSING_KEYS) { - /* - Flush key cache for this file if we are calling this outside - myisamchk - */ - flush_key_blocks(share->key_cache,share->kfile, FLUSH_IGNORE_CHANGED); - /* Clear the pointers to the given rows */ - for (i=0 ; i < share->base.keys ; i++) - share->state.key_root[i]= HA_OFFSET_ERROR; - for (i=0 ; i < share->state.header.max_block_size ; i++) - share->state.key_del[i]= HA_OFFSET_ERROR; - info->state->key_file_length=share->base.keystart; - } - else - { - if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_FORCE_WRITE)) - goto err; - key_map= ~key_map; /* Create the missing keys */ + /* Invert the copied key_map to recreate all disabled indexes. */ + key_map= ~key_map; } sort_info.info=info; @@ -2682,6 +2788,10 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, sort_param[i].key=key; sort_param[i].keyinfo=share->keyinfo+key; sort_param[i].seg=sort_param[i].keyinfo->seg; + /* + Skip this index if it is marked disabled in the copied + (and possibly inverted) key_map. + */ if (! mi_is_key_active(key_map, key)) { /* Remember old statistics for key */ diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 7fc29cd13ca..176d0e97012 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -1806,4 +1806,29 @@ SELECT a FROM t1 FORCE INDEX (inx) WHERE a=1; a 1 DROP TABLE t1; +CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE INDEX (c1), INDEX (c2)) ENGINE=MYISAM; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 0 # # # 1024 # # # # # # # +INSERT INTO t1 VALUES (1,1); +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 DISABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 ENABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 DISABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 ENABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index d5f403616c8..ad223dc2664 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -1161,4 +1161,30 @@ ALTER TABLE t1 ENABLE KEYS; SELECT a FROM t1 FORCE INDEX (inx) WHERE a=1; DROP TABLE t1; +# +# Bug#4692 - DISABLE/ENABLE KEYS waste a space +# +CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE INDEX (c1), INDEX (c2)) ENGINE=MYISAM; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +INSERT INTO t1 VALUES (1,1); +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 DISABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 ENABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 DISABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 ENABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +#--exec ls -log var/master-data/test/t1.MYI +#--exec myisamchk -dvv var/master-data/test/t1.MYI +#--exec myisamchk -iev var/master-data/test/t1.MYI +DROP TABLE t1; + --echo End of 5.0 tests From e85cc0000aa47896780854a584f979f4bc2389df Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Tue, 6 Nov 2007 14:47:15 +0100 Subject: [PATCH 21/33] Bug#4692 - DISABLE/ENABLE KEYS waste a space Post-merge fix. Moved test into 5.0 section. --- mysql-test/r/myisam.result | 50 ++++++++++++++++++------------------- mysql-test/t/myisam.test | 51 +++++++++++++++++++------------------- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index e3ff66afeab..3125660643c 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -1794,6 +1794,31 @@ SELECT a FROM t1 FORCE INDEX (inx) WHERE a=1; a 1 DROP TABLE t1; +CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE INDEX (c1), INDEX (c2)) ENGINE=MYISAM; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 0 # # # 1024 # # # # # # # +INSERT INTO t1 VALUES (1,1); +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 DISABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 ENABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 DISABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +ALTER TABLE t1 ENABLE KEYS; +SHOW TABLE STATUS LIKE 't1'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # +DROP TABLE t1; End of 5.0 tests create table t1 (a int not null, key `a` (a) key_block_size=1024); show create table t1; @@ -1987,28 +2012,3 @@ Table Op Msg_type Msg_text test.t1 check status OK DROP TABLE t1; End of 5.1 tests -CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE INDEX (c1), INDEX (c2)) ENGINE=MYISAM; -SHOW TABLE STATUS LIKE 't1'; -Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MyISAM 10 Fixed 0 # # # 1024 # # # # # # # -INSERT INTO t1 VALUES (1,1); -SHOW TABLE STATUS LIKE 't1'; -Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # -ALTER TABLE t1 DISABLE KEYS; -SHOW TABLE STATUS LIKE 't1'; -Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # -ALTER TABLE t1 ENABLE KEYS; -SHOW TABLE STATUS LIKE 't1'; -Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # -ALTER TABLE t1 DISABLE KEYS; -SHOW TABLE STATUS LIKE 't1'; -Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # -ALTER TABLE t1 ENABLE KEYS; -SHOW TABLE STATUS LIKE 't1'; -Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MyISAM 10 Fixed 1 # # # 3072 # # # # # # # -DROP TABLE t1; diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index 0c5a2e621d1..6f24d84f4c0 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -1146,6 +1146,32 @@ ALTER TABLE t1 ENABLE KEYS; SELECT a FROM t1 FORCE INDEX (inx) WHERE a=1; DROP TABLE t1; +# +# Bug#4692 - DISABLE/ENABLE KEYS waste a space +# +CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE INDEX (c1), INDEX (c2)) ENGINE=MYISAM; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +INSERT INTO t1 VALUES (1,1); +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 DISABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 ENABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 DISABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +ALTER TABLE t1 ENABLE KEYS; +--replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # +SHOW TABLE STATUS LIKE 't1'; +#--exec ls -log var/master-data/test/t1.MYI +#--exec myisamchk -dvv var/master-data/test/t1.MYI +#--exec myisamchk -iev var/master-data/test/t1.MYI +DROP TABLE t1; + --echo End of 5.0 tests @@ -1256,29 +1282,4 @@ CHECK TABLE t1; DROP TABLE t1; --echo End of 5.1 tests -# -# Bug#4692 - DISABLE/ENABLE KEYS waste a space -# -CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE INDEX (c1), INDEX (c2)) ENGINE=MYISAM; ---replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # -SHOW TABLE STATUS LIKE 't1'; -INSERT INTO t1 VALUES (1,1); ---replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # -SHOW TABLE STATUS LIKE 't1'; -ALTER TABLE t1 DISABLE KEYS; ---replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # -SHOW TABLE STATUS LIKE 't1'; -ALTER TABLE t1 ENABLE KEYS; ---replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # -SHOW TABLE STATUS LIKE 't1'; -ALTER TABLE t1 DISABLE KEYS; ---replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # -SHOW TABLE STATUS LIKE 't1'; -ALTER TABLE t1 ENABLE KEYS; ---replace_column 6 # 7 # 8 # 10 # 11 # 12 # 13 # 14 # 15 # 16 # -SHOW TABLE STATUS LIKE 't1'; -#--exec ls -log var/master-data/test/t1.MYI -#--exec myisamchk -dvv var/master-data/test/t1.MYI -#--exec myisamchk -iev var/master-data/test/t1.MYI -DROP TABLE t1; From d06e2f922354bb1f98f5fe434ea5445c99af215d Mon Sep 17 00:00:00 2001 From: "svoj@mysql.com/june.mysql.com" <> Date: Tue, 6 Nov 2007 18:09:33 +0400 Subject: [PATCH 22/33] BUG#32111 - Security Breach via DATA/INDEX DIRECORY and RENAME TABLE RENAME TABLE against a table with DATA/INDEX DIRECTORY overwrites the file to which the symlink points. This is security issue, because it is possible to create a table with some name in some non-system database and set DATA/INDEX DIRECTORY to mysql system database. Renaming this table to one of mysql system tables (e.g. user, host) would overwrite the system table. Return an error when the file to which the symlink points exist. --- mysql-test/r/symlink.result | 6 ++++++ mysql-test/t/symlink.test | 12 ++++++++++++ mysys/my_symlink2.c | 11 ++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/symlink.result b/mysql-test/r/symlink.result index d07a8613883..e2b26cb508c 100644 --- a/mysql-test/r/symlink.result +++ b/mysql-test/r/symlink.result @@ -84,3 +84,9 @@ t1 CREATE TABLE `t1` ( `b` int(11) default NULL ) TYPE=MyISAM drop table t1; +CREATE TABLE t1(a INT) +DATA DIRECTORY='TEST_DIR/var/master-data/mysql' +INDEX DIRECTORY='TEST_DIR/var/master-data/mysql'; +RENAME TABLE t1 TO user; +Can't create/write to file 'TEST_DIR/var/master-data/mysql/user.MYI' (Errcode: 17) +DROP TABLE t1; diff --git a/mysql-test/t/symlink.test b/mysql-test/t/symlink.test index 7a42a60054e..9750e6fdfdd 100644 --- a/mysql-test/t/symlink.test +++ b/mysql-test/t/symlink.test @@ -112,3 +112,15 @@ eval alter table t1 index directory="$MYSQL_TEST_DIR/var/log"; enable_query_log; show create table t1; drop table t1; + +# +# BUG#32111 - Security Breach via DATA/INDEX DIRECORY and RENAME TABLE +# +--replace_result $MYSQL_TEST_DIR TEST_DIR +eval CREATE TABLE t1(a INT) +DATA DIRECTORY='$MYSQL_TEST_DIR/var/master-data/mysql' +INDEX DIRECTORY='$MYSQL_TEST_DIR/var/master-data/mysql'; +--replace_result $MYSQL_TEST_DIR TEST_DIR +--error 1 +RENAME TABLE t1 TO user; +DROP TABLE t1; diff --git a/mysys/my_symlink2.c b/mysys/my_symlink2.c index 913f632fbb4..4d58699412a 100644 --- a/mysys/my_symlink2.c +++ b/mysys/my_symlink2.c @@ -120,6 +120,7 @@ int my_rename_with_symlink(const char *from, const char *to, myf MyFlags) int was_symlink= (!my_disable_symlinks && !my_readlink(link_name, from, MYF(0))); int result=0; + int name_is_different; DBUG_ENTER("my_rename_with_symlink"); if (!was_symlink) @@ -128,6 +129,14 @@ int my_rename_with_symlink(const char *from, const char *to, myf MyFlags) /* Change filename that symlink pointed to */ strmov(tmp_name, to); fn_same(tmp_name,link_name,1); /* Copy dir */ + name_is_different= strcmp(link_name, tmp_name); + if (name_is_different && !access(tmp_name, F_OK)) + { + my_errno= EEXIST; + if (MyFlags & MY_WME) + my_error(EE_CANTCREATEFILE, MYF(0), tmp_name, EEXIST); + DBUG_RETURN(1); + } /* Create new symlink */ if (my_symlink(tmp_name, to, MyFlags)) @@ -139,7 +148,7 @@ int my_rename_with_symlink(const char *from, const char *to, myf MyFlags) the same basename and different directories. */ - if (strcmp(link_name, tmp_name) && my_rename(link_name, tmp_name, MyFlags)) + if (name_is_different && my_rename(link_name, tmp_name, MyFlags)) { int save_errno=my_errno; my_delete(to, MyFlags); /* Remove created symlink */ From 9de5a2424fff878e6f0074bc6b214f065b4c494e Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Wed, 7 Nov 2007 09:30:41 +0100 Subject: [PATCH 23/33] Bug#22351 - handler::index_next_same() call to key_cmp_if_same() uses the wrong buffer handler::index_next_same() did not take into account that the internally called function key_cmp_if_same() uses the fixed buffer table->record[0] for key comparison instead of the buffer provided by the caller of handler::index_next_same(). Added code to temporarily redirect table->record[0] and the fields used for the key to the record buffer provided by the caller of handler::index_next_same(). The test case is in partition.test already. --- sql/handler.cc | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/sql/handler.cc b/sql/handler.cc index 75c3a64bc27..7891661cefc 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2522,15 +2522,56 @@ int ha_enable_transaction(THD *thd, bool on) int handler::index_next_same(uchar *buf, const uchar *key, uint keylen) { int error; + DBUG_ENTER("index_next_same"); if (!(error=index_next(buf))) { + my_ptrdiff_t ptrdiff= buf - table->record[0]; + uchar *save_record_0; + KEY *key_info; + KEY_PART_INFO *key_part; + KEY_PART_INFO *key_part_end; + LINT_INIT(save_record_0); + LINT_INIT(key_info); + LINT_INIT(key_part); + LINT_INIT(key_part_end); + + /* + key_cmp_if_same() compares table->record[0] against 'key'. + In parts it uses table->record[0] directly, in parts it uses + field objects with their local pointers into table->record[0]. + If 'buf' is distinct from table->record[0], we need to move + all record references. This is table->record[0] itself and + the field pointers of the fields used in this key. + */ + if (ptrdiff) + { + save_record_0= table->record[0]; + table->record[0]= buf; + key_info= table->key_info + active_index; + key_part= key_info->key_part; + key_part_end= key_part + key_info->key_parts; + for (; key_part < key_part_end; key_part++) + { + DBUG_ASSERT(key_part->field); + key_part->field->move_field_offset(ptrdiff); + } + } + if (key_cmp_if_same(table, key, active_index, keylen)) { table->status=STATUS_NOT_FOUND; error=HA_ERR_END_OF_FILE; } + + /* Move back if necessary. */ + if (ptrdiff) + { + table->record[0]= save_record_0; + for (key_part= key_info->key_part; key_part < key_part_end; key_part++) + key_part->field->move_field_offset(-ptrdiff); + } } - return error; + DBUG_RETURN(error); } From 6776cc19a0271b3d63d0069aec2ae4155488b426 Mon Sep 17 00:00:00 2001 From: "mattiasj@mattiasj-laptop.(none)" <> Date: Fri, 9 Nov 2007 23:22:00 +0100 Subject: [PATCH 24/33] Bug#32091: Security breach via directory changes Problem: the table's INDEX and DATA DIR was taken directly from the table's first partition. This allowed rename attack similar to bug#32111 when ALTER TABLE REMOVE PARTITIONING Solution: Silently ignore the INDEX/DATA DIR for the table. (Like some other storage engines do). Partitioned tables do not support DATA/INDEX DIR on the table level, only on its partitions. --- mysql-test/r/partition_mgm.result | 81 +++++++++++++++++++++ mysql-test/t/partition_mgm.test | 113 +++++++++++++++++++++++++++++- sql/ha_partition.cc | 1 + 3 files changed, 193 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/partition_mgm.result b/mysql-test/r/partition_mgm.result index 04ac603fea7..7d2c159bb15 100644 --- a/mysql-test/r/partition_mgm.result +++ b/mysql-test/r/partition_mgm.result @@ -1,4 +1,85 @@ DROP TABLE IF EXISTS t1; +# Creating two non colliding tables mysqltest2.t1 and test.t1 +# test.t1 have partitions in mysqltest2-directory! +# user root: +GRANT USAGE ON test.* TO mysqltest_1@localhost; +CREATE DATABASE mysqltest2; +USE mysqltest2; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0); +# user mysqltest_1: +USE test; +CREATE TABLE t1 (a INT) +PARTITION BY LIST (a) ( +PARTITION p0 VALUES IN (0) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2', +PARTITION p1 VALUES IN (1) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test', +PARTITION p2 VALUES IN (2) +); +# without the patch for bug#32091 this would create +# files mysqltest2/t1.MYD + .MYI and possible overwrite +# the mysqltest2.t1 table (depending on bug#32111) +ALTER TABLE t1 REMOVE PARTITIONING; +INSERT INTO t1 VALUES (1); +SELECT * FROM t1; +a +1 +# user root: +USE mysqltest2; +FLUSH TABLES; +# if the patch works, this should be different +# and before the patch they were the same! +SELECT * FROM t1; +a +0 +USE test; +SELECT * FROM t1; +a +1 +DROP TABLE t1; +DROP DATABASE mysqltest2; +# test that symlinks can not overwrite files when CREATE TABLE +# user root: +CREATE DATABASE mysqltest2; +USE mysqltest2; +CREATE TABLE t1 (a INT) +PARTITION BY LIST (a) ( +PARTITION p0 VALUES IN (0) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2', +PARTITION p1 VALUES IN (1) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + ); +# user mysqltest_1: +USE test; +CREATE TABLE t1 (a INT) +PARTITION BY LIST (a) ( +PARTITION p0 VALUES IN (0) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2', +PARTITION p1 VALUES IN (1) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + ); +ERROR HY000: Can't create/write to file 'MYSQLTEST_VARDIR/master-data/mysqltest2/t1#P#p0.MYI' (Errcode: 17) +CREATE TABLE t1 (a INT) +PARTITION BY LIST (a) ( +PARTITION p0 VALUES IN (0) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test', +PARTITION p1 VALUES IN (1) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + ); +ERROR HY000: Can't create/write to file 'MYSQLTEST_VARDIR/master-data/test/t1#P#p1.MYI' (Errcode: 17) +# user root (cleanup): +DROP DATABASE mysqltest2; +USE test; +REVOKE USAGE ON *.* FROM mysqltest_1@localhost; create table t1 (a int) partition by range (a) subpartition by key (a) diff --git a/mysql-test/t/partition_mgm.test b/mysql-test/t/partition_mgm.test index a06f8d1aee5..a405e15ec16 100644 --- a/mysql-test/t/partition_mgm.test +++ b/mysql-test/t/partition_mgm.test @@ -1,7 +1,116 @@ -- source include/have_partition.inc ---disable_warnings +-- disable_warnings DROP TABLE IF EXISTS t1; ---enable_warnings +-- enable_warnings + +# +# Bug 32091: Security breach via directory changes +# +# The below test shows that a pre-existing table mysqltest2.t1 cannot be +# replaced by a user with no rights in 'mysqltest2'. The altered table +# test.t1 will be altered (remove partitioning) into the test directory +# and having its partitions removed from the mysqltest2 directory. +# (the partitions data files are named #P#.MYD +# and will not collide with a non partitioned table's data files.) +# NOTE: the privileges on files and directories are the same for all +# database users in mysqld, though mysqld enforces privileges on +# the database and table levels which in turn maps to directories and +# files, but not the other way around (any db-user can use any +# directory or file that the mysqld-process can use, via DATA/INDEX DIR) +# this is the security flaw that was used in bug#32091 and bug#32111 +-- echo # Creating two non colliding tables mysqltest2.t1 and test.t1 +-- echo # test.t1 have partitions in mysqltest2-directory! +-- echo # user root: + GRANT USAGE ON test.* TO mysqltest_1@localhost; + CREATE DATABASE mysqltest2; + USE mysqltest2; + CREATE TABLE t1 (a INT); + INSERT INTO t1 VALUES (0); +connect(con1,localhost,mysqltest_1,,); +-- echo # user mysqltest_1: + USE test; + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + eval CREATE TABLE t1 (a INT) + PARTITION BY LIST (a) ( + PARTITION p0 VALUES IN (0) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2', + PARTITION p1 VALUES IN (1) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test', + PARTITION p2 VALUES IN (2) + ); + -- echo # without the patch for bug#32091 this would create + -- echo # files mysqltest2/t1.MYD + .MYI and possible overwrite + -- echo # the mysqltest2.t1 table (depending on bug#32111) + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + ALTER TABLE t1 REMOVE PARTITIONING; + INSERT INTO t1 VALUES (1); + SELECT * FROM t1; +connection default; +-- echo # user root: + USE mysqltest2; + FLUSH TABLES; + -- echo # if the patch works, this should be different + -- echo # and before the patch they were the same! + SELECT * FROM t1; + USE test; + SELECT * FROM t1; + DROP TABLE t1; + DROP DATABASE mysqltest2; +# The below test shows that a pre-existing partition can not be +# destroyed by a new partition from another table. +# (Remember that a table or partition that uses the DATA/INDEX DIR +# is symlinked and thus has +# 1. the real file in the DATA/INDEX DIR and +# 2. a symlink in its default database directory pointing to +# the real file. +# So it is using/blocking 2 files in (in 2 different directories +-- echo # test that symlinks can not overwrite files when CREATE TABLE +-- echo # user root: + CREATE DATABASE mysqltest2; + USE mysqltest2; + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + eval CREATE TABLE t1 (a INT) + PARTITION BY LIST (a) ( + PARTITION p0 VALUES IN (0) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2', + PARTITION p1 VALUES IN (1) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + ); +connection con1; +-- echo # user mysqltest_1: + USE test; + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + -- error 1 + eval CREATE TABLE t1 (a INT) + PARTITION BY LIST (a) ( + PARTITION p0 VALUES IN (0) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2', + PARTITION p1 VALUES IN (1) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + ); + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + -- error 1 + eval CREATE TABLE t1 (a INT) + PARTITION BY LIST (a) ( + PARTITION p0 VALUES IN (0) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test', + PARTITION p1 VALUES IN (1) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + ); +connection default; +-- echo # user root (cleanup): + DROP DATABASE mysqltest2; + USE test; + REVOKE USAGE ON *.* FROM mysqltest_1@localhost; + disconnect con1; # # Bug 21143: mysqld hang when error in number of subparts in diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 363c0a273bc..b53a5e3da97 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -1599,6 +1599,7 @@ error: void ha_partition::update_create_info(HA_CREATE_INFO *create_info) { m_file[0]->update_create_info(create_info); + create_info->data_file_name= create_info->index_file_name = NULL; return; } From 43c1daf630a28b64048fb20fae5b3052c09aa3a3 Mon Sep 17 00:00:00 2001 From: "mattiasj@mattiasj-laptop.(none)" <> Date: Sat, 10 Nov 2007 13:09:18 +0100 Subject: [PATCH 25/33] Bug#29368: Modified error messages Problem: there was no standard syntax error when creating partitions with syntax error in the partitioning clause. Solution: added "Syntax error: " to the error message --- mysql-test/r/partition.result | 4 ++-- mysql-test/r/partition_error.result | 15 ++++++++++++--- mysql-test/t/partition_error.test | 13 +++++++++++++ sql/share/errmsg.txt | 6 +++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 4e4bd0bbc0a..3c41e9a0d49 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -709,7 +709,7 @@ partition by range (a) alter table t1 add partition (partition p1 values in (2)); ERROR HY000: Only LIST PARTITIONING can use VALUES IN in partition definition alter table t1 add partition (partition p1); -ERROR HY000: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition +ERROR HY000: Syntax error: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition drop table t1; create table t1 (a int) partition by list (a) @@ -717,7 +717,7 @@ partition by list (a) alter table t1 add partition (partition p1 values less than (2)); ERROR HY000: Only RANGE PARTITIONING can use VALUES LESS THAN in partition definition alter table t1 add partition (partition p1); -ERROR HY000: LIST PARTITIONING requires definition of VALUES IN for each partition +ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition drop table t1; create table t1 (a int) partition by hash (a) diff --git a/mysql-test/r/partition_error.result b/mysql-test/r/partition_error.result index 7952c8df609..46532cb32ab 100644 --- a/mysql-test/r/partition_error.result +++ b/mysql-test/r/partition_error.result @@ -1,4 +1,13 @@ drop table if exists t1; +CREATE TABLE t1 ( +a int +) +PARTITION BY RANGE (a) +( +PARTITION p0 VALUES LESS THAN (1), +PARTITION p1 VALU ES LESS THAN (2) +); +ERROR HY000: Syntax error: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition partition by list (a) partitions 3 (partition x1 values in (1,2,9,4) tablespace ts1, @@ -351,7 +360,7 @@ partition by range (a) partitions 2 (partition x1 values less than (4), partition x2); -ERROR HY000: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition +ERROR HY000: Syntax error: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition CREATE TABLE t1 ( a int not null, b int not null, @@ -531,7 +540,7 @@ partition by list (a) partitions 2 (partition x1 values in (4), partition x2); -ERROR HY000: LIST PARTITIONING requires definition of VALUES IN for each partition +ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition CREATE TABLE t1 ( a int not null, b int not null, @@ -551,7 +560,7 @@ partition by list (a) partitions 2 (partition x1 values in (4,6), partition x2); -ERROR HY000: LIST PARTITIONING requires definition of VALUES IN for each partition +ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition CREATE TABLE t1 ( a int not null, b int not null, diff --git a/mysql-test/t/partition_error.test b/mysql-test/t/partition_error.test index 5fc2097cc52..c9b95fc1664 100644 --- a/mysql-test/t/partition_error.test +++ b/mysql-test/t/partition_error.test @@ -8,6 +8,19 @@ drop table if exists t1; --enable_warnings +# +# Bug 29368: +# Incorrect error, 1467, for syntax error when creating partition +--error ER_PARTITION_REQUIRES_VALUES_ERROR +CREATE TABLE t1 ( + a int +) +PARTITION BY RANGE (a) +( + PARTITION p0 VALUES LESS THAN (1), + PARTITION p1 VALU ES LESS THAN (2) +); + # # Partition by key stand-alone error # diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 8fad09eb221..257cea7c27b 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5667,9 +5667,9 @@ ER_ILLEGAL_HA_CREATE_OPTION eng "Table storage engine '%-.64s' does not support the create option '%.64s'" ger "Speicher-Engine '%-.64s' der Tabelle unterstützt die Option '%.64s' nicht" ER_PARTITION_REQUIRES_VALUES_ERROR - eng "%-.64s PARTITIONING requires definition of VALUES %-.64s for each partition" - ger "%-.64s-PARTITIONierung erfordert Definition von VALUES %-.64s für jede Partition" - swe "%-.64s PARTITIONering kräver definition av VALUES %-.64s för varje partition" + eng "Syntax error: %-.64s PARTITIONING requires definition of VALUES %-.64s for each partition" + ger "Fehler in der SQL-Syntax: %-.64s-PARTITIONierung erfordert Definition von VALUES %-.64s für jede Partition" + swe "Syntaxfel: %-.64s PARTITIONering kräver definition av VALUES %-.64s för varje partition" ER_PARTITION_WRONG_VALUES_ERROR eng "Only %-.64s PARTITIONING can use VALUES %-.64s in partition definition" ger "Nur %-.64s-PARTITIONierung kann VALUES %-.64s in der Partitionsdefinition verwenden" From 10df30f091931ae83abf936905807d604d08dcc4 Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Sat, 10 Nov 2007 14:36:25 +0100 Subject: [PATCH 26/33] Bug#31210 - INSERT DELAYED crashes server when used on partitioned table Post-merge fix A new need for lex initialization arose. --- sql/ha_ndbcluster.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 436710e3dee..bf2b19bfc9c 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -9073,6 +9073,7 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) thd->thread_stack= (char*)&thd; /* remember where our stack is */ if (thd->store_globals()) goto ndb_util_thread_fail; + lex_start(thd); thd->init_for_queries(); thd->version=refresh_version; thd->main_security_ctx.host_or_ip= ""; From 47a03ea32169e56526b31423334a56c8b6095621 Mon Sep 17 00:00:00 2001 From: "mattiasj@mattiasj-laptop.(none)" <> Date: Sat, 10 Nov 2007 14:56:21 +0100 Subject: [PATCH 27/33] Bug#32091: Security breach via directory changes small fix of test case (when running make test after merge, it did not substitute MYSQLTEST_VARDIR in the error) --- mysql-test/r/partition_mgm.result | 4 ++-- mysql-test/t/partition_mgm.test | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/partition_mgm.result b/mysql-test/r/partition_mgm.result index 7d2c159bb15..e59a2e881dd 100644 --- a/mysql-test/r/partition_mgm.result +++ b/mysql-test/r/partition_mgm.result @@ -65,7 +65,7 @@ PARTITION p1 VALUES IN (1) DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' ); -ERROR HY000: Can't create/write to file 'MYSQLTEST_VARDIR/master-data/mysqltest2/t1#P#p0.MYI' (Errcode: 17) +Got one of the listed errors CREATE TABLE t1 (a INT) PARTITION BY LIST (a) ( PARTITION p0 VALUES IN (0) @@ -75,7 +75,7 @@ PARTITION p1 VALUES IN (1) DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' ); -ERROR HY000: Can't create/write to file 'MYSQLTEST_VARDIR/master-data/test/t1#P#p1.MYI' (Errcode: 17) +Got one of the listed errors # user root (cleanup): DROP DATABASE mysqltest2; USE test; diff --git a/mysql-test/t/partition_mgm.test b/mysql-test/t/partition_mgm.test index a405e15ec16..0127f61eb4b 100644 --- a/mysql-test/t/partition_mgm.test +++ b/mysql-test/t/partition_mgm.test @@ -84,7 +84,7 @@ connection con1; -- echo # user mysqltest_1: USE test; -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR - -- error 1 + -- error 1,1 eval CREATE TABLE t1 (a INT) PARTITION BY LIST (a) ( PARTITION p0 VALUES IN (0) @@ -95,7 +95,7 @@ connection con1; INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' ); -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR - -- error 1 + -- error 1,1 eval CREATE TABLE t1 (a INT) PARTITION BY LIST (a) ( PARTITION p0 VALUES IN (0) From f9c771b037cf10fec7e29121f9363e8469772719 Mon Sep 17 00:00:00 2001 From: "mattiasj@mattiasj-laptop.(none)" <> Date: Sat, 10 Nov 2007 21:29:39 +0100 Subject: [PATCH 28/33] Bug#32091: Security breach via directory changes Changed test case from GRANT to CREATE USER --- mysql-test/r/partition_mgm.result | 5 +++-- mysql-test/t/partition_mgm.test | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/partition_mgm.result b/mysql-test/r/partition_mgm.result index e59a2e881dd..04358fa0f9f 100644 --- a/mysql-test/r/partition_mgm.result +++ b/mysql-test/r/partition_mgm.result @@ -1,8 +1,9 @@ DROP TABLE IF EXISTS t1; +DROP DATABASE IF EXISTS mysqltest2; # Creating two non colliding tables mysqltest2.t1 and test.t1 # test.t1 have partitions in mysqltest2-directory! # user root: -GRANT USAGE ON test.* TO mysqltest_1@localhost; +CREATE USER mysqltest_1@localhost; CREATE DATABASE mysqltest2; USE mysqltest2; CREATE TABLE t1 (a INT); @@ -79,7 +80,7 @@ Got one of the listed errors # user root (cleanup): DROP DATABASE mysqltest2; USE test; -REVOKE USAGE ON *.* FROM mysqltest_1@localhost; +DROP USER mysqltest_1@localhost; create table t1 (a int) partition by range (a) subpartition by key (a) diff --git a/mysql-test/t/partition_mgm.test b/mysql-test/t/partition_mgm.test index 0127f61eb4b..1532ea64ab2 100644 --- a/mysql-test/t/partition_mgm.test +++ b/mysql-test/t/partition_mgm.test @@ -1,6 +1,7 @@ -- source include/have_partition.inc -- disable_warnings DROP TABLE IF EXISTS t1; +DROP DATABASE IF EXISTS mysqltest2; -- enable_warnings # @@ -21,7 +22,7 @@ DROP TABLE IF EXISTS t1; -- echo # Creating two non colliding tables mysqltest2.t1 and test.t1 -- echo # test.t1 have partitions in mysqltest2-directory! -- echo # user root: - GRANT USAGE ON test.* TO mysqltest_1@localhost; + CREATE USER mysqltest_1@localhost; CREATE DATABASE mysqltest2; USE mysqltest2; CREATE TABLE t1 (a INT); @@ -109,7 +110,7 @@ connection default; -- echo # user root (cleanup): DROP DATABASE mysqltest2; USE test; - REVOKE USAGE ON *.* FROM mysqltest_1@localhost; + DROP USER mysqltest_1@localhost; disconnect con1; # From e2cc172d35253e6ea4d7773bccddd5cca88e9c17 Mon Sep 17 00:00:00 2001 From: "istruewing@stella.local" <> Date: Sun, 11 Nov 2007 20:38:28 +0100 Subject: [PATCH 29/33] Bug#31210 - INSERT DELAYED crashes server when used on partitioned table Post-pushbuild fix Pushbuild detected a new need for lex initialization in embedded server. Fixed test for INSERT DELAYED in partitions_hash.test so that it works with embedded server. --- libmysqld/lib_sql.cc | 1 + mysql-test/r/partition_hash.result | 1 - mysql-test/t/partition_hash.test | 4 +++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 4e525f8447f..d929024483c 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -94,6 +94,7 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, thd->current_stmt= stmt; thd->store_globals(); // Fix if more than one connect + lex_start(thd); /* We have to call free_old_query before we start to fill mysql->fields for new query. In the case of embedded server we collect field data diff --git a/mysql-test/r/partition_hash.result b/mysql-test/r/partition_hash.result index 3ebbd020db4..72f036be099 100644 --- a/mysql-test/r/partition_hash.result +++ b/mysql-test/r/partition_hash.result @@ -185,5 +185,4 @@ c1 c2 c3 drop table t1; CREATE TABLE t1 (c1 INT) ENGINE=MyISAM PARTITION BY HASH(c1) PARTITIONS 1; INSERT DELAYED INTO t1 VALUES (1); -ERROR HY000: Table storage engine for 't1' doesn't have this option DROP TABLE t1; diff --git a/mysql-test/t/partition_hash.test b/mysql-test/t/partition_hash.test index 16c3e2b3b9b..52caaa8c8e9 100644 --- a/mysql-test/t/partition_hash.test +++ b/mysql-test/t/partition_hash.test @@ -148,7 +148,9 @@ drop table t1; # Bug#31210 - INSERT DELAYED crashes server when used on partitioned table # CREATE TABLE t1 (c1 INT) ENGINE=MyISAM PARTITION BY HASH(c1) PARTITIONS 1; ---error ER_ILLEGAL_HA +# The test succeeds in an embedded server because normal insert is done. +# The test fails in a normal server with "engine doesn't have this option". +--error 0, ER_ILLEGAL_HA INSERT DELAYED INTO t1 VALUES (1); DROP TABLE t1; From e7e18ac405a3090b4a9689e9ff48ae866526121a Mon Sep 17 00:00:00 2001 From: "mattiasj@mattiasj-laptop.(none)" <> Date: Sun, 11 Nov 2007 22:30:01 +0100 Subject: [PATCH 30/33] Bug#30695: An apostrophe ' in the comment of the ADD PARTITION causes the Server to crash. Post-pushbuild fix Pushbuild genereted valgrind warnings. Changed function to safer variant. --- sql/sql_partition.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index ac098d57c24..ad9eec1906a 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1866,7 +1866,7 @@ static int add_quoted_string(File fptr, const char *quotestr) String escapedstr; int err= add_string(fptr, "'"); err+= append_escaped(&escapedstr, &orgstr); - err+= add_string(fptr, escapedstr.c_ptr()); + err+= add_string(fptr, escapedstr.c_ptr_safe()); return err + add_string(fptr, "'"); } From 40a78cd3900d72e76edf0e7d9b83b26f1a55811c Mon Sep 17 00:00:00 2001 From: "svoj@mysql.com/june.mysql.com" <> Date: Mon, 12 Nov 2007 15:15:16 +0400 Subject: [PATCH 31/33] After merge fix. --- mysql-test/r/symlink.result | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/r/symlink.result b/mysql-test/r/symlink.result index cc54233107a..81798b2dc20 100644 --- a/mysql-test/r/symlink.result +++ b/mysql-test/r/symlink.result @@ -94,7 +94,7 @@ CREATE TABLE t1(a INT) DATA DIRECTORY='TEST_DIR/var/master-data/mysql' INDEX DIRECTORY='TEST_DIR/var/master-data/mysql'; RENAME TABLE t1 TO user; -Can't create/write to file 'TEST_DIR/var/master-data/mysql/user.MYI' (Errcode: 17) +ERROR HY000: Can't create/write to file 'TEST_DIR/var/master-data/mysql/user.MYI' (Errcode: 17) DROP TABLE t1; show create table t1; Table Create Table From 9c05d109aa5d29947315f3e465ef31f0f83c3dc0 Mon Sep 17 00:00:00 2001 From: "mattiasj@mattiasj-laptop.(none)" <> Date: Mon, 12 Nov 2007 13:23:45 +0100 Subject: [PATCH 32/33] Bug#32091: Security breach via directory changes Merge fix partition_mgm did not require have_symlink. Moved the test case to partition_symlink, which require have_symlink, and should work on both *nix and Windows --- mysql-test/r/partition_mgm.result | 82 ------------------ mysql-test/r/partition_symlink.result | 83 ++++++++++++++++++ mysql-test/t/partition_mgm.test | 114 +----------------------- mysql-test/t/partition_symlink.test | 119 ++++++++++++++++++++++++++ 4 files changed, 204 insertions(+), 194 deletions(-) create mode 100644 mysql-test/r/partition_symlink.result create mode 100644 mysql-test/t/partition_symlink.test diff --git a/mysql-test/r/partition_mgm.result b/mysql-test/r/partition_mgm.result index 04358fa0f9f..04ac603fea7 100644 --- a/mysql-test/r/partition_mgm.result +++ b/mysql-test/r/partition_mgm.result @@ -1,86 +1,4 @@ DROP TABLE IF EXISTS t1; -DROP DATABASE IF EXISTS mysqltest2; -# Creating two non colliding tables mysqltest2.t1 and test.t1 -# test.t1 have partitions in mysqltest2-directory! -# user root: -CREATE USER mysqltest_1@localhost; -CREATE DATABASE mysqltest2; -USE mysqltest2; -CREATE TABLE t1 (a INT); -INSERT INTO t1 VALUES (0); -# user mysqltest_1: -USE test; -CREATE TABLE t1 (a INT) -PARTITION BY LIST (a) ( -PARTITION p0 VALUES IN (0) -DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' - INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2', -PARTITION p1 VALUES IN (1) -DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' - INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test', -PARTITION p2 VALUES IN (2) -); -# without the patch for bug#32091 this would create -# files mysqltest2/t1.MYD + .MYI and possible overwrite -# the mysqltest2.t1 table (depending on bug#32111) -ALTER TABLE t1 REMOVE PARTITIONING; -INSERT INTO t1 VALUES (1); -SELECT * FROM t1; -a -1 -# user root: -USE mysqltest2; -FLUSH TABLES; -# if the patch works, this should be different -# and before the patch they were the same! -SELECT * FROM t1; -a -0 -USE test; -SELECT * FROM t1; -a -1 -DROP TABLE t1; -DROP DATABASE mysqltest2; -# test that symlinks can not overwrite files when CREATE TABLE -# user root: -CREATE DATABASE mysqltest2; -USE mysqltest2; -CREATE TABLE t1 (a INT) -PARTITION BY LIST (a) ( -PARTITION p0 VALUES IN (0) -DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' - INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2', -PARTITION p1 VALUES IN (1) -DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' - INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' - ); -# user mysqltest_1: -USE test; -CREATE TABLE t1 (a INT) -PARTITION BY LIST (a) ( -PARTITION p0 VALUES IN (0) -DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' - INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2', -PARTITION p1 VALUES IN (1) -DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' - INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' - ); -Got one of the listed errors -CREATE TABLE t1 (a INT) -PARTITION BY LIST (a) ( -PARTITION p0 VALUES IN (0) -DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' - INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test', -PARTITION p1 VALUES IN (1) -DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' - INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' - ); -Got one of the listed errors -# user root (cleanup): -DROP DATABASE mysqltest2; -USE test; -DROP USER mysqltest_1@localhost; create table t1 (a int) partition by range (a) subpartition by key (a) diff --git a/mysql-test/r/partition_symlink.result b/mysql-test/r/partition_symlink.result new file mode 100644 index 00000000000..20e841d2e0e --- /dev/null +++ b/mysql-test/r/partition_symlink.result @@ -0,0 +1,83 @@ +DROP TABLE IF EXISTS t1; +DROP DATABASE IF EXISTS mysqltest2; +# Creating two non colliding tables mysqltest2.t1 and test.t1 +# test.t1 have partitions in mysqltest2-directory! +# user root: +CREATE USER mysqltest_1@localhost; +CREATE DATABASE mysqltest2; +USE mysqltest2; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0); +# user mysqltest_1: +USE test; +CREATE TABLE t1 (a INT) +PARTITION BY LIST (a) ( +PARTITION p0 VALUES IN (0) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2', +PARTITION p1 VALUES IN (1) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test', +PARTITION p2 VALUES IN (2) +); +# without the patch for bug#32091 this would create +# files mysqltest2/t1.MYD + .MYI and possible overwrite +# the mysqltest2.t1 table (depending on bug#32111) +ALTER TABLE t1 REMOVE PARTITIONING; +INSERT INTO t1 VALUES (1); +SELECT * FROM t1; +a +1 +# user root: +USE mysqltest2; +FLUSH TABLES; +# if the patch works, this should be different +# and before the patch they were the same! +SELECT * FROM t1; +a +0 +USE test; +SELECT * FROM t1; +a +1 +DROP TABLE t1; +DROP DATABASE mysqltest2; +# test that symlinks can not overwrite files when CREATE TABLE +# user root: +CREATE DATABASE mysqltest2; +USE mysqltest2; +CREATE TABLE t1 (a INT) +PARTITION BY LIST (a) ( +PARTITION p0 VALUES IN (0) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2', +PARTITION p1 VALUES IN (1) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + ); +# user mysqltest_1: +USE test; +CREATE TABLE t1 (a INT) +PARTITION BY LIST (a) ( +PARTITION p0 VALUES IN (0) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2', +PARTITION p1 VALUES IN (1) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + ); +Got one of the listed errors +CREATE TABLE t1 (a INT) +PARTITION BY LIST (a) ( +PARTITION p0 VALUES IN (0) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/test', +PARTITION p1 VALUES IN (1) +DATA DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/master-data/mysqltest2' + ); +Got one of the listed errors +# user root (cleanup): +DROP DATABASE mysqltest2; +USE test; +DROP USER mysqltest_1@localhost; diff --git a/mysql-test/t/partition_mgm.test b/mysql-test/t/partition_mgm.test index 1532ea64ab2..a06f8d1aee5 100644 --- a/mysql-test/t/partition_mgm.test +++ b/mysql-test/t/partition_mgm.test @@ -1,117 +1,7 @@ -- source include/have_partition.inc --- disable_warnings +--disable_warnings DROP TABLE IF EXISTS t1; -DROP DATABASE IF EXISTS mysqltest2; --- enable_warnings - -# -# Bug 32091: Security breach via directory changes -# -# The below test shows that a pre-existing table mysqltest2.t1 cannot be -# replaced by a user with no rights in 'mysqltest2'. The altered table -# test.t1 will be altered (remove partitioning) into the test directory -# and having its partitions removed from the mysqltest2 directory. -# (the partitions data files are named #P#.MYD -# and will not collide with a non partitioned table's data files.) -# NOTE: the privileges on files and directories are the same for all -# database users in mysqld, though mysqld enforces privileges on -# the database and table levels which in turn maps to directories and -# files, but not the other way around (any db-user can use any -# directory or file that the mysqld-process can use, via DATA/INDEX DIR) -# this is the security flaw that was used in bug#32091 and bug#32111 --- echo # Creating two non colliding tables mysqltest2.t1 and test.t1 --- echo # test.t1 have partitions in mysqltest2-directory! --- echo # user root: - CREATE USER mysqltest_1@localhost; - CREATE DATABASE mysqltest2; - USE mysqltest2; - CREATE TABLE t1 (a INT); - INSERT INTO t1 VALUES (0); -connect(con1,localhost,mysqltest_1,,); --- echo # user mysqltest_1: - USE test; - -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR - eval CREATE TABLE t1 (a INT) - PARTITION BY LIST (a) ( - PARTITION p0 VALUES IN (0) - DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' - INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2', - PARTITION p1 VALUES IN (1) - DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' - INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test', - PARTITION p2 VALUES IN (2) - ); - -- echo # without the patch for bug#32091 this would create - -- echo # files mysqltest2/t1.MYD + .MYI and possible overwrite - -- echo # the mysqltest2.t1 table (depending on bug#32111) - -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR - ALTER TABLE t1 REMOVE PARTITIONING; - INSERT INTO t1 VALUES (1); - SELECT * FROM t1; -connection default; --- echo # user root: - USE mysqltest2; - FLUSH TABLES; - -- echo # if the patch works, this should be different - -- echo # and before the patch they were the same! - SELECT * FROM t1; - USE test; - SELECT * FROM t1; - DROP TABLE t1; - DROP DATABASE mysqltest2; -# The below test shows that a pre-existing partition can not be -# destroyed by a new partition from another table. -# (Remember that a table or partition that uses the DATA/INDEX DIR -# is symlinked and thus has -# 1. the real file in the DATA/INDEX DIR and -# 2. a symlink in its default database directory pointing to -# the real file. -# So it is using/blocking 2 files in (in 2 different directories --- echo # test that symlinks can not overwrite files when CREATE TABLE --- echo # user root: - CREATE DATABASE mysqltest2; - USE mysqltest2; - -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR - eval CREATE TABLE t1 (a INT) - PARTITION BY LIST (a) ( - PARTITION p0 VALUES IN (0) - DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' - INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2', - PARTITION p1 VALUES IN (1) - DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' - INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' - ); -connection con1; --- echo # user mysqltest_1: - USE test; - -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR - -- error 1,1 - eval CREATE TABLE t1 (a INT) - PARTITION BY LIST (a) ( - PARTITION p0 VALUES IN (0) - DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' - INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2', - PARTITION p1 VALUES IN (1) - DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' - INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' - ); - -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR - -- error 1,1 - eval CREATE TABLE t1 (a INT) - PARTITION BY LIST (a) ( - PARTITION p0 VALUES IN (0) - DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' - INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test', - PARTITION p1 VALUES IN (1) - DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' - INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' - ); -connection default; --- echo # user root (cleanup): - DROP DATABASE mysqltest2; - USE test; - DROP USER mysqltest_1@localhost; - disconnect con1; +--enable_warnings # # Bug 21143: mysqld hang when error in number of subparts in diff --git a/mysql-test/t/partition_symlink.test b/mysql-test/t/partition_symlink.test new file mode 100644 index 00000000000..6f823c4a30a --- /dev/null +++ b/mysql-test/t/partition_symlink.test @@ -0,0 +1,119 @@ +# Test that must have symlink. eg. using DATA/INDEX DIR +# (DATA/INDEX DIR requires symlinks) +-- source include/have_partition.inc +-- source include/have_symlink.inc +-- disable_warnings +DROP TABLE IF EXISTS t1; +DROP DATABASE IF EXISTS mysqltest2; +-- enable_warnings + +# +# Bug 32091: Security breach via directory changes +# +# The below test shows that a pre-existing table mysqltest2.t1 cannot be +# replaced by a user with no rights in 'mysqltest2'. The altered table +# test.t1 will be altered (remove partitioning) into the test directory +# and having its partitions removed from the mysqltest2 directory. +# (the partitions data files are named #P#.MYD +# and will not collide with a non partitioned table's data files.) +# NOTE: the privileges on files and directories are the same for all +# database users in mysqld, though mysqld enforces privileges on +# the database and table levels which in turn maps to directories and +# files, but not the other way around (any db-user can use any +# directory or file that the mysqld-process can use, via DATA/INDEX DIR) +# this is the security flaw that was used in bug#32091 and bug#32111 +-- echo # Creating two non colliding tables mysqltest2.t1 and test.t1 +-- echo # test.t1 have partitions in mysqltest2-directory! +-- echo # user root: + CREATE USER mysqltest_1@localhost; + CREATE DATABASE mysqltest2; + USE mysqltest2; + CREATE TABLE t1 (a INT); + INSERT INTO t1 VALUES (0); +connect(con1,localhost,mysqltest_1,,); +-- echo # user mysqltest_1: + USE test; + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + eval CREATE TABLE t1 (a INT) + PARTITION BY LIST (a) ( + PARTITION p0 VALUES IN (0) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2', + PARTITION p1 VALUES IN (1) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test', + PARTITION p2 VALUES IN (2) + ); + -- echo # without the patch for bug#32091 this would create + -- echo # files mysqltest2/t1.MYD + .MYI and possible overwrite + -- echo # the mysqltest2.t1 table (depending on bug#32111) + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + ALTER TABLE t1 REMOVE PARTITIONING; + INSERT INTO t1 VALUES (1); + SELECT * FROM t1; +connection default; +-- echo # user root: + USE mysqltest2; + FLUSH TABLES; + -- echo # if the patch works, this should be different + -- echo # and before the patch they were the same! + SELECT * FROM t1; + USE test; + SELECT * FROM t1; + DROP TABLE t1; + DROP DATABASE mysqltest2; +# The below test shows that a pre-existing partition can not be +# destroyed by a new partition from another table. +# (Remember that a table or partition that uses the DATA/INDEX DIR +# is symlinked and thus has +# 1. the real file in the DATA/INDEX DIR and +# 2. a symlink in its default database directory pointing to +# the real file. +# So it is using/blocking 2 files in (in 2 different directories +-- echo # test that symlinks can not overwrite files when CREATE TABLE +-- echo # user root: + CREATE DATABASE mysqltest2; + USE mysqltest2; + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + eval CREATE TABLE t1 (a INT) + PARTITION BY LIST (a) ( + PARTITION p0 VALUES IN (0) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2', + PARTITION p1 VALUES IN (1) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + ); +connection con1; +-- echo # user mysqltest_1: + USE test; + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + -- error 1,1 + eval CREATE TABLE t1 (a INT) + PARTITION BY LIST (a) ( + PARTITION p0 VALUES IN (0) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2', + PARTITION p1 VALUES IN (1) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + ); + -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR + -- error 1,1 + eval CREATE TABLE t1 (a INT) + PARTITION BY LIST (a) ( + PARTITION p0 VALUES IN (0) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/test' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/test', + PARTITION p1 VALUES IN (1) + DATA DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/master-data/mysqltest2' + ); +connection default; +-- echo # user root (cleanup): + DROP DATABASE mysqltest2; + USE test; + DROP USER mysqltest_1@localhost; + disconnect con1; + + From 43578c9097b4bf76495c0765ab9f9a5e84a2f89e Mon Sep 17 00:00:00 2001 From: "mattiasj@mattiasj-laptop.(none)" <> Date: Mon, 12 Nov 2007 14:51:14 +0100 Subject: [PATCH 33/33] Bug#31705 Partitions: crash if varchar length > 65530 Buffer overflow due to wrong key length in partitioning Changed to the correct key_length function. --- mysql-test/r/partition_datatype.result | 282 +++++++++++++++++++++++++ mysql-test/t/partition_datatype.test | 213 +++++++++++++++++++ sql/opt_range.cc | 10 +- 3 files changed, 499 insertions(+), 6 deletions(-) create mode 100644 mysql-test/r/partition_datatype.result create mode 100644 mysql-test/t/partition_datatype.test diff --git a/mysql-test/r/partition_datatype.result b/mysql-test/r/partition_datatype.result new file mode 100644 index 00000000000..c6506178b03 --- /dev/null +++ b/mysql-test/r/partition_datatype.result @@ -0,0 +1,282 @@ +drop table if exists t1; +create table t1 (a tinyint not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a smallint not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a mediumint not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a int not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a bigint not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a float not null) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +a +drop table t1; +create table t1 (a double not null) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +a +2.1 +drop table t1; +create table t1 (a decimal not null) partition by key (a); +insert into t1 values (2.1); +Warnings: +Note 1265 Data truncated for column 'a' at row 1 +select * from t1 where a = 2.1; +a +drop table t1; +create table t1 (a date not null) partition by key (a); +insert into t1 values ('2001-01-01'); +select * from t1 where a = '2001-01-01'; +a +2001-01-01 +drop table t1; +create table t1 (a datetime not null) partition by key (a); +insert into t1 values ('2001-01-01 01:02:03'); +select * from t1 where a = '2001-01-01 01:02:03'; +a +2001-01-01 01:02:03 +drop table t1; +create table t1 (a timestamp not null) partition by key (a); +insert into t1 values ('2001-01-01 01:02:03'); +select * from t1 where a = '2001-01-01 01:02:03'; +a +2001-01-01 01:02:03 +drop table t1; +create table t1 (a time not null) partition by key (a); +insert into t1 values ('01:02:03'); +select * from t1 where a = '01:02:03'; +a +01:02:03 +drop table t1; +create table t1 (a year not null) partition by key (a); +insert into t1 values ('2001'); +select * from t1 where a = '2001'; +a +2001 +drop table t1; +create table t1 (a varchar(10) character set utf8 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a varchar(300) character set utf8 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a varchar(10) character set latin1 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a varchar(300) character set latin1 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a char(10) character set utf8 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a char(10) character set latin1 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a enum('y','n') not null) partition by key (a); +insert into t1 values ('y'); +select * from t1 where a = 'y'; +a +y +drop table t1; +create table t1 (a set('y','n') not null) partition by key (a); +insert into t1 values ('y'); +select * from t1 where a = 'y'; +a +y +drop table t1; +create table t1 (a tinyint) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a smallint) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a mediumint) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a int) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a bigint) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +a +2 +drop table t1; +create table t1 (a float) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +a +drop table t1; +create table t1 (a double) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +a +2.1 +drop table t1; +create table t1 (a decimal) partition by key (a); +insert into t1 values (2.1); +Warnings: +Note 1265 Data truncated for column 'a' at row 1 +select * from t1 where a = 2.1; +a +drop table t1; +create table t1 (a date) partition by key (a); +insert into t1 values ('2001-01-01'); +select * from t1 where a = '2001-01-01'; +a +2001-01-01 +drop table t1; +create table t1 (a datetime) partition by key (a); +insert into t1 values ('2001-01-01 01:02:03'); +select * from t1 where a = '2001-01-01 01:02:03'; +a +2001-01-01 01:02:03 +drop table t1; +create table t1 (a timestamp null) partition by key (a); +insert into t1 values ('2001-01-01 01:02:03'); +select * from t1 where a = '2001-01-01 01:02:03'; +a +2001-01-01 01:02:03 +drop table t1; +create table t1 (a time) partition by key (a); +insert into t1 values ('01:02:03'); +select * from t1 where a = '01:02:03'; +a +01:02:03 +drop table t1; +create table t1 (a year) partition by key (a); +insert into t1 values ('2001'); +select * from t1 where a = '2001'; +a +2001 +drop table t1; +create table t1 (a varchar(10) character set utf8) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a varchar(300) character set utf8) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a varchar(10) character set latin1) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a varchar(300) character set latin1) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a char(10) character set utf8) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a char(10) character set latin1) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +a +abc +drop table t1; +create table t1 (a enum('y','n')) partition by key (a); +insert into t1 values ('y'); +select * from t1 where a = 'y'; +a +y +drop table t1; +create table t1 (a set('y','n')) partition by key (a); +insert into t1 values ('y'); +select * from t1 where a = 'y'; +a +y +drop table t1; +create table t1 (a varchar(65531)) partition by key (a); +insert into t1 values ('bbbb'); +insert into t1 values ('aaaa'); +select * from t1 where a = 'aaa%'; +a +select * from t1 where a like 'aaa%'; +a +aaaa +drop table t1; +create table t1 (a varchar(65532)) partition by key (a); +insert into t1 values ('bbbb'); +insert into t1 values ('aaaa'); +select * from t1 where a = 'aaa%'; +a +select * from t1 where a like 'aaa%'; +a +aaaa +drop table t1; +create table t1 (a varchar(65533) not null) partition by key (a); +insert into t1 values ('aaaa'); +select * from t1 where a = 'aaa%'; +a +drop table t1; +create table t1 (a varchar(65533)) partition by key (a); +ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs +create table t1 (a varchar(65534) not null) partition by key (a); +ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs +create table t1 (a varchar(65535)) partition by key (a); +ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs diff --git a/mysql-test/t/partition_datatype.test b/mysql-test/t/partition_datatype.test new file mode 100644 index 00000000000..61d3cb42c7b --- /dev/null +++ b/mysql-test/t/partition_datatype.test @@ -0,0 +1,213 @@ +# +# Simple test for the partition storage engine +# with most datatypes and null / not null +# as partition by key +# Created to verify the fix for Bug#31705 +# Partitions: crash if varchar length > 65530 +# +-- source include/have_partition.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +# FIXME: disabled this test because of valgrind error +#create table t1 (a bit not null) partition by key (a); +#insert into t1 values (b'1'); +#select * from t1 where a = b'1'; +#drop table t1; +create table t1 (a tinyint not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a smallint not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a mediumint not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a int not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a bigint not null) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a float not null) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +drop table t1; +create table t1 (a double not null) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +drop table t1; +create table t1 (a decimal not null) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +drop table t1; +create table t1 (a date not null) partition by key (a); +insert into t1 values ('2001-01-01'); +select * from t1 where a = '2001-01-01'; +drop table t1; +create table t1 (a datetime not null) partition by key (a); +insert into t1 values ('2001-01-01 01:02:03'); +select * from t1 where a = '2001-01-01 01:02:03'; +drop table t1; +create table t1 (a timestamp not null) partition by key (a); +insert into t1 values ('2001-01-01 01:02:03'); +select * from t1 where a = '2001-01-01 01:02:03'; +drop table t1; +create table t1 (a time not null) partition by key (a); +insert into t1 values ('01:02:03'); +select * from t1 where a = '01:02:03'; +drop table t1; +create table t1 (a year not null) partition by key (a); +insert into t1 values ('2001'); +select * from t1 where a = '2001'; +drop table t1; +create table t1 (a varchar(10) character set utf8 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a varchar(300) character set utf8 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a varchar(10) character set latin1 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a varchar(300) character set latin1 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a char(10) character set utf8 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a char(10) character set latin1 not null) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a enum('y','n') not null) partition by key (a); +insert into t1 values ('y'); +select * from t1 where a = 'y'; +drop table t1; +create table t1 (a set('y','n') not null) partition by key (a); +insert into t1 values ('y'); +select * from t1 where a = 'y'; +drop table t1; +# FIXME: disabled this test because of valgrind error +#create table t1 (a bit) partition by key (a); +#insert into t1 values (b'1'); +#select * from t1 where a = b'1'; +#drop table t1; +create table t1 (a tinyint) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a smallint) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a mediumint) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a int) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a bigint) partition by key (a); +insert into t1 values (2); +select * from t1 where a = 2; +drop table t1; +create table t1 (a float) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +drop table t1; +create table t1 (a double) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +drop table t1; +create table t1 (a decimal) partition by key (a); +insert into t1 values (2.1); +select * from t1 where a = 2.1; +drop table t1; +create table t1 (a date) partition by key (a); +insert into t1 values ('2001-01-01'); +select * from t1 where a = '2001-01-01'; +drop table t1; +create table t1 (a datetime) partition by key (a); +insert into t1 values ('2001-01-01 01:02:03'); +select * from t1 where a = '2001-01-01 01:02:03'; +drop table t1; +create table t1 (a timestamp null) partition by key (a); +insert into t1 values ('2001-01-01 01:02:03'); +select * from t1 where a = '2001-01-01 01:02:03'; +drop table t1; +create table t1 (a time) partition by key (a); +insert into t1 values ('01:02:03'); +select * from t1 where a = '01:02:03'; +drop table t1; +create table t1 (a year) partition by key (a); +insert into t1 values ('2001'); +select * from t1 where a = '2001'; +drop table t1; +create table t1 (a varchar(10) character set utf8) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a varchar(300) character set utf8) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a varchar(10) character set latin1) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a varchar(300) character set latin1) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a char(10) character set utf8) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a char(10) character set latin1) partition by key (a); +insert into t1 values ('abc'); +select * from t1 where a = 'abc'; +drop table t1; +create table t1 (a enum('y','n')) partition by key (a); +insert into t1 values ('y'); +select * from t1 where a = 'y'; +drop table t1; +create table t1 (a set('y','n')) partition by key (a); +insert into t1 values ('y'); +select * from t1 where a = 'y'; +drop table t1; +create table t1 (a varchar(65531)) partition by key (a); +insert into t1 values ('bbbb'); +insert into t1 values ('aaaa'); +select * from t1 where a = 'aaa%'; +select * from t1 where a like 'aaa%'; +drop table t1; +create table t1 (a varchar(65532)) partition by key (a); +insert into t1 values ('bbbb'); +insert into t1 values ('aaaa'); +select * from t1 where a = 'aaa%'; +select * from t1 where a like 'aaa%'; +drop table t1; +create table t1 (a varchar(65533) not null) partition by key (a); +insert into t1 values ('aaaa'); +select * from t1 where a = 'aaa%'; +drop table t1; +-- error ER_TOO_BIG_ROWSIZE +create table t1 (a varchar(65533)) partition by key (a); +-- error ER_TOO_BIG_ROWSIZE +create table t1 (a varchar(65534) not null) partition by key (a); +-- error ER_TOO_BIG_ROWSIZE +create table t1 (a varchar(65535)) partition by key (a); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 99c28be36b0..b89e8b3dcbb 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -3344,18 +3344,16 @@ static bool create_partition_index_description(PART_PRUNE_PARAM *ppar) { key_part->key= 0; key_part->part= part; - key_part->length= (uint16) (*field)->pack_length_in_rec(); - /* - psergey-todo: check yet again if this is correct for tricky field types, - e.g. see "Fix a fatal error in decimal key handling" in open_binary_frm() - */ - key_part->store_length= (uint16) (*field)->pack_length(); + key_part->store_length= key_part->length= (uint16) (*field)->key_length(); if ((*field)->real_maybe_null()) key_part->store_length+= HA_KEY_NULL_LENGTH; if ((*field)->type() == MYSQL_TYPE_BLOB || (*field)->real_type() == MYSQL_TYPE_VARCHAR) key_part->store_length+= HA_KEY_BLOB_LENGTH; + DBUG_PRINT("info", ("part %u length %u store_length %u", part, + key_part->length, key_part->store_length)); + key_part->field= (*field); key_part->image_type = Field::itRAW; /*