Hi, Georgi!
On Nov 12, Georgi Kodinov wrote:
> On 12.11.2008, at 12:18, Sergei Golubchik wrote:
>
>> Don't you think that the bug is here:
>>
>> /*
>> If this field is part of the primary key and all keys contains
>> the primary key, then we can use any key to find this column
>> */
>> if (ha_option & HA_PRIMARY_KEY_IN_READ_INDEX)
>> {
>> field->part_of_key= share->keys_in_use;
>> if (field->part_of_sortkey.is_set(key))
>> field->part_of_sortkey= share->keys_in_use;
>> }
>>
>> looks like it shouldn't set field->part_of_key to all keys if the
>> primary key is built on the part of the field.
>
> Why ? Even a partial key part of the primary key is a part of all the
> secondary keys.
And ? It's never used as such, as far as I can see.
field->part_of_key is used to determine what keys can be used and
whether keyread can be used.
For partial primary keys added to every secondary key, keyread is wrong,
and should not be used (it's a subject of this bug). As for the "what
keys can be used" - primary key parts aren't used when searching by
secondary key (*) so in this role field->part_of_key is unused.
To summarize: field->part_of_key is used for two purposes, but when a
partial primary key is added to all secondary keys the first usage of
part_of_key is ignored, the second - leads to wrong results :)
Regards / Mit vielen Grüßen,
Sergei
(*) I mean that in
CREATE TABLE t1 (a int, b int, c int, d int, primary key (a,b), index (c));
...
SELECT * FROM t1 WHERE c=10 AND a=11;
MySQL could, technically speaking, notice that the index {c} is, in
fact, index {c,a,b} and search for the pair {10,11}. But we don't do
that. So this usage of field->part_of_key is not utilized.
--
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Sergei Golubchik <serg@stripped>
/ /|_/ / // /\ \/ /_/ / /__ Principal Software Engineer/Server Architect
/_/ /_/\_, /___/\___\_\___/ Sun Microsystems GmbH, HRB München 161028
<___/ Sonnenallee 1, 85551 Kirchheim-Heimstetten
Geschäftsführer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer
Vorsitzender des Aufsichtsrates: Martin Häring