[MDEV-13418] Compatibility: The order of evaluation of SELECT..INTO assignments Created: 2017-08-01 Updated: 2018-04-10 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | OTHER |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | Alexander Barkov | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | Compatibility | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
This compatibility issue was originally reported by Jerome B. on the maria-developers list on 2017-07-31. This script returns 1 in MariaDB:
A similar script with sql_mode=ORACLE in 10.3 also returns 1:
A similar script returns 10 in Oracle:
Notice:
The SQL standars says in the section <select statement: single row>:
Although the Standard does not explicitly says so, it seems clear that the above rules assume that the result row is calculated BEFORE any assignment is done: Therefore, in the above SQL scrips, the fact that 1 is assigned to b1 must not affect the value of res. The expression cast(b1 as varchar(10)) must be evaluated using the original b1 value of 10. MariaDB's results seem to contradict the SQL standard. Note, the phrase The assignment of values... is in an implementation-dependent order should not confuse the reader: it only says that copying from Q to targets (e.g. b1 and res) is done in arbitrary order (it does not change the fact that Q itself is evaluated before any assignment is done). In any cases, at least when running with sql_mode=ORACLE, MariaDB should reproduce Oracle-style behavior and return 10 in the above script. |
| Comments |
| Comment by Alexander Barkov [ 2017-10-30 ] | ||||||||||||||||||||||||
|
We will create temporary variables for assignment targets and will do the following translation from:
to
Notice, SELECT..INTO is first done into temporary variables a_tmp and b_tmp, which then are copied to a and b. This guarantees than the values of a and b stay untouched during select list calculation. |