Thread: Which is faster: BETWEEN or 2 WHERE statements?

Which is faster: BETWEEN or 2 WHERE statements?

From
Chuck Roberts
Date:

Psql 8.4

 

Which will help the query run faster on my version of Psql;

 

1) WHERE (mydate >= '2015-01-01') AND (mydate<='2015-01-31')

 

2) WHERE (mydate BETWEEN '2015-01-01' AND '2015-01-31')

 

I'm just curious.  We have 500,000+ records to go through on this one table, and query involves 2 tables. The date field 'mydate' is not indexed.

 

Thank you!

 

Re: Which is faster: BETWEEN or 2 WHERE statements?

From
Thom Brown
Date:
On 17 February 2015 at 13:04, Chuck Roberts <croberts@gilsongraphics.com> wrote:

Psql 8.4

 

Which will help the query run faster on my version of Psql;

 

1) WHERE (mydate >= '2015-01-01') AND (mydate<='2015-01-31')

 

2) WHERE (mydate BETWEEN '2015-01-01' AND '2015-01-31')

 

I'm just curious.  We have 500,000+ records to go through on this one table, and query involves 2 tables. The date field 'mydate' is not indexed.


The planner will convert the 2nd clause to be the same as the 1st, so there should be no difference in the resulting plans.

Run EXPLAIN <query> and see what query plan you get for each.
 
Regards

Thom