Bug #79753 In SET stmt, different set operations are not executed sequentially
Submitted: 23 Dec 2015 8:47 Modified: 24 Dec 2015 15:20
Reporter: Su Dylan Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.7.8 OS:Any
Assigned to: CPU Architecture:Any

[23 Dec 2015 8:47] Su Dylan
Description:
Output:
=======
mysql> set @a=1, @b=@a;
Query OK, 0 rows affected (0.01 sec)

mysql> select @a, @b;
+------+------+
| @a   | @b   |
+------+------+
|    1 | NULL |
+------+------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc  |
+-----------+
1 row in set (0.00 sec)

Problem:
========
In this SET stmt, the set operations are not executed sequentially.

How to repeat:
set @a=1, @b=@a;
select @a, @b;

Suggested fix:
In this SET stmt, the set operations should be executed sequentially.
@b is expected to be 1.
[24 Dec 2015 12:59] MySQL Verification Team
Hi Su Dylan,

Thank you for the report.
Imho this is known behavior i.e order of evaluation for expressions involving user variables is undefined and hence never set and use a variable in same statement. Also, see http://dev.mysql.com/doc/refman/5.7/en/user-variables.html

Thanks,
Umesh
[24 Dec 2015 15:20] Su Dylan
Hi Umesh,

I also checked the manual you posted before I issued this problem.
In the manual, it says that "other than in SET statement", the behavior is undefined. However, the is in a SET statement, which is not clearly stated in the manual.

Quote ===
As a general rule, other than in SET statements, you should never assign a value to a user variable and read the value within the same statement. For example, to increment a variable, this is okay:
Quote ===