Skip to content

Commit 93f2f63

Browse files
author
Sergey Glukhov
committed
Bug#16391678 EXT. SECONDARY KEYS DON'T WORK FOR CUSTOM STORAGE ENGINES
Added possibility to use 'extended keys' feature for custom storage engines.
1 parent 6ca09cc commit 93f2f63

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

sql/handler.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,17 @@ struct handlerton
968968
#define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported
969969
#define HTON_SUPPORT_LOG_TABLES (1 << 7) //Engine supports log tables
970970
#define HTON_NO_PARTITION (1 << 8) //You can not partition these tables
971+
972+
/**
973+
Engine supports extended keys. The flag allows to
974+
use 'extended key' feature if the engine is able to
975+
do it (has primary key values in the secondary key).
976+
Note that handler flag HA_PRIMARY_KEY_IN_READ_INDEX is
977+
actually partial case of HTON_SUPPORTS_EXTENDED_KEYS.
978+
*/
979+
980+
#define HTON_SUPPORTS_EXTENDED_KEYS (1 << 9)
981+
971982
/*
972983
This flag should be set when deciding that the engine does not allow row based
973984
binary logging (RBL) optimizations.

sql/table.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,9 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
11011101

11021102
strpos=disk_buff+6;
11031103

1104-
use_extended_sk= (legacy_db_type == DB_TYPE_INNODB);
1104+
use_extended_sk=
1105+
ha_check_storage_engine_flag(share->db_type(),
1106+
HTON_SUPPORTS_EXTENDED_KEYS);
11051107

11061108
uint total_key_parts;
11071109
if (use_extended_sk)
@@ -1175,12 +1177,12 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
11751177
key_part->store_length=key_part->length;
11761178
}
11771179
/*
1178-
Add PK parts if engine supports PK extension for secondary keys.
1179-
Atm it works for Innodb only. Here we add unique first key parts
1180-
to the end of secondary key parts array and increase actual number
1181-
of key parts. Note that primary key is always first if exists.
1182-
Later if there is no PK in the table then number of actual keys parts
1183-
is set to user defined key parts.
1180+
Add primary key parts if engine supports primary key extension for
1181+
secondary keys. Here we add unique first key parts to the end of
1182+
secondary key parts array and increase actual number of key parts.
1183+
Note that primary key is always first if exists. Later if there is no
1184+
primary key in the table then number of actual keys parts is set to
1185+
user defined key parts.
11841186
*/
11851187
keyinfo->actual_key_parts= keyinfo->user_defined_key_parts;
11861188
keyinfo->actual_flags= keyinfo->flags;

storage/innobase/handler/ha_innodb.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,7 @@ innobase_init(
27712771

27722772
innobase_hton->flush_logs = innobase_flush_logs;
27732773
innobase_hton->show_status = innobase_show_status;
2774-
innobase_hton->flags = HTON_NO_FLAGS;
2774+
innobase_hton->flags = HTON_SUPPORTS_EXTENDED_KEYS;
27752775

27762776
innobase_hton->release_temporary_latches =
27772777
innobase_release_temporary_latches;

0 commit comments

Comments
 (0)