Friday, 15 June 2012

mysql - How to determine whether a multi-column index exists -



mysql - How to determine whether a multi-column index exists -

similar this question want determine if index exists, using more 1 column. example, have next table hotel room:

create table `rooms` ( `id` mediumint(9) not null auto_increment, `res_num` int(11) not null, `room_id` int(11) not null, `date` date not null, `adults` tinyint(4) not null default '0', `children` tinyint(4) not null default '0', `young_children` tinyint(4) not null default '0', `pets` tinyint(4) not null default '0', `smoking` tinyint(1) not null default '0', primary key (`id`), unique key `room_id` (`room_id`,`date`), key `res_num` (`res_num`), key `date` (`date`) ) engine=innodb auto_increment=97449 default charset=utf8

i want add together single index on room_id , date if not exist already. doing show index produces next output:

mysql> show index rooms; +-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | table | non_unique | key_name | seq_in_index | column_name | collation | cardinality | sub_part | packed | null | index_type | comment | index_comment | +-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | rooms | 0 | primary | 1 | id | | 67399 | null | null | | btree | | | | rooms | 0 | room_id | 1 | room_id | | 58 | null | null | | btree | | | | rooms | 0 | room_id | 2 | date | | 67399 | null | null | | btree | | | | rooms | 1 | res_num | 1 | res_num | | 67399 | null | null | | btree | | | | rooms | 1 | date | 1 | date | | 6739 | null | null | | btree | | | +-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 9 rows in set (0.01 sec)

i limit output columns in question doing:

show index rooms column_name = 'room_id' or column_name = 'date';

however individual columns may have own index, date column in case above. how can determine index exists on multiple columns belonging same key_name?

mysql indexing

No comments:

Post a Comment