DROP TABLE IF EXISTS ranges;
CREATE TABLE ranges (
id int PRIMARY KEY,
start timestamp DEFAULT '2016-04-21 00:00:00',
end timestamp DEFAULT '2016-04-22 00:00:00',
UNIQUE KEY range_key(start, end)
);
INSERT INTO ranges VALUES (1, "2012-10-25 16:18:29", "2038-01-18 15:14:07");
INSERT INTO ranges VALUES (2, "1970-01-01 12:00:00", "2012-10-05 16:18:29");
INSERT INTO ranges VALUES (3, "2038-01-18 15:14:07", "1970-01-01 12:00:00");
INSERT INTO ranges VALUES (4, "1970-01-01 12:00:00", "2038-01-18 15:14:07");
SELECT * FROM ranges FORCE INDEX(range_key)
ORDER BY start, end;
id	start	end
2	1970-01-01 12:00:00	2012-10-05 16:18:29
4	1970-01-01 12:00:00	2038-01-18 15:14:07
1	2012-10-25 16:18:29	2038-01-18 15:14:07
3	2038-01-18 15:14:07	1970-01-01 12:00:00
DROP TABLE ranges;
