From: igor Date: June 3 2006 12:06am Subject: bk commit into 5.0 tree (igor:1.2165) List-Archive: http://lists.mysql.com/commits/7234 Message-Id: <20060603000620.BFAEC2E5AB2@rurik.mysql.com> Below is the list of changes that have just been committed into a local 5.0 repository of igor. When igor 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 1.2165 06/06/02 17:06:10 igor@stripped +5 -0 Merge rurik.mysql.com:/home/igor/mysql-4.1-opt into rurik.mysql.com:/home/igor/mysql-5.0-opt mysql-test/t/func_group.test 1.47 06/06/02 17:06:05 igor@stripped +0 -0 SCCS merged mysql-test/r/func_group.result 1.49 06/06/02 17:06:05 igor@stripped +0 -0 SCCS merged sql/sql_select.h 1.108 06/06/02 16:55:50 igor@stripped +0 -0 Auto merged sql/sql_select.cc 1.422 06/06/02 16:55:50 igor@stripped +0 -0 Auto merged sql/opt_sum.cc 1.52 06/06/02 16:55:50 igor@stripped +0 -0 Auto merged # 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: igor # Host: rurik.mysql.com # Root: /home/igor/mysql-5.0-opt/RESYNC --- 1.51/sql/opt_sum.cc 2006-04-06 10:42:00 -07:00 +++ 1.52/sql/opt_sum.cc 2006-06-02 16:55:50 -07:00 @@ -569,6 +569,10 @@ 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; @@ -608,7 +612,8 @@ } 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, Field::itRAW); @@ -663,6 +668,8 @@ 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, @@ -672,8 +679,8 @@ 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) @@ -706,6 +713,10 @@ { 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)) { --- 1.421/sql/sql_select.cc 2006-05-26 01:51:17 -07:00 +++ 1.422/sql/sql_select.cc 2006-06-02 16:55:50 -07:00 @@ -4788,7 +4788,7 @@ */ bool -store_val_in_field(Field *field,Item *item) +store_val_in_field(Field *field, Item *item, enum_check_fields check_flag) { bool error; THD *thd= field->table->in_use; @@ -4799,7 +4799,7 @@ with select_insert, which make count_cuted_fields= 1 */ enum_check_fields old_count_cuted_fields= thd->count_cuted_fields; - thd->count_cuted_fields= CHECK_FIELD_WARN; + thd->count_cuted_fields= check_flag; error= item->save_in_field(field, 1); thd->count_cuted_fields= old_count_cuted_fields; return error || cuted_fields != thd->cuted_fields; @@ -10928,7 +10928,7 @@ field->real_type() != MYSQL_TYPE_VARCHAR && (field->type() != FIELD_TYPE_FLOAT || field->decimals() == 0)) { - return !store_val_in_field(field,right_item); + return !store_val_in_field(field, right_item, CHECK_FIELD_WARN); } } } --- 1.107/sql/sql_select.h 2006-02-27 04:51:34 -08:00 +++ 1.108/sql/sql_select.h 2006-06-02 16:55:50 -07:00 @@ -404,7 +404,7 @@ void TEST_join(JOIN *join); /* Extern functions in sql_select.cc */ -bool store_val_in_field(Field *field,Item *val); +bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag); TABLE *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, ORDER *group, bool distinct, bool save_sum_fields, ulonglong select_options, ha_rows rows_limit, --- 1.48/mysql-test/r/func_group.result 2006-05-22 06:10:48 -07:00 +++ 1.49/mysql-test/r/func_group.result 2006-06-02 17:06:05 -07:00 @@ -821,6 +821,30 @@ MAX(id) NULL DROP TABLE t1; +CREATE TABLE t1 (id int PRIMARY KEY, b char(3), INDEX(b)); +INSERT INTO t1 VALUES (1,'xx'), (2,'aa'); +SELECT * FROM t1; +id b +1 xx +2 aa +SELECT MAX(b) FROM t1 WHERE b < 'ppppp'; +MAX(b) +aa +SHOW WARNINGS; +Level Code Message +SELECT MAX(b) FROM t1 WHERE b < 'pp'; +MAX(b) +aa +DROP TABLE t1; +CREATE TABLE t1 (id int PRIMARY KEY, b char(16), INDEX(b(4))); +INSERT INTO t1 VALUES (1, 'xxxxbbbb'), (2, 'xxxxaaaa'); +SELECT MAX(b) FROM t1; +MAX(b) +xxxxbbbb +EXPLAIN SELECT MAX(b) FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +DROP TABLE t1; create table t2 (ff double); insert into t2 values (2.2); select cast(sum(distinct ff) as decimal(5,2)) from t2; --- 1.46/mysql-test/t/func_group.test 2006-05-22 06:10:48 -07:00 +++ 1.47/mysql-test/t/func_group.test 2006-06-02 17:06:05 -07:00 @@ -539,6 +539,25 @@ SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6; DROP TABLE t1; +# +# Bug #18206: min/max optimization cannot be applied to partial index +# + +CREATE TABLE t1 (id int PRIMARY KEY, b char(3), INDEX(b)); +INSERT INTO t1 VALUES (1,'xx'), (2,'aa'); +SELECT * FROM t1; + +SELECT MAX(b) FROM t1 WHERE b < 'ppppp'; +SHOW WARNINGS; +SELECT MAX(b) FROM t1 WHERE b < 'pp'; +DROP TABLE t1; + +CREATE TABLE t1 (id int PRIMARY KEY, b char(16), INDEX(b(4))); +INSERT INTO t1 VALUES (1, 'xxxxbbbb'), (2, 'xxxxaaaa'); +SELECT MAX(b) FROM t1; +EXPLAIN SELECT MAX(b) FROM t1; +DROP TABLE t1; + # End of 4.1 tests #