mysql - I've indexed a combined column, should I index separate column too? -
i have table this
create table `tbl` ( `id` int(10) unsigned not null, `pid` int(10) unsigned not null, `cid` int(10) unsigned not null, `name` int(11) default null, `desc` varchar(500), `deleted` tinyint(1) unsigned not null default 0, `createdat` datetime default null, primary key `pid_cid` (`pid`,`cid`) ) engine=innodb where clause of select queries those:
where pid=pid [and deleted = 1]; cid=cid [and deleted = 1]; pid=pid , cid=cid [and deleted = 1]; - should index
pid,cidseparately? - should index
deleted?
the optimal set of indexes be:
pid, deletedcid, deletedpid, cid, deleted
whether need 3 depends on data. how many different deleted values there each pid/cid. first 2 may sufficient.
indexing deleted not useful. presumably, takes on 2 values, not candidate index.
Comments
Post a Comment