Below is the list of changes that have just been committed into a local
5.0 repository of . When 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.1910 05/08/29 17:13:42 timour@stripped +3 -0
Fix for BUG#12672.
sql/opt_range.cc
1.184 05/08/29 17:13:37 timour@stripped +40 -0
Some storage managers like InnoDB always retrieve the value of
the primary key (if any) with any other key. For such storage
managers the optimizer marks an index as covering if that index
and the primary key contain all query fields. This is good for
reading data from an index, but not for lookup. The patch detects
such cases and tests whether an index is really a covering index
by itself, without the primary key. If yes, then that index can
be used for the index skip algorithm of the GROUP_MIN_MAX
access method.
mysql-test/t/group_min_max.test
1.13 05/08/29 17:13:37 timour@stripped +19 -0
Test for BUG#12672.
mysql-test/r/group_min_max.result
1.15 05/08/29 17:13:37 timour@stripped +20 -0
Test for BUG#12672.
# 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: timour
# Host: zmei.
# Root: X:/home/timka/mysql/src/5.0-bug-12672
--- 1.183/sql/opt_range.cc 2005-07-18 18:36:11 +03:00
+++ 1.184/sql/opt_range.cc 2005-08-29 17:13:37 +03:00
@@ -7016,6 +7016,7 @@
ha_rows cur_quick_prefix_records= 0;
uint cur_param_idx;
key_map cur_used_key_parts;
+ uint pk= param->table->s->primary_key;
for (uint cur_index= 0 ; cur_index_info != cur_index_info_end ;
cur_index_info++, cur_index++)
@@ -7023,6 +7024,45 @@
/* Check (B1) - if current index is covering. */
if (!table->used_keys.is_set(cur_index))
goto next_index;
+
+ /*
+ If the current storage manager is such that it appends the primary key to
+ each index, then the above condition is insufficient to check if the
+ index is covering. In such cases it may happen that some fields are
+ covered by the PK index, but not by the current index. Since we can't
+ use the concatenation of both indexes for index lookup, such an index
+ does not qualify as covering in our case. If this is the case, below
+ we check that all query fields are indeed covered by 'cur_index'.
+ */
+ if (pk < MAX_KEY && cur_index != pk &&
+ (table->file->table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX))
+ {
+ /* For each table field */
+ for (uint i= 0; i < table->s->fields; i++)
+ {
+ Field *cur_field= table->field[i];
+ /*
+ If the field is used in the current query, check that the
+ field is covered by some keypart of the current index.
+ */
+ if (thd->query_id == cur_field->query_id)
+ {
+ bool is_covered= FALSE;
+ KEY_PART_INFO *key_part= cur_index_info->key_part;
+ KEY_PART_INFO *key_part_end= key_part + cur_index_info->key_parts;
+ for (; key_part != key_part_end ; key_part++)
+ {
+ if (key_part->field == cur_field)
+ {
+ is_covered= TRUE;
+ break;
+ }
+ }
+ if (!is_covered)
+ goto next_index;
+ }
+ }
+ }
/*
Check (GA1) for GROUP BY queries.
--- 1.14/mysql-test/r/group_min_max.result 2005-06-14 12:52:38 +03:00
+++ 1.15/mysql-test/r/group_min_max.result 2005-08-29 17:13:37 +03:00
@@ -1972,6 +1972,26 @@
b
c
d
+create table bug12672 (
+pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
+) engine=innodb;
+insert into bug12672 (a1, a2, b, c, d, dummy) select * from t1;
+create index idx12672_0 on bug12672 (a1);
+create index idx12672_1 on bug12672 (a1,a2,b,c);
+create index idx12672_2 on bug12672 (a1,a2,b);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Table is already up to date
+explain select distinct a1 from bug12672 where pk_col not in (1,2,3,4);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE bug12672 range PRIMARY PRIMARY 4 NULL 93 Using where; Using temporary
+select distinct a1 from bug12672 where pk_col not in (1,2,3,4);
+a1
+a
+b
+c
+d
+drop table bug12672;
drop table t1;
drop table t2;
drop table t3;
--- 1.12/mysql-test/t/group_min_max.test 2005-06-14 12:52:38 +03:00
+++ 1.13/mysql-test/t/group_min_max.test 2005-08-29 17:13:37 +03:00
@@ -651,6 +651,25 @@
explain select distinct a1 from t1 where a2 = 'b';
select distinct a1 from t1 where a2 = 'b';
+#
+# Bug #12672: primary key implcitly included in every innodb index
+#
+
+create table bug12672 (
+ pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
+) engine=innodb;
+
+insert into bug12672 (a1, a2, b, c, d, dummy) select * from t1;
+
+create index idx12672_0 on bug12672 (a1);
+create index idx12672_1 on bug12672 (a1,a2,b,c);
+create index idx12672_2 on bug12672 (a1,a2,b);
+analyze table t1;
+
+explain select distinct a1 from bug12672 where pk_col not in (1,2,3,4);
+select distinct a1 from bug12672 where pk_col not in (1,2,3,4);
+
+drop table bug12672;
drop table t1;
drop table t2;
| Thread |
|---|
| • bk commit into 5.0 tree (timour:1.1910) BUG#12672 | timour | 29 Aug |