Bug #8500 User Variable not working with Group By

Submitted: 14 Feb 2005 15:15 Modified: 14 Feb 2005 19:31
Reporter: Ingo Welling Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:3.23.58 OS:Linux (Fedora Core 2)
Assigned to: CPU Architecture:Any

[14 Feb 2005 15:15] Ingo Welling
Description:
When you do the query (see in 'How to repeat') in Version 3.23.56 it produces the following output, which is what I want:
+-----------------------------+------------+
| @blub := @blub + sum( `b` ) | sum( `b` ) |
+-----------------------------+------------+
|                          56 |          1 |
|                          58 |          2 |
|                          61 |          3 |
|                          65 |          4 |
+-----------------------------+------------+

in Version 3.23.58 it produces:

+-----------------------------+------------+
| @blub := @blub + sum( `b` ) | sum( `b` ) |
+-----------------------------+------------+
|                           1 |          1 |
|                           3 |          2 |
|                           6 |          3 |
|                          10 |          4 |
+-----------------------------+------------+

in Version 4.1.9 it's even different, it produces:

+-----------------------------+------------+
| @blub := @blub + sum( `b` ) | sum( `b` ) |
+-----------------------------+------------+
|                          56 |          1 |
|                          57 |          2 |
|                          58 |          3 |
|                          59 |          4 |
+-----------------------------+------------+

How to repeat:
CREATE TABLE `blah` ( `a` int(11), `b` int(11) ) TYPE=MyISAM;

INSERT INTO `blah` VALUES ( 1, 1 );
INSERT INTO `blah` VALUES ( 2, 2 );
INSERT INTO `blah` VALUES ( 3, 3 );
INSERT INTO `blah` VALUES ( 4, 4 );

SET @blub := 55; /* this is somehow ignored in 3.23.58 */

SELECT @blub := @blub + sum( `b` ) , sum( `b` )
FROM `blah`
GROUP BY `a`;

Suggested fix:
The Output in Verion 3.23.56 is what I want and in my eyes it's correct. It is also what all versions would show if you leave out SUM and GROUP BY in the SELECT statement.
[14 Feb 2005 17:40] MySQL Verification Team
Hi,

Thank you for the report, but 3.23 is retired and only critical bugs are fixed in this series.
Please, upgrade MySQL server to the recent stable version.
[14 Feb 2005 19:31] Sergei Golubchik
See http://dev.mysql.com/doc/mysql/en/variables.html

In particular, note the line "The general rule is to never assign and use the same variable in the same statement."
[15 Feb 2005 12:24] Ingo Welling
In my eyes this is a critical bug. As it has been working in 3.23 and now it's silently delivering differrent results. Which leads to wrong relsults without notice.

I've read the man-page you mentioned before, but it's not very clear as in the first example on the page you do a similar thing:

mysql> SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;

Is there a way to make my exaple work on 4.1.9?  (all I want to do is to accumulate results with a start value)

Will it be supported (in future) if I leave out group by and sum?

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.051 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.