MySQL Forums
Forum List  »  Newbie

help with optimize a query plzzzz.....
Posted by: henri_indon
Date: August 17, 2005 04:14AM

for example:

create table test(
id int(10) unsigned auto_increment,
checkIn datetime default '0000-00-00 00:00:00',
primary key (id)
);

and i want to optimize the following query.

explain select * from visits where (checkIn <= '2005-08-18 23:59:59') and (checkIn >= '2005-08-18 00:00:00');

and it gives me:

+--------+------+---------------+------+---------+------+------+-------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------+------+---------------+------+---------+------+------+-------------+
| visits | ALL | checkIn | NULL | NULL | NULL | 30 | Using where |
+--------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

i add index on checkIn, but still somehow it give the same result.
but when i change the query to:
explain select * from visits where (checkIn <= '2005-08-17 23:59:59') and (checkIn >= '2005-08-17 00:00:00'); (checkIn date is different)

it gives me the "range" type.
the main difference between the 2005-08-18 records and 2005-08-17 records is that the 18th has about 10 rows in the database while 17th only have about 3 records.

so can somebody help me with this plz????

Options: ReplyQuote


Subject
Written By
Posted
help with optimize a query plzzzz.....
August 17, 2005 04:14AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.