tags:

views:

31

answers:

1

I'm using explain to test these queries. The col type is DATE

this uses index:

explain SELECT events.* FROM events WHERE events.date = '2010-06-11' 

this doesnt

explain SELECT events.* FROM events WHERE events.date >= '2010-06-11' 

index as follows (phpmyadmin)

Action  Keyname Type    Unique  Packed  Field   Cardinality Collation   Null    Comment
Edit    Drop    PRIMARY BTREE   Yes No  event_id    18  A       
Edit    Drop    date    BTREE   No  No  date    0   A       

i notice cardinality is 0, though there are some rows with the same date..

+1  A: 

If MySQL doesn't use the index, it has seen your query, and estimated that a table scan would probably be faster then using the index (in terms of IO / disk operations required probably). You can use a FORCE INDEX and check whether this query will actually be faster using the index or not.

SELECT events.* FROM events
FORCE INDEX (date)
WHERE events.date >= '2010-06-11';
Wrikken
yes i think you're right, as its a test table with only 20rows (will be tens of thousands). how do i implement FORCE (to test)? this doesnt work: explain SELECT events.* FROM events WHERE events.date >= '2010-06-11' FORCE INDEX(date)
Haroldo
Edit answer with example.
Wrikken