| 27367 | */ |
| 27368 | |
| 27369 | static uint |
| 27370 | test_if_subkey(ORDER *order, TABLE *table, uint ref, uint ref_key_parts, |
| 27371 | const key_map *usable_keys) |
| 27372 | { |
| 27373 | uint nr; |
| 27374 | uint min_length= (uint) ~0; |
| 27375 | uint best= MAX_KEY; |
| 27376 | KEY_PART_INFO *ref_key_part= table->key_info[ref].key_part; |
| 27377 | KEY_PART_INFO *ref_key_part_end= ref_key_part + ref_key_parts; |
| 27378 | |
| 27379 | /* |
| 27380 | Find the shortest key that |
| 27381 | - produces the required ordering |
| 27382 | - has key #ref (up to ref_key_parts) as its subkey. |
| 27383 | */ |
| 27384 | for (nr= 0 ; nr < table->s->keys ; nr++) |
| 27385 | { |
| 27386 | uint not_used; |
| 27387 | if (usable_keys->is_set(nr) && |
| 27388 | table->key_info[nr].key_length < min_length && |
| 27389 | table->key_info[nr].user_defined_key_parts >= ref_key_parts && |
| 27390 | is_subkey(table->key_info[nr].key_part, ref_key_part, |
| 27391 | ref_key_part_end) && |
| 27392 | test_if_order_by_key(NULL, order, table, nr, ¬_used)) |
| 27393 | { |
| 27394 | min_length= table->key_info[nr].key_length; |
| 27395 | best= nr; |
| 27396 | } |
| 27397 | } |
| 27398 | return best; |
| 27399 | } |
| 27400 | |
| 27401 | |
| 27402 | /** |
no test coverage detected