mysql and indexes with more than one column
Posted
by
clarkk
on Stack Overflow
See other posts from Stack Overflow
or by clarkk
Published on 2012-11-10T10:43:48Z
Indexed on
2012/11/10
11:00 UTC
Read the original article
Hit count: 228
mysql
|database-indexes
How to use indexes with more than one column
The original index has an index on block_id
, but is it necesarry when it's already in the unique index with two column?
Indexes with more than one column
(a,b,c)
- you can search for a, b and c
- you can search for a and b
- you can search for a
- you can not search for a and c
Does this apply to unique indexes too?
table
id
block_id
account_id
name
indexes origin
PRIMARY KEY (`id`)
UNIQUE KEY `block_id` (`block_id`,`account_id`)
KEY `block_id` (`block_id`),
KEY `account_id` (`account_id`),
indexes alternative
PRIMARY KEY (`id`)
UNIQUE KEY `block_id` (`block_id`,`account_id`)
KEY `account_id` (`account_id`),
© Stack Overflow or respective owner