[MDEV-14306] SELECT With Variable Assignation := and HAVING: Gives wrong results - Error Shall be Raised Created: 2017-11-07 Updated: 2017-12-16 Resolved: 2017-12-01 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Documentation |
| Affects Version/s: | 10.2.8, 10.2.10 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Juan Telleria | Assignee: | Unassigned |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Windows |
||
| Description |
|
When using Variable Assignation in a SELECT Query and using a HAVING (Filtering After Table Materialization) Wrong Results are returned:
When Using "HAVING `LifeDays_UT_Year` IS NOT NULL" Calculations are not done correctly, and when not using such clause, yes. I knew that Variable Assignation := did not worked properly when used with GROUP BY, but did not know that also did not worked with HAVING. My suggestion on how to avoid Incorrect Calculations: Thank you, |
| Comments |
| Comment by Alice Sherepa [ 2017-11-27 ] | |
|
Setting a variable in one place (such as the SELECT list) and reading it in another (such as the HAVING clause) might give wrong results, it is unsafe to read a user-defined variable and set its value in the same statement (unless the command is SET), because the order of these actions is undefined. (https://mariadb.com/kb/en/library/user-defined-variables/)
The reference to b in the HAVING clause refers to an alias for an expression in the select list that uses @aa. This does not work as expected: @aa contains the value of id from the previous selected row, not from the current row. | |
| Comment by Juan Telleria [ 2017-12-01 ] | |
|
I see... a workaround would be that you could use column aliases within the selection part of a SELECT statement itself, avoiding to have to overwrite all the column content into another for it's use. Simply for the Execution Order it shall be checked which are the dependant columns, and stablish an execution order. |