什么是适合这个查询的索引。如何在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秒 –