Function call optimization MySQL functions are marked internally as deterministic or nondeterministic. If a function given fixed values for its arguments can return different results for different calls, it is undefined. Examples of nondeterministic functions: If a function is marked non-deterministic, references to the function in a MySQL also determines when to evaluate a function based on the type of its arguments (whether the arguments are table columns or constant values). Whenever a table column changes value, the deterministic function taking the table column as an argument must be evaluated. Non-deterministic functions may affect query performance. For example, some optimizations might not be available, or more locking might be required. The following discussion uses Assume a table t has the following definition: CREATE TABLE t (id INT NOT NULL PRIMARY KEY, col_a VARCHAR(100)); Consider the following two queries: SELECT * FROM t WHERE id = POW(1,2); SELECT * FROM t WHERE id = FLOOR(1 + RAND() * 49); Both queries appear to use the primary key lookup due to the equality comparison with the primary key, but this only applies to the first query:
The effects of nondeterminism are not limited to UPDATE t SET col_a = some_expr WHERE id = FLOOR(1 + RAND() * 49); Presumably the intention is to update at most one row where the primary key matches the expression. However, it may update zero, one, or more rows, depending on the The behavior just described has implications for performance and replication:
The difficulty arises from the fact that
SET @keyval = FLOOR(1 + RAND() * 49); UPDATE t SET col_a = some_expr WHERE id = @keyval;
SET optimizer_switch = 'derived_merge=off'; UPDATE t, (SELECT @keyval := FLOOR(1 + RAND() * 49)) AS dt SET col_a = some_expr WHERE id = @keyval; As mentioned previously, nondeterministic expressions in the SELECT * FROM t WHERE partial_key=5 AND some_column=RAND(); If the optimizer can use The above is a detailed explanation of MySQL function call optimization. For more information about MySQL function call optimization, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to ensure that every page of WeChat Mini Program is logged in
>>: Definition and function of zoom:1 attribute in CSS
This may be an issue that is easily overlooked. F...
Table of contents 1. Pull the image 2. Create a l...
Table of contents 1. Basic grammar 2. Filter by c...
Preface Recently I started using robot framework ...
Table of contents 1. Template 2. Generics 3. Gene...
In the previous article, I introduced how to solv...
The table caption can be placed above or below th...
Install MySQL database a) Download the MySQL sour...
The effect is as follows: The code is as follows ...
1. Create a centos7.6 system and optimize the sys...
I don’t know why, but UI likes to design honeycom...
Translated from Docker official documentation, or...
Table of contents 1. Startup management of source...
Docker installs mysql docker search mysql Search ...
When a request is sent to your server to display ...