在Extra中优化MYSQL:-Using where;使用临时;使用filesort

时间:2017-09-29 12:01:47

标签: mysql sql database-administration query-performance

什么是正确的索引?我重写查询和表格以了解击球手。

我试过为这个查询提供了不同的索引组合,但它仍在使用tempory,使用filesort等。

      CREATE TABLE IF NOT EXISTS `test_data` 
     (`table_id` int(11) NOT NULL AUTO_INCREMENT, 
    `id` int(11) NOT NULL,
    `store` varchar(255) NOT  NULL,  
    `brand` varchar(255) DEFAULT NULL,  
     `product` 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 `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 FROM `test_data` WHERE product='dresses' and availability=1
 group by brand order by store limit 10;

检查实时数据库http://sqlfiddle.com/#!9/5280b1/1

0 个答案:

没有答案
相关问题