DROP TABLE IF EXISTS ranges;
CREATE TABLE ranges (
id INT PRIMARY KEY,
start DATE,
end DATE,
UNIQUE KEY range_key(start, end)
);
INSERT INTO ranges VALUES (1, "2012-10-25", "9999-12-31");
INSERT INTO ranges VALUES (2, "1000-01-01", "2012-10-05");
INSERT INTO ranges VALUES (3, "9999-12-31", "1000-01-01");
INSERT INTO ranges VALUES (4, "1000-01-01", "9999-12-31");
SELECT * FROM ranges FORCE INDEX(range_key)
ORDER BY start DESC, end DESC;
id	start	end
3	9999-12-31	1000-01-01
1	2012-10-25	9999-12-31
4	1000-01-01	9999-12-31
2	1000-01-01	2012-10-05
DROP TABLE ranges;
