CREATE FUNCTION error “This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA”

前端 未结 7 853
走了就别回头了
走了就别回头了 2021-01-01 17:17

Our database has a function to generate an order number. It reads a value from a Settings table, increments it, then returns the new value. For example:

CREA         


        
7条回答
  •  旧巷少年郎
    2021-01-01 17:41

    As per my understating it cause problem when data recovery or replication

    Ref: http://dev.mysql.com/doc/refman/5.0/en/stored-programs-logging.html

    MySQL 5.0.6: Statements that create stored routines and CALL statements are logged. Stored function invocations are logged when they occur in statements that update data (because those statements are logged).

    However, function invocations are not logged when they occur in statements such as SELECT that do not change data, even if a data change occurs within a function itself; this can cause problems.

    Under some circumstances, functions and procedures can have different effects if executed at different times or on different (master and slave) machines, and thus can be unsafe for data recovery or replication.

    E.g.

    CREATE FUNCTION myfunc () RETURNS INT DETERMINISTIC
    BEGIN
      INSERT INTO t (i) VALUES(1);
      RETURN 0;
    END;
    
    SELECT myfunc();
    

    If a stored function is invoked within a statement such as SELECT that does not modify data, execution of the function is not written to the binary log, even if the function itself modifies data. This logging behavior has the potential to cause problems. Suppose that a function myfunc() is defined as above.

提交回复
热议问题