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 article shares the installation and activati...
In the interview, you should have experienced the...
1. Open port 2375 Edit docker.service vim /lib/sy...
1. Overlay Overview Overlay means covering, as th...
This article uses an example to illustrate the co...
What is a selector? The role of the selector is t...
1. Preparation After installing the Linux operati...
CSS3 syntax: (1rem = 100px for a 750px design) @m...
When we develop a single-page application, someti...
This article is intended to be a starting point f...
1. Introduction The location instruction is the c...
The first cutter in China github.com/chokcoco Fir...
Preface : Today I was asked, "Have you carefu...
Table of contents Introduction to bootstrap and i...
The color matching in website construction is ver...