mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Manual merge of mysql-5.1-bugteam into mysql-trunk-merge.
Conflicts: Text conflict in .bzr-mysql/default.conf Text conflict in mysql-test/r/explain.result Text conflict in mysql-test/r/having.result Text conflict in mysql-test/suite/rpl/t/disabled.def Text conflict in mysql-test/suite/rpl/t/rpl_slave_skip.test Text conflict in storage/federated/ha_federated.cc
This commit is contained in:
@ -13032,12 +13032,35 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
|
||||
|
||||
uint find_shortest_key(TABLE *table, const key_map *usable_keys)
|
||||
{
|
||||
uint min_length= (uint) ~0;
|
||||
uint best= MAX_KEY;
|
||||
uint usable_clustered_pk= (table->file->primary_key_is_clustered() &&
|
||||
table->s->primary_key != MAX_KEY &&
|
||||
usable_keys->is_set(table->s->primary_key)) ?
|
||||
table->s->primary_key : MAX_KEY;
|
||||
if (!usable_keys->is_clear_all())
|
||||
{
|
||||
uint min_length= (uint) ~0;
|
||||
for (uint nr=0; nr < table->s->keys ; nr++)
|
||||
{
|
||||
/*
|
||||
As far as
|
||||
1) clustered primary key entry data set is a set of all record
|
||||
fields (key fields and not key fields) and
|
||||
2) secondary index entry data is a union of its key fields and
|
||||
primary key fields (at least InnoDB and its derivatives don't
|
||||
duplicate primary key fields there, even if the primary and
|
||||
the secondary keys have a common subset of key fields),
|
||||
then secondary index entry data is always a subset of primary key
|
||||
entry, and the PK is always longer.
|
||||
Unfortunately, key_info[nr].key_length doesn't show the length
|
||||
of key/pointer pair but a sum of key field lengths only, thus
|
||||
we can't estimate index IO volume comparing only this key_length
|
||||
value of seconday keys and clustered PK.
|
||||
So, try secondary keys first, and choose PK only if there are no
|
||||
usable secondary covering keys:
|
||||
*/
|
||||
if (nr == usable_clustered_pk)
|
||||
continue;
|
||||
if (usable_keys->is_set(nr))
|
||||
{
|
||||
if (table->key_info[nr].key_length < min_length)
|
||||
@ -13048,7 +13071,7 @@ uint find_shortest_key(TABLE *table, const key_map *usable_keys)
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
return best != MAX_KEY ? best : usable_clustered_pk;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user