There is a table with the goods (item) and a table with the colors of the goods (item_color). Links "one product to multiple colors." Tables are large, item is 1.5 million lines, item_color is 2.5 million. Type is InnoDB.
On the page of the online store you need to display filters by color, size of goods. Total filters - 6 pieces. To do this, I use similar queries:
SELECT DISTINCT item_color.id_color FROM item_color JOIN item ON item.id = item_color.id_item AND item.enabled=1 AND item.id_category BETWEEN 10100000 AND 10199999 Server: 2 cores, 4GB of RAM. The request takes 6-8 seconds.
Item Table Indices:
PRIMARY KEY (`id`), KEY `c` (`id_category`), KEY `e` (`enabled`), KEY `ce` (`id_category`,`enabled`), KEY `iec` (`id`,`enabled`,`id_category`), KEY `cei` (`id_category`,`enabled`,`id`) Item_color table indexes:
PRIMARY KEY (`id`), KEY `ic` (`id_item`,`id_color`), KEY `ci` (`id_color`,`id_item`), KEY `i` (`id_item`) Explain:
Tell me, please, how to optimize the request? Maybe I chose the wrong approach to building filters?

e. Indexes with such selectivity only slow down the work. other indices are generally the same would not hurt to revise. for example, why do you need bothicandciin the second table. obviously enoughci. And by the way, what is youridfield in that table? In link tables, the own id field is not needed in 95% of cases. Hereciin this table is suitable for the role of the primary key - Mikecewith fields in reverse. But this is for this particular, very artificial request. - Mike