Saturday, February 25, 2012

Repost: Between vs >= and <=

Which is better to use? I heard that <= and >= are better because it allows
SQL Server to retain the query plan in cache, or something like that. This i
s
in reference to a date comparison.
SELECT * FROM <table> WHERE <date> between <start_date> and <end_date>
SELECT * FROM <table> WHERE <date> >= <start_date> and <date> <= <end_date>
Performance wise they use they same indexes and are not different. But is
there an internal reason to use one over the other like plan reuse, or
caching?
Basically, I am looking for any information on caching or query plan reuse i
n
reference to using between or >+ and <=. Also, I am
looking for information pertaining to the fact that SQL Server converts a
Between to a >= and <= pair, and if you resubmit the same between statement,
it converts it again and regenerates it plan. If you use the >= and <=
instead, it will reuse the existing plan to re-execute the statement. Is thi
s
true? and if so, is there documentation on it?On Fri, 7 Oct 2005 14:52:02 -0700, John Barr wrote:

>Which is better to use? I heard that <= and >= are better because it allows
>SQL Server to retain the query plan in cache, or something like that. This
is
>in reference to a date comparison.
>SELECT * FROM <table> WHERE <date> between <start_date> and <end_date>
>SELECT * FROM <table> WHERE <date> >= <start_date> and <date> <= <end_date>
>Performance wise they use they same indexes and are not different. But is
>there an internal reason to use one over the other like plan reuse, or
>caching?
>Basically, I am looking for any information on caching or query plan reuse
in
>reference to using between or >+ and <=. Also, I am
>looking for information pertaining to the fact that SQL Server converts a
>Between to a >= and <= pair, and if you resubmit the same between statement
,
>it converts it again and regenerates it plan. If you use the >= and <=
>instead, it will reuse the existing plan to re-execute the statement. Is th
is
>true? and if so, is there documentation on it?
Hi John,
See my reply to your original question.
Also, please don't repost the same question three times within hours
after each other. Reposting if you still have no answer after two or
three days is okay; reposting more often is showing impatience.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

No comments:

Post a Comment