MySQL Forums
Forum List  »  Performance

Index with two date fields using comparison operators
Posted by: Istvan Zakar
Date: December 05, 2010 05:38PM

Hi,

I have a table for storing historical data with two date fields (valid_from, valid_till). I have indexed this two fields with a B-Tree index. If I run a query like this:

select * from subreg where
valid_from = '2011-01-22' and
valid_till = '2011-01-25';

it works fine. If check the explain I can see, that the key length is 6.

If I change the query slightly:

select * from subreg where
valid_from = '2011-01-22' and
valid_till > '2011-01-23';

it's still okay.

But this query takes long time to execute:

select * from subreg where
valid_from < '2011-01-23' and
valid_till > '2011-01-23';

I suppose the index is used only for the first column in this case (at least the length of the key is only 3 in this case). Is there anything I can do to increase the performance of this query?

Options: ReplyQuote


Subject
Views
Written By
Posted
Index with two date fields using comparison operators
5787
December 05, 2010 05:38PM


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.