I have a mysql database with 7 million rows hosted on an aws rds micro instance.
I am doing this sort of queries:
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
And thus I created an index like that:
| 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 | | |
Everything is fine so far. The problems arrise when I try to add ORDER BY published DESC (30"+ for one query).
Is there anyway to have an efficient ORDER BY published DESC knowing that I also need published to be in a WHERE clause?