Bug #112569 | Deprecating variables within expressions - re-using calculations within SELECT | ||
---|---|---|---|
Submitted: | 28 Sep 2023 20:34 | Modified: | 29 Sep 2023 13:25 |
Reporter: | Nuno P | Email Updates: | |
Status: | Unsupported | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | Other (Docker) |
Assigned to: | CPU Architecture: | x86 |
[28 Sep 2023 20:34]
Nuno P
[29 Sep 2023 11:22]
MySQL Verification Team
Hi Mr. P, Thank you for your bug report. However, we do not have good news for you. Deprecating user variables remains strictly our policy , but for a very , very good reason. The reasoning for the decision is that the order of evaluation for expressions involving user variables is undefined. For example, there is no guarantee that SELECT @a, @a:=@a+1 evaluates @a first and then performs the assignment. Simply, SQL Standard does not require that fields in the SELECT list are evaluated in the order in which they are written. If that would be required, many queries would have executed slower. You have to use: SELECT .... INTO @a ...; and then in the next command SET @a := @a + 1; Unsupported.
[29 Sep 2023 13:25]
Nuno P
Thank you very much. I understand the reasonings. Looks like I'll have to go ahead and wrap this into subqueries, to reuse the calculations in the wrapping query. I appreciate your reply.
[29 Sep 2023 13:26]
MySQL Verification Team
Hi, You are truly welcome.