MySQL Forums :: Performance :: Index with two date fields using comparison operators


Advanced Search

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 3746 Istvan Zakar 12/05/2010 05:38PM
Re: Index with two date fields using comparison operators 1000 Rick James 12/06/2010 08:33PM
Re: Index with two date fields using comparison operators 777 Thomas Wiedmann 12/08/2010 06:04AM
Re: Index with two date fields using comparison operators 925 Stevie Lancer 12/08/2010 06:08AM
Re: Index with two date fields using comparison operators 724 Thomas Wiedmann 12/08/2010 06:28AM
Re: Index with two date fields using comparison operators 1031 Thomas Wiedmann 12/08/2010 09:09AM
Re: Index with two date fields using comparison operators 1052 Rick James 12/08/2010 09:54AM


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.