I created test()
function with the proper characteristic DETERMINISTIC
as shown below because it always produces the same result 3
according to the doc:
CREATE FUNCTION test() RETURNS INT
DETERMINISTIC -- Here
RETURN 3;
And, I also created test()
function with the improper characteristics NOT DETERMINISTIC
, NO SQL
, READS SQL DATA
and MODIFIES SQL DATA
as shown below:
CREATE FUNCTION test() RETURNS INT
NOT DETERMINISTIC -- Here
NO SQL -- Here
READS SQL DATA -- Here
MODIFIES SQL DATA -- Here
RETURN 3;
Even if:
NO SQL
indicates that the routine contains no SQL statements.READS SQL DATA
indicates that the routine contains statements that read data (for example,SELECT
), but not statements that write data.MODIFIES SQL DATA
indicates that the routine contains statements that may write data (for example,INSERT
orDELETE
).
So, what is the pros(advantages) and cons(disadvantages) to use proper and improper characteristics for a function in MySQL?
The only implication that I know of is that functions marked
DETERMINISTIC
are allowed to be used freely in statements whilebinlog_format=STATEMENT
is in effect. Read https://dev.mysql.com/doc/refman/8.0/en/stored-programs-logging.html for details.The other annotations are advisory only. They have no effect as far as MySQL is concerned, so you can use them however you want.