Subject | Best index for BETWEEN? |
---|---|
Author | Milan Babuskov |
Post date | 2008-10-15T16:30:46Z |
Hi,
In an application I'm currently developing I have a lot of parametrized
queries like this:
SELECT * FROM table1 t WHERE :somevalue BETWEEN t.field1 AND t.field2;
Most of the time field1 and field2 are timestamps, but I also have
varchar and even integer columns. Of course, type of field1 and field2
is the same in all cases.
I wonder what kind of index would be most effective for this. Compound
index on (field1,field2)? or maybe separate index on both fields? Or
maybe just index on first field? Or maybe something like ASC index on
one field and DESC on another?
Values found in field1 and field2 are not unique, but are not far from
that either.
Thanks,
--
Milan Babuskov
http://www.flamerobin.org
http://www.guacosoft.com
In an application I'm currently developing I have a lot of parametrized
queries like this:
SELECT * FROM table1 t WHERE :somevalue BETWEEN t.field1 AND t.field2;
Most of the time field1 and field2 are timestamps, but I also have
varchar and even integer columns. Of course, type of field1 and field2
is the same in all cases.
I wonder what kind of index would be most effective for this. Compound
index on (field1,field2)? or maybe separate index on both fields? Or
maybe just index on first field? Or maybe something like ASC index on
one field and DESC on another?
Values found in field1 and field2 are not unique, but are not far from
that either.
Thanks,
--
Milan Babuskov
http://www.flamerobin.org
http://www.guacosoft.com