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]; 
  1. should index pid , cid separately?
  2. should index deleted?

the optimal set of indexes be:

  • pid, deleted
  • cid, deleted
  • pid, 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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -