From: Date: October 19 2006 9:52am Subject: bk commit into 4.1 tree (ramil:1.2578) BUG#20732 List-Archive: http://lists.mysql.com/commits/13940 X-Bug: 20732 Message-Id: <200610190752.k9J7qgX5022330@myoffice.izhnet.ru> Below is the list of changes that have just been committed into a local 4.1 repository of ram. When ram does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2006-10-19 12:52:37+05:00, ramil@stripped +6 -0 Fix for bug #20732: Partial index and long sjis search with '>' fails sometimes We miss some records sometimes using RANGE method if we have partial key segments. Example: Create table t1(a char(2), key(a(1))); insert into t1 values ('a'), ('xx'); select a from t1 where a > 'x'; We call index_read() passing 'x' key and HA_READ_AFTER_KEY flag in the handler::read_range_first() wich is wrong because we have a partial key segment for the field and might miss records like 'xx'. Fix: don't use open segments in such a case. mysql-test/r/range.result@stripped, 2006-10-19 12:52:34+05:00, ramil@stripped +10 -0 Fix for bug #20732: Partial index and long sjis search with '>' fails sometimes - test result. mysql-test/t/range.test@stripped, 2006-10-19 12:52:34+05:00, ramil@stripped +11 -1 Fix for bug #20732: Partial index and long sjis search with '>' fails sometimes - test case. sql/opt_range.cc@stripped, 2006-10-19 12:52:34+05:00, ramil@stripped +5 -1 Fix for bug #20732: Partial index and long sjis search with '>' fails sometimes - check if we have a partial key segment for a Item_func::GT_FUNC; if so, don't set NEAR_MIN flag in order to use HA_READ_KEY_OR_NEXT instead of HA_READ_AFTER_KEY. sql/opt_range.h@stripped, 2006-10-19 12:52:34+05:00, ramil@stripped +1 -1 Fix for bug #20732: Partial index and long sjis search with '>' fails sometimes - key segment 'flag' slot added. sql/sql_select.cc@stripped, 2006-10-19 12:52:34+05:00, ramil@stripped +1 -1 Fix for bug #20732: Partial index and long sjis search with '>' fails sometimes - test (HA_PART_KEY_SEG | HA_NULL_PART) as we split it in the sql/table.cc sql/table.cc@stripped, 2006-10-19 12:52:35+05:00, ramil@stripped +1 -1 Fix for bug #20732: Partial index and long sjis search with '>' fails sometimes - set HA_NULL_PART flag instead of HA_PART_KEY_SEG in order not to mix them. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: ramil # Host: myoffice.izhnet.ru # Root: /usr/home/ram/work/bug20732/my41-bug20732 --- 1.149/sql/opt_range.cc 2006-10-19 12:52:43 +05:00 +++ 1.150/sql/opt_range.cc 2006-10-19 12:52:43 +05:00 @@ -885,6 +885,7 @@ int SQL_SELECT::test_quick_select(THD *t key_parts->null_bit= key_part_info->null_bit; key_parts->image_type = (key_info->flags & HA_SPATIAL) ? Field::itMBR : Field::itRAW; + key_parts->flag= key_part_info->key_part_flag; } param.real_keynr[param.keys++]=idx; } @@ -1398,7 +1399,9 @@ get_mm_leaf(PARAM *param, COND *conf_fun } break; case Item_func::GT_FUNC: - if (field_is_equal_to_item(field,value)) + /* Don't use open ranges for partial key_segments */ + if (field_is_equal_to_item(field,value) && + !(key_part->flag & HA_PART_KEY_SEG)) tree->min_flag=NEAR_MIN; /* fall through */ case Item_func::GE_FUNC: @@ -2899,6 +2902,7 @@ QUICK_SELECT *get_quick_select_for_ref(T key_part->length= key_info->key_part[part].length; key_part->store_length= key_info->key_part[part].store_length; key_part->null_bit= key_info->key_part[part].null_bit; + key_part->flag= key_info->key_part[part].key_part_flag; } if (quick->ranges.push_back(range)) goto err; --- 1.42/sql/opt_range.h 2006-10-19 12:52:43 +05:00 +++ 1.43/sql/opt_range.h 2006-10-19 12:52:43 +05:00 @@ -36,7 +36,7 @@ typedef struct st_key_part { uint16 key,part, store_length, length; - uint8 null_bit; + uint8 null_bit, flag; Field *field; Field::imagetype image_type; } KEY_PART; --- 1.460/sql/sql_select.cc 2006-10-19 12:52:43 +05:00 +++ 1.461/sql/sql_select.cc 2006-10-19 12:52:43 +05:00 @@ -7337,7 +7337,7 @@ part_of_refkey(TABLE *table,Field *field for (uint part=0 ; part < ref_parts ; part++,key_part++) if (field->eq(key_part->field) && - !(key_part->key_part_flag & HA_PART_KEY_SEG)) + !(key_part->key_part_flag & (HA_PART_KEY_SEG | HA_NULL_PART))) return table->reginfo.join_tab->ref.items[part]; } return (Item*) 0; --- 1.139/sql/table.cc 2006-10-19 12:52:43 +05:00 +++ 1.140/sql/table.cc 2006-10-19 12:52:43 +05:00 @@ -676,7 +676,7 @@ int openfrm(const char *name, const char as we need to test for NULL = NULL. */ if (field->real_maybe_null()) - key_part->key_part_flag|= HA_PART_KEY_SEG; + key_part->key_part_flag|= HA_NULL_PART; } else { // Error: shorten key --- 1.35/mysql-test/r/range.result 2006-10-19 12:52:43 +05:00 +++ 1.36/mysql-test/r/range.result 2006-10-19 12:52:43 +05:00 @@ -649,3 +649,13 @@ OR ((pk4 =1) AND (((pk1 IN ( 7, 2, 1 ))) pk1 pk2 pk3 pk4 filler 2621 2635 1000015 0 filler drop table t1, t2; +create table t1(a char(2), key(a(1))); +insert into t1 values ('x'), ('xx'); +explain select a from t1 where a > 'x'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 2 NULL 2 Using where +select a from t1 where a > 'x'; +a +xx +drop table t1; +End of 4.1 tests --- 1.31/mysql-test/t/range.test 2006-10-19 12:52:43 +05:00 +++ 1.32/mysql-test/t/range.test 2006-10-19 12:52:43 +05:00 @@ -510,4 +510,14 @@ OR ((pk4 =1) AND (((pk1 IN ( 7, 2, 1 ))) ) AND (pk3 >=1000000); drop table t1, t2; -# End of 4.1 tests +# +# Bug #20732: Partial index and long sjis search with '>' fails sometimes +# + +create table t1(a char(2), key(a(1))); +insert into t1 values ('x'), ('xx'); +explain select a from t1 where a > 'x'; +select a from t1 where a > 'x'; +drop table t1; + +--echo End of 4.1 tests