diff options
author | unknown <igor@rurik.mysql.com> | 2006-06-02 14:14:57 -0700 |
---|---|---|
committer | unknown <igor@rurik.mysql.com> | 2006-06-02 14:14:57 -0700 |
commit | e3e0658779bffacd5323efb54ecb7f42ded19231 (patch) | |
tree | 73c42f8475188528c843bc2d2a7f64fa2f122d1e /sql/opt_sum.cc | |
parent | a9824f263dcaedaabfbbc9e398eb55117f19a41f (diff) | |
download | mariadb-git-e3e0658779bffacd5323efb54ecb7f42ded19231.tar.gz |
Fixed bug #18206.
The bug report revealed two problems related to min/max optimization:
1. If the length of a constant key used in a SARGable condition for
for the MIN/MAX fields is greater than the length of the field an
unwanted warning on key truncation is issued;
2. If MIN/MAX optimization is applied to a partial index, like INDEX(b(4))
than can lead to returning a wrong result set.
mysql-test/r/func_group.result:
Added test cases for bug #18206.
mysql-test/t/func_group.test:
Added test cases for bug #18206.
sql/opt_sum.cc:
Fixed bug #18206.
Suppressed the warning about data truncation when store_val_in_field
was used to store keys for the field used in MIN/MAX optimization.
Blocked MIN/MAX optimization for partial keys, such as in INDEX(b(4)).
sql/sql_select.cc:
Fixed bug #18206.
Added a parameter for the function store_val_in_field allowing to
control setting warnings about data truncation in the function.
sql/sql_select.h:
Fixed bug #18206.
Added a parameter for the function store_val_in_field allowing to
control setting warnings about data truncation in the function.
Diffstat (limited to 'sql/opt_sum.cc')
-rw-r--r-- | sql/opt_sum.cc | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index cfb5b3695a3..82211120c57 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -543,6 +543,10 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, break; // Found a part od the key for the field } +#if 0 + if (part->length != (((Item_field*) args[0])->field)->field_length) + return 0; +#endif bool is_field_part= part == field_part; if (!(is_field_part || eq_type)) return 0; @@ -582,7 +586,8 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, } else { - store_val_in_field(part->field, args[between && max_fl ? 2 : 1]); + store_val_in_field(part->field, args[between && max_fl ? 2 : 1], + CHECK_FIELD_IGNORE); if (part->null_bit) *key_ptr++= (byte) test(part->field->is_null()); part->field->get_key_image((char*) key_ptr, part->length, @@ -638,6 +643,8 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, field BETWEEN const1 AND const2 3. all references to the columns from the same table as column field occur only in conjucts mentioned above. + 4. each of k first components the index is not partial, i.e. is not + defined on a fixed length proper prefix of the field. If such an index exists the function through the ref parameter returns the key value to find max/min for the field using the index, @@ -647,8 +654,8 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, of the whole search key) NOTE - This function may set table->key_read to 1, which must be reset after - index is used! (This can only happen when function returns 1) + This function may set table->key_read to 1, which must be reset after + index is used! (This can only happen when function returns 1) RETURN 0 Index can not be used to optimize MIN(field)/MAX(field) @@ -682,6 +689,10 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, if (!(table->file->index_flags(idx, jdx, 0) & HA_READ_ORDER)) return 0; + /* Check whether the index component is partial */ + if (part->length < table->field[part->fieldnr-1]->pack_length()) + break; + if (field->eq(part->field)) { ref->key= idx; |