Bug #14016 | ORDER BY DATE_FORMAT() and uppercase/lowercase DATE_FORMAT argument pairs | ||
---|---|---|---|
Submitted: | 13 Oct 2005 19:28 | Modified: | 19 Jan 2006 22:28 |
Reporter: | Geoff Traugott | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 4.1.14-standard/5.0 BK source | OS: | Linux (Linux (x86, glibc-2.3)) |
Assigned to: | Evgeny Potemkin | CPU Architecture: | Any |
[13 Oct 2005 19:28]
Geoff Traugott
[13 Oct 2005 22:45]
MySQL Verification Team
Thank you for the bug report. mysql> select version(); +------------------+ | version() | +------------------+ | 4.1.16-debug-log | +------------------+ 1 row in set (0.00 sec) mysql> select date_format(dtmDate, "%m") as Date1, date_format(dtmDate, "%M") as -> Date2 from tblDateSort order by date_format(dtmDate, "%M"); +-------+-----------+ | Date1 | Date2 | +-------+-----------+ | 01 | January | | 02 | February | | 03 | March | | 04 | April | | 05 | May | | 06 | June | | 07 | July | | 08 | August | | 09 | September | | 10 | October | | 11 | November | | 12 | December | +-------+-----------+ 12 rows in set (0.00 sec) ----------------------------------------------------------------------------------- mysql> select version(); +-----------------+ | version() | +-----------------+ | 5.0.15-rc-debug | +-----------------+ 1 row in set (0.00 sec) mysql> select date_format(dtmDate, "%m") as Date1, date_format(dtmDate, "%M") as -> Date2 from tblDateSort order by date_format(dtmDate, "%M"); +-------+-----------+ | Date1 | Date2 | +-------+-----------+ | 01 | January | | 02 | February | | 03 | March | | 04 | April | | 05 | May | | 06 | June | | 07 | July | | 08 | August | | 09 | September | | 10 | October | | 11 | November | | 12 | December | +-------+-----------+ 12 rows in set (0.00 sec) ----------------------------------------------------------------------------------- mysql> select version(); +------------------+ | version() | +------------------+ | 4.0.26-debug-log | +------------------+ 1 row in set (0.00 sec) mysql> select date_format(dtmDate, "%m") as Date1, date_format(dtmDate, "%M") as -> Date2 from tblDateSort order by date_format(dtmDate, "%M"); +-------+-----------+ | Date1 | Date2 | +-------+-----------+ | 04 | April | | 08 | August | | 12 | December | | 02 | February | | 01 | January | | 07 | July | | 06 | June | | 03 | March | | 05 | May | | 11 | November | | 10 | October | | 09 | September | +-------+-----------+ 12 rows in set (0.00 sec)
[25 Oct 2005 16:38]
Evgeny Potemkin
By default constant strings in second parameter of date_time() have case insensitive collation. Because of this expressions date_format(f,'%m') and date_format(f,'%M') wrongly becomes equal, which results in choosing wrong column to sort by. Fixed in 4.1.16, cset 1.2462.2.1
[28 Oct 2005 14:08]
Evgeny Potemkin
Fixed in 5.0.16
[19 Jan 2006 22:28]
Mike Hillyer
Added to 4.1.16 and 5.0.16 changelogs: <listitem> <para> When the <function>DATE_FORMAT()</function> function appeared in both the <literal>SELECT</literal> and <literal>ORDER BY</literal> clauses of a query but with arguments that differ by case (i.e. %m and %M), incorrect sorting may have occurred. (Bug #14016) </para> </listitem>