2013-01-08 40 views
0

我有一个mysql数据库,700万行托管在aws rds微型实例上。多列索引和ORDER BY

我做这样的查询:

SELECT 
    `id`, `address`, `property_type`, `rooms`, 
    `published`, `size`, `net_rent`, `gross_rent`, 
    `purchase_price`, `original_id` 
FROM (`properties`) 
WHERE 
    `postcode` IN ('1000', '1001', '1002', '1003', 
       '1004', '1005', '1006', '1007', 
       '1010', '1011', '1012', '1014', 
       '1015', '1017', '1018', '1019') 
    AND `published` < '2013-01-09' 
    AND `property_type` IN ('Apartment', 'Apartment with terrace', 
          'Attic', 'Attic flat/penthouse', 
          'Loft', 'Maisonette', 'Studio') 
    AND `sale_or_rent` = 'rent' 
LIMIT 50 

就这样我创建这样一个索引:

| properties |   1 | listing  |   1 | postcode  | A   |  25091 |  NULL | NULL | YES | BTREE  |   |    | 
| properties |   1 | listing  |   2 | published  | A   |  2333545 |  NULL | NULL | YES | BTREE  |   |    | 
| properties |   1 | listing  |   3 | property_type | A   |  3500318 |  NULL | NULL | YES | BTREE  |   |    | 
| properties |   1 | listing  |   4 | sale_or_rent | A   |  3500318 |  NULL | NULL | YES | BTREE  |   |    | 

一切都好为止。当我尝试添加ORDER BY发表DESC(30" +一个查询)的问题arrise。

反正有一个有效的ORDER BY发表DESC知道我还需要公布是在WHERE子句中?

+0

前缀查询(由顺序)与讲解,并运行它,结果添加到您的问题。我想是不是找你的索引可用于TEH按顺序排序,但这是一个猜测。 –

回答

1

我会尝试把“发布”首次在索引

+0

它确实加快了速度,谢谢。 –