Execution order of expressions in SELECT statement

我只是一个虾纸丫 提交于 2020-02-02 12:39:05

问题


I want to know if the execution order of expressions in SELECT statement always takes place from left to right.

SET @a := 0;

SELECT 
@a AS first,
@a := @a + 1 AS second,
@a := @a + 1 AS third,
@a := @a + 1 AS fourth,
@a := @a + 1 AS fifth,
@a := @a + 1 AS sixth;

Is it guaranteed that the above query will always generate the following output?

first second third fourth fifth sixth 
  0     1      2     3     4      5

回答1:


According to the MySQL manual:

However, the order of evaluation for expressions involving user variables is undefined

So the answer to your question, is no, the execution order is not guaranteed.




回答2:


Yes, by any means there is no configuration for execution order, so you always get output like this.



来源:https://stackoverflow.com/questions/38919532/execution-order-of-expressions-in-select-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!