MySQL Forums
Forum List  »  Stored Procedures

Re: When is an INSERT DETERMINISTIC?
Posted by: Jon Stephens
Date: August 07, 2017 09:47PM

"[Input] parameter" and "[non]deterministic" are not at all unique to MySQL.

Generally speaking, a function or routine is deterministic if it always produces the same output for the same input. The classic example of a routine that isn't deterministic is one that depends on one or more time and date functions (e.g. NOW()), or on the RAND() function.

As for when to use the DETERMINISTIC keyword, I think the Manual is pretty clear: If you don't use it, the optimiser does not attempt to perform some optimisations that it would otherwise; if you do use it, be sure that your routine is in fact deterministic, because using DETERMINISTIC for a nondeterministic routine causes the optimiser to make bad choices that can have a negative impact on performance.

Your routine does not actually return a value, but it does perform an update; in this case, you must consider the values inserted, one of which depends on NOW(). And the Manual is quite clear that "[a] routine that contains the NOW() function (or its synonyms) or RAND() is nondeterministic," and so contains the answer to that question.

cheers,

Jon Stephens
MySQL Documentation Team @ Oracle
Stockholm, Sweden

MySQL Dev Zone
MySQL Server Documentation
Oracle

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: When is an INSERT DETERMINISTIC?
19
August 07, 2017 09:47PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.