On Fri, Oct 1, 2010 at 2:34 PM, Joerg Bruehe <joerg.bru...@oracle.com> wrote:
> Hi!
>
>
> Hank wrote:
>> On Wed, Sep 29, 2010 at 8:33 AM, Patrice Olivier-Wilson
>> <b...@biz-comm.com> wrote:
>>> On 9/28/10 8:33 PM, Chris W wrote:
>>>
>>>> SELECT *
>>>> FROM announcements
>>>> WHERE announcements_expiredate > CURDATE()
>>>> AND announcements_postdate <= CURDATE()
>>>> ORDER BY announcements_expiredate ASC
>>
>> Or how about something like this:
>>
>> SELECT *
>> FROM announcements
>> WHERE  CURDATE() between announcements_postdate and announcements_expiredate
>> ORDER BY announcements_expiredate ASC
>
> The syntax is correct, but I don't think this statement will be
> optimized as well as the other proposal:
> BETWEEN is intended for "column BETWEEN const1 AND const2",
> whereas your statement is "const BETWEEN column1 AND column2".
>

But that only really matters if there are indexes on the column1 and
column2 fields.

And for the optimizer, wouldn't it make sense to map BETWEEN into two
comparison statements "(column>const1 and column<=const2)"  or
"(const>column1 and const<=column2)" where both scenarios the
optimizer may be able to use indexes on the fields?  It's exactly the
same as the other proposal:

"CURDATE() > announcements_postdate and CURDATE()<=
announcements_expiredate" which still is using two different fields
for the comparisons... so wouldn't both scenarios end up in the exact
same place?

-Hank

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=arch...@jab.org

Reply via email to