0

我有一个 mysql 数据库,在 aws rds 微型实例上托管了 700 万行。

我正在做这种查询:

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"+)时,问题就出现了。

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

4

1 回答 1

1

我会尝试将“已发布”放在索引中

于 2013-01-08T23:50:23.137 回答