I decided to start optimizing queries on the online store, because there are already about 15,000 items in the product table, and the page load has become noticeably dimmed, not critical, but not very pleasant either. Here I want to consult with you, who, what will advise.
There are tables: 1 - t1 - collections 2 - t3 - goods (tied to collection by collection_id) 3 - t3 - characteristics of goods (tied to goods by product_id)
We display collections in the catalog, based on sorting by the characteristics of the goods, the query is cumbersome:
SELECT DISTINCT `t1`.`title`, `t1`.`id`, `t1`.`imgs`, `t1`.`price`, `t1`.`code_col`, `t1`.`brand_id`, count(*) as cnt FROM `t1` INNER JOIN `t2` ON `t1`.`id` = `t2`.`collection_id` INNER JOIN `t3` ON `t2`.`id` = `t3`.`product_id` WHERE `t1`.`section_id` = 1 + куча параметров из сортировки по разным таблицам GROUP BY `t2`.`id` HAVING cnt = 1 (кол-во разных параметров сортировки) ORDER BY `t1`.`price` * (1 - `sale`), `t1`.`id` LIMIT 0, 30 (и т.д. постраничная навигация по 30 штук на странице) Sometimes there is another INNER JOIN with the sizes of the goods (a separate table of sizes, connects with the goods by product_id)
Is it possible to somehow ease this construction?
.price` * (1 -sale) - xoma