@@ -1852,6 +1852,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
1852
1852
bool *interval_unescaped= NULL ;
1853
1853
extra2_fields extra2;
1854
1854
bool extra_index_flags_present= FALSE ;
1855
+ key_map sort_keys_in_use (0 );
1855
1856
DBUG_ENTER (" TABLE_SHARE::init_from_binary_frm_image" );
1856
1857
1857
1858
keyinfo= &first_keyinfo;
@@ -3207,7 +3208,10 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
3207
3208
field->part_of_key .set_bit (key);
3208
3209
}
3209
3210
if (handler_file->index_flags (key, i, 1 ) & HA_READ_ORDER)
3211
+ {
3210
3212
field->part_of_sortkey .set_bit (key);
3213
+ sort_keys_in_use.set_bit (key);
3214
+ }
3211
3215
3212
3216
if (i < keyinfo->user_defined_key_parts )
3213
3217
field->part_of_key_not_clustered .set_bit (key);
@@ -3216,22 +3220,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
3216
3220
usable_parts == i)
3217
3221
usable_parts++; // For FILESORT
3218
3222
field->flags |= PART_KEY_FLAG;
3219
- if (key == primary_key)
3220
- {
3221
- field->flags |= PRI_KEY_FLAG;
3222
- /*
3223
- If this field is part of the primary key and all keys contains
3224
- the primary key, then we can use any key to find this column
3225
- */
3226
- if (ha_option & HA_PRIMARY_KEY_IN_READ_INDEX)
3227
- {
3228
- if (field->key_length () == key_part->length &&
3229
- !(field->flags & BLOB_FLAG))
3230
- field->part_of_key = share->keys_in_use ;
3231
- if (field->part_of_sortkey .is_set (key))
3232
- field->part_of_sortkey = share->keys_in_use ;
3233
- }
3234
- }
3235
3223
if (field->key_length () != key_part->length )
3236
3224
{
3237
3225
#ifndef TO_BE_DELETED_ON_PRODUCTION
@@ -3294,21 +3282,39 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
3294
3282
if (primary_key < MAX_KEY &&
3295
3283
(share->keys_in_use .is_set (primary_key)))
3296
3284
{
3297
- DBUG_ASSERT ( share->primary_key == primary_key) ;
3285
+ keyinfo= share->key_info + primary_key;
3298
3286
/*
3299
3287
If we are using an integer as the primary key then allow the user to
3300
3288
refer to it as '_rowid'
3301
3289
*/
3302
- if (share-> key_info [primary_key]. user_defined_key_parts == 1 )
3290
+ if (keyinfo-> user_defined_key_parts == 1 )
3303
3291
{
3304
- Field *field= share-> key_info [primary_key]. key_part [0 ].field ;
3292
+ Field *field= keyinfo-> key_part [0 ].field ;
3305
3293
if (field && field->result_type () == INT_RESULT)
3306
3294
{
3307
3295
/* note that fieldnr here (and rowid_field_offset) starts from 1 */
3308
- share->rowid_field_offset = (share->key_info [primary_key].key_part [0 ].
3309
- fieldnr);
3296
+ share->rowid_field_offset = keyinfo->key_part [0 ].fieldnr ;
3310
3297
}
3311
3298
}
3299
+ for (i=0 ; i < keyinfo->user_defined_key_parts ; key_part++, i++)
3300
+ {
3301
+ Field *field= keyinfo->key_part [i].field ;
3302
+ field->flags |= PRI_KEY_FLAG;
3303
+ /*
3304
+ If this field is part of the primary key and all keys contains
3305
+ the primary key, then we can use any key to find this column
3306
+ */
3307
+ if (ha_option & HA_PRIMARY_KEY_IN_READ_INDEX)
3308
+ {
3309
+ if (field->key_length () == keyinfo->key_part [i].length &&
3310
+ !(field->flags & BLOB_FLAG))
3311
+ {
3312
+ field->part_of_key = share->keys_in_use ;
3313
+ field->part_of_sortkey = sort_keys_in_use;
3314
+ }
3315
+ }
3316
+ }
3317
+ DBUG_ASSERT (share->primary_key == primary_key);
3312
3318
}
3313
3319
else
3314
3320
{
0 commit comments