什麼是適合這個查詢的索引。如何在Extra中優化MYSQL: - 使用where;使用臨時;使用filesort
我試圖給定索引的不同組合對於該查詢,但它仍然使用tempory使用,使用文件排序等
總表中的數據 - 7,60,346
product
=「連衣裙」 - 總行數= 122 554
CREATE TABLE IF NOT EXISTS `product_data` (
`table_id` int(11) NOT NULL AUTO_INCREMENT,
`id` int(11) NOT NULL,
`price` int(11) NOT NULL,
`store` varchar(255) NOT NULL,
`brand` varchar(255) DEFAULT NULL,
`product` varchar(255) NOT NULL,
`model` varchar(255) NOT NULL,
`size` varchar(50) NOT NULL,
`discount` varchar(255) NOT NULL,
`gender_id` int(11) NOT NULL,
`availability` int(11) NOT NULL,
PRIMARY KEY (`table_id`),
UNIQUE KEY `table_id` (`table_id`),
KEY `id` (`id`),
KEY `discount` (`discount`),
KEY `step_one` (`product`,`availability`),
KEY `step_two` (`product`,`availability`,`brand`,`store`),
KEY `step_three` (`product`,`availability`,`brand`,`store`,`id`),
KEY `step_four` (`brand`,`store`),
KEY `step_five` (`brand`,`store`,`id`)
) ENGINE=InnoDB ;
查詢:
SELECT id ,store,brand FROM `product_data` WHERE product='dresses' and
availability='1' group by brand,store order by store limit 10;
excu..time: - (10總計,查詢花費1.0941秒)
說明計劃:
possible_keys: - step_one,step_two,step_three,step_four,step_five
key: - step_two
ref: - 常量,常量
行: -
額外: - 使用其中;使用臨時;使用文件排序
我想這些指標
Key
step_one(product
,availability
)
Key
step_two(product
,availability
,brand
,store
)
Key
step_three(product
, availability
,brand
,store
,id
)
Key
step_four(brand
,store
)
Key
step_five(brand
,store
,id
)
在你的問題中提供'SHOW CREATE TABLE product_data'輸出。 –
@kuldeepupadhyay請給我們每個指標組合時的結果,你mentionned –
@小寶答:是的,先生我的查詢挑選他們查詢花費1.0941秒 –