Mysql function call

前端 未结 4 883
伪装坚强ぢ
伪装坚强ぢ 2021-02-10 04:34

If I call a function several time then will it execute every time or just execute once and the value will be used then after several time? Example:

 select my_fu         


        
4条回答
  •  盖世英雄少女心
    2021-02-10 05:12

    It is possible to have some optimization if you declare your function as DETERMINISTIC. But it really should be deterministic:

    A routine is considered “deterministic” if it always produces the same result for the same input parameters, and “not deterministic” otherwise. If neither DETERMINISTIC nor NOT DETERMINISTIC is given in the routine definition, the default is NOT DETERMINISTIC. To declare that a function is deterministic, you must specify DETERMINISTIC explicitly.

    Assessment of the nature of a routine is based on the “honesty” of the creator: MySQL does not check that a routine declared DETERMINISTIC is free of statements that produce nondeterministic results. However, misdeclaring a routine might affect results or affect performance. Declaring a nondeterministic routine as DETERMINISTIC might lead to unexpected results by causing the optimizer to make incorrect execution plan choices. Declaring a deterministic routine as NONDETERMINISTIC might diminish performance by causing available optimizations not to be used. Prior to MySQL 5.0.44, the DETERMINISTIC characteristic is accepted, but not used by the optimizer.

提交回复
热议问题