Mysql 多列索引和排序方式

Mysql 多列索引和排序方式,mysql,indexing,Mysql,Indexing,我有一个拥有700万行的mysql数据库,托管在一个aws rds微实例上 我正在做这类查询: SELECT `id`, `address`, `property_type`, `rooms`, `published`, `size`, `net_rent`, `gross_rent`, `purchase_price`, `original_id` FROM (`properties`) WHERE `postcode` IN ('1000', '1001', '1002',

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

我正在做这类查询:

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
到目前为止一切都很好。当我试图通过发布的DESC(一个查询30“+)添加订单时,问题就出现了


知道我也需要在WHERE子句中发布,是否仍需要按已发布描述进行有效的排序?

我会尝试将“已发布”放在索引的第一位(使用ORDER BY)作为查询的前缀使用EXPLAIN,运行它,并将结果添加到您的问题中。我猜它不会发现您的索引可用于排序和进行完整排序,但这是一个猜测。
| 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      |         |               |