I have a query like this for finding the max/min values of primary key, which satisfy the where condition.
SELECT id
FROM mytable
WHERE date_created >= '2015-01-27 00:00:00'
AND date_created <= '2015-01-27 23:59:59'
LIMIT 1
and EXPLAIN
+----+-------------+------------------------+------+---------------+------+---------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------------------+------+---------------+------+---------+------+----------+-------------+
| 1 | SIMPLE | mytable | ALL | NULL | NULL | NULL | NULL | 44726469 | Using where |
+----+-------------+------------------------+------+---------------+------+---------+------+----------+-------------+
and for maximum,
SELECT id
FROM mytable
WHERE date_created >= '2015-01-27 00:00:00'
AND date_created <= '2015-01-27 23:59:59'
ORDER BY id DESC
LIMIT 1
and EXPLAIN will give
+----+-------------+------------------------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------------------+-------+---------------+---------+---------+------+------+-------------+
| 1 | SIMPLE | mytable | index | NULL | PRIMARY | 4 | NULL | 1 | Using where |
+----+-------------+------------------------+-------+---------------+---------+---------+------+------+-------------+
As I am running this queries against a very large table, the query is getting time out. Is there any alternative method for finding these values?
id is the primary key and I already created index for date_created. But doesn't have any effect on the performance.