MySQL 8.0.40
Source Code Documentation
|
This file defines all numerical Items. More...
#include "sql/item_func.h"
#include <algorithm>
#include <atomic>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <initializer_list>
#include <iosfwd>
#include <limits>
#include <memory>
#include <new>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include "integer_digits.h"
#include "m_string.h"
#include "map_helpers.h"
#include "mutex_lock.h"
#include "my_bit.h"
#include "my_bitmap.h"
#include "my_byteorder.h"
#include "my_dbug.h"
#include "my_double2ulonglong.h"
#include "my_hostname.h"
#include "my_loglevel.h"
#include "my_psi_config.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "my_systime.h"
#include "my_thread.h"
#include "my_user.h"
#include "mysql/components/services/bits/mysql_cond_bits.h"
#include "mysql/components/services/bits/mysql_mutex_bits.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/bits/psi_mutex_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/mysql_lex_string.h"
#include "mysql/plugin_audit.h"
#include "mysql/psi/mysql_cond.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/service_mysql_password_policy.h"
#include "mysql/service_thd_wait.h"
#include "mysql/status_var.h"
#include "prealloced_array.h"
#include "sql-common/json_dom.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/binlog.h"
#include "sql/check_stack.h"
#include "sql/current_thd.h"
#include "sql/dd/info_schema/table_stats.h"
#include "sql/dd/info_schema/tablespace_stats.h"
#include "sql/dd/object_id.h"
#include "sql/dd/properties.h"
#include "sql/dd/types/abstract_table.h"
#include "sql/dd/types/column.h"
#include "sql/dd/types/index.h"
#include "sql/dd_sql_view.h"
#include "sql/dd_table_share.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/error_handler.h"
#include "sql/item.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_json_func.h"
#include "sql/item_strfunc.h"
#include "sql/item_subselect.h"
#include "sql/key.h"
#include "sql/log_event.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/parse_tree_helpers.h"
#include "sql/parse_tree_node_base.h"
#include "sql/protocol.h"
#include "sql/psi_memory_key.h"
#include "sql/resourcegroups/resource_group.h"
#include "sql/resourcegroups/resource_group_basic_types.h"
#include "sql/resourcegroups/resource_group_mgr.h"
#include "sql/rpl_gtid.h"
#include "sql/rpl_mi.h"
#include "sql/rpl_msr.h"
#include "sql/rpl_rli.h"
#include "sql/sp.h"
#include "sql/sp_head.h"
#include "sql/sp_pcontext.h"
#include "sql/sql_array.h"
#include "sql/sql_audit.h"
#include "sql/sql_base.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_class.h"
#include "sql/sql_cmd.h"
#include "sql/sql_derived.h"
#include "sql/sql_error.h"
#include "sql/sql_exchange.h"
#include "sql/sql_executor.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_load.h"
#include "sql/sql_optimizer.h"
#include "sql/sql_parse.h"
#include "sql/sql_show.h"
#include "sql/sql_time.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/thd_raii.h"
#include "sql/val_int_compare.h"
#include "sql_string.h"
#include "template_utils.h"
#include "thr_mutex.h"
Classes | |
class | Interruptible_wait |
Enables a session to wait on a condition until a timeout or a network disconnect occurs. More... | |
struct | User_level_lock |
For locks with EXPLICIT duration, MDL returns a new ticket every time a lock is granted. More... | |
class | User_level_lock_wait_error_handler |
When MDL detects a lock wait timeout, it pushes an error into the statement diagnostics area. More... | |
class | MDL_lock_get_owner_thread_id_visitor |
Functions | |
static void | free_user_var (user_var_entry *entry) |
static int | get_var_with_binlog (THD *thd, enum_sql_command sql_command, const Name_string &name, user_var_entry **out_entry) |
Get variable by name and, if necessary, put the record of variable use into the binary log. More... | |
bool | check_reserved_words (const char *name) |
void | report_conversion_error (const CHARSET_INFO *to_cs, const char *from, size_t from_length, const CHARSET_INFO *from_cs) |
bool | simplify_string_args (THD *thd, const DTCollation &c, Item **args, uint nargs) |
Simplify the string arguments to a function, if possible. More... | |
String * | eval_string_arg_noinline (const CHARSET_INFO *to_cs, Item *arg, String *buffer) |
Evaluate an argument string and return it in the desired character set. More... | |
bool | eval_const_cond (THD *thd, Item *cond, bool *value) |
Evaluate a constant condition, represented by an Item tree. More... | |
static bool | test_if_sum_overflows_ull (ulonglong arg1, ulonglong arg2) |
Test if the sum of arguments overflows the ulonglong range. More... | |
bool | param_type_uses_non_param_inner (THD *thd, uint arg_count, Item **args, enum_field_types def) |
For arguments of this Item_func ("args" array), all of them: find an argument that is not a dynamic parameter; if found, all dynamic parameters without a valid type get the type of this; if not found, they get type "def". More... | |
bool | is_function_of_type (const Item *item, Item_func::Functype type) |
Checks if "item" is a function of the specified type. More... | |
bool | contains_function_of_type (Item *item, Item_func::Functype type) |
Checks if "item" contains a function of the specified type. More... | |
Item_field * | get_gc_for_expr (const Item *func, Field *fld, Item_result type, Field **found) |
Return new Item_field if given expression matches GC. More... | |
static bool | substitute_gc_expression (Item **expr, Item **value, List< Field > *gc_fields, Item_result type, Item_func *predicate) |
Attempt to substitute an expression with an equivalent generated column in a predicate. More... | |
static void | gc_subst_overlaps_contains (Item **func, Item **vals, Json_wrapper &vals_wr, List< Field > *gc_fields) |
A helper function for Item_func::gc_subst_transformer, that tries to substitute the given JSON_CONTAINS or JSON_OVERLAPS function for one of GCs from the provided list. More... | |
bool | reject_geometry_args (uint arg_count, Item **args, Item_result_field *me) |
void | unsupported_json_comparison (size_t arg_count, Item **args, const char *msg) |
Go through the arguments of a function and check if any of them are JSON. More... | |
static longlong | val_int_from_str (Item *item, bool unsigned_flag, bool *null_value) |
template longlong | Item_func_bit_two_param::eval_int_op< std::bit_or< ulonglong > > (std::bit_or< ulonglong >) |
Instantiations of the above. More... | |
template longlong | Item_func_bit_two_param::eval_int_op< std::bit_and< ulonglong > > (std::bit_and< ulonglong >) |
template longlong | Item_func_bit_two_param::eval_int_op< std::bit_xor< ulonglong > > (std::bit_xor< ulonglong >) |
double | my_double_round (double value, longlong dec, bool dec_unsigned, bool truncate) |
static ulonglong | my_unsigned_round (ulonglong value, ulonglong to, bool *round_overflow) |
static int | temporal_rank (enum_field_types type) |
void | mysql_ull_cleanup (THD *thd) |
Release all user level locks for this THD. More... | |
void | mysql_ull_set_explicit_lock_duration (THD *thd) |
Set explicit duration for metadata locks corresponding to user level locks to protect them from being released at the end of transaction. More... | |
static bool | check_and_convert_ull_name (char *buff, const String *org_name) |
Helper function which checks if user-level lock name is acceptable and converts it to system charset (utf8). More... | |
static void | init_item_func_sleep_psi_keys () |
void | item_func_sleep_init () |
void | item_func_sleep_free () |
static user_var_entry * | get_variable (THD *thd, const Name_string &name, const CHARSET_INFO *cs) |
Get variable with given name; conditionally create it if non-existing. More... | |
static void | update_table_read_set (const Field *field) |
Add field into table read set. More... | |
Item * | get_system_variable (Parse_context *pc, enum_var_type scope, const LEX_CSTRING &prefix, const LEX_CSTRING &suffix, bool unsafe_for_replication) |
Return value of an system variable base[.name] as a constant item. More... | |
static void | my_missing_function_error (const LEX_STRING &token, const char *func_name) |
void | uuid_short_init () |
static bool | is_hidden_by_ndb (THD *thd, String *schema_name, String *table_name) |
Check if schema and table are hidden by NDB engine. More... | |
static bool | check_table_and_trigger_access (Item **args, bool check_trigger_acl, bool *null_value) |
static ulonglong | get_table_statistics (Item **args, uint arg_count, dd::info_schema::enum_table_stats_type stype, bool *null_value) |
Get table statistics from dd::info_schema::get_table_statistics. More... | |
void | retrieve_tablespace_statistics (THD *thd, Item **args, bool *null_value) |
Retrieve tablespace statistics from SE. More... | |
Variables | |
static const char | separator = ',' |
mysql_mutex_t | LOCK_item_func_sleep |
Lock which is used to implement interruptible wait for SLEEP() function. More... | |
static PSI_mutex_key | key_LOCK_item_func_sleep |
static PSI_mutex_info | item_func_sleep_mutexes [] |
static bool | item_func_sleep_inited = false |
ulonglong | uuid_value |
This file defines all numerical Items.
|
static |
Helper function which checks if user-level lock name is acceptable and converts it to system charset (utf8).
Error is emitted if name is not acceptable. Name is also lowercased to ensure that user-level lock names are treated in case-insensitive fashion even though MDL subsystem which used by implementation does binary comparison of keys.
buff | Buffer for lowercased name in system charset of NAME_LEN + 1 bytes length. |
org_name | Original string passed as name parameter to user-level lock function. |
bool check_reserved_words | ( | const char * | name | ) |
|
static |
bool contains_function_of_type | ( | Item * | item, |
Item_func::Functype | type | ||
) |
Checks if "item" contains a function of the specified type.
Evaluate a constant condition, represented by an Item tree.
thd | Thread handler | |
cond | The constant condition to evaluate | |
[out] | value | Returned value, either true or false |
String * eval_string_arg_noinline | ( | const CHARSET_INFO * | to_cs, |
Item * | arg, | ||
String * | buffer | ||
) |
Evaluate an argument string and return it in the desired character set.
Perform character set conversion if needed. Perform character set validation (from a binary string) if needed.
to_cs | The desired character set |
arg | Argument to evaluate as a string value |
buffer | String buffer where argument is evaluated, if necessary |
|
static |
|
static |
A helper function for Item_func::gc_subst_transformer, that tries to substitute the given JSON_CONTAINS or JSON_OVERLAPS function for one of GCs from the provided list.
The function checks whether there's an index with matching expression and whether all scalars for lookup can be coerced to index's GC field without errors. If so, index's GC field substitutes the given function, args are replaced for array of coerced values in order to match GC's type. substitute_gc_expression() can't be used to these functions as it's tailored to handle regular single-valued indexes and doesn't ensure correct coercion of all values to lookup in multi-valued index.
func | Function to replace |
vals | Args to replace |
vals_wr | Json_wrapper containing array of values for index lookup |
gc_fields | List of generated fields to look the function's substitute in |
Item_field * get_gc_for_expr | ( | const Item * | func, |
Field * | fld, | ||
Item_result | type, | ||
Field ** | found | ||
) |
Return new Item_field if given expression matches GC.
func | Expression to be replaced | |
fld | GCs field | |
type | Result type to match with Field | |
[out] | found | If given, just return found field, without Item_field |
Item * get_system_variable | ( | Parse_context * | pc, |
enum_var_type | scope, | ||
const LEX_CSTRING & | prefix, | ||
const LEX_CSTRING & | suffix, | ||
bool | unsafe_for_replication | ||
) |
Return value of an system variable base[.name] as a constant item.
Create new Item_func_get_system_var object.
pc | Current parse context |
scope | Global / session |
prefix | Optional prefix part of the variable name |
suffix | Trivial name of suffix part of the variable name |
unsafe_for_replication | If true and if the variable is written to a binlog then mark the statement as unsafe. |
|
static |
Get table statistics from dd::info_schema::get_table_statistics.
args | List of parameters in following order, - Schema_name - Table_name - Engine_name - se_private_id - Hidden_table - Tablespace_se_private_data - Table_se_private_data (Used if stype is AUTO_INC) - Partition name (optional argument). | |
arg_count | Number of arguments in 'args' | |
stype | Type of statistics that is requested | |
[out] | null_value | Marked true indicating NULL, if there is no value. |
|
static |
Get variable by name and, if necessary, put the record of variable use into the binary log.
When a user variable is invoked from an update query (INSERT, UPDATE etc), stores this variable and its value in thd->user_var_events, so that it can be written to the binlog (will be written just before the query is written, see log.cc).
thd | Current session. | |
sql_command | The command the variable participates in. | |
name | Variable name | |
[out] | out_entry | variable structure or NULL. The pointer is set regardless of whether function succeeded or not. |
0 | OK |
1 | Failed to put appropriate record into binary log |
|
static |
Get variable with given name; conditionally create it if non-existing.
thd | thread context |
name | name of user variable |
cs | character set; = NULL: Do not create variable if non-existing. != NULL: Create variable with this character set. |
|
static |
bool is_function_of_type | ( | const Item * | item, |
Item_func::Functype | type | ||
) |
Checks if "item" is a function of the specified type.
Check if schema and table are hidden by NDB engine.
thd | Thread handle. |
schema_name | Schema name. |
table_name | Table name. |
true | If schema and table are hidden by NDB. |
false | If schema and table are not hidden by NDB. |
template longlong Item_func_bit_two_param::eval_int_op< std::bit_and< ulonglong > > | ( | std::bit_and< ulonglong > | ) |
template longlong Item_func_bit_two_param::eval_int_op< std::bit_or< ulonglong > > | ( | std::bit_or< ulonglong > | ) |
Instantiations of the above.
template longlong Item_func_bit_two_param::eval_int_op< std::bit_xor< ulonglong > > | ( | std::bit_xor< ulonglong > | ) |
void item_func_sleep_free | ( | ) |
void item_func_sleep_init | ( | ) |
double my_double_round | ( | double | value, |
longlong | dec, | ||
bool | dec_unsigned, | ||
bool | truncate | ||
) |
|
static |
|
inlinestatic |
void mysql_ull_cleanup | ( | THD * | thd | ) |
Release all user level locks for this THD.
void mysql_ull_set_explicit_lock_duration | ( | THD * | thd | ) |
Set explicit duration for metadata locks corresponding to user level locks to protect them from being released at the end of transaction.
|
inline |
For arguments of this Item_func ("args" array), all of them: find an argument that is not a dynamic parameter; if found, all dynamic parameters without a valid type get the type of this; if not found, they get type "def".
thd | thread handler |
arg_count | number of arguments to check |
args | array of arguments, size 'arg_count' |
def | default type |
bool reject_geometry_args | ( | uint | arg_count, |
Item ** | args, | ||
Item_result_field * | me | ||
) |
void report_conversion_error | ( | const CHARSET_INFO * | to_cs, |
const char * | from, | ||
size_t | from_length, | ||
const CHARSET_INFO * | from_cs | ||
) |
Retrieve tablespace statistics from SE.
thd | The current thread. | |
args | List of parameters in following order, - Tablespace_name - Engine_name - Tablespace_se_private_data | |
[out] | null_value | Marked true indicating NULL, if there is no value. |
bool simplify_string_args | ( | THD * | thd, |
const DTCollation & | c, | ||
Item ** | args, | ||
uint | nargs | ||
) |
Simplify the string arguments to a function, if possible.
Currently used to substitute const values with character strings in the desired character set. Only used during resolving.
thd | thread handler |
c | Desired character set and collation |
args | Pointer to argument array |
nargs | Number of arguments to process |
|
static |
Attempt to substitute an expression with an equivalent generated column in a predicate.
expr | the expression that should be substituted |
value | if given, value will be coerced to GC field's type and the result will substitute the original value. Used by multi-valued index. |
gc_fields | list of indexed generated columns to check for equivalence with the expression |
type | the acceptable type of the generated column that replaces the expression |
predicate | the predicate in which the substitution is done |
|
static |
Test if the sum of arguments overflows the ulonglong range.
void unsupported_json_comparison | ( | size_t | arg_count, |
Item ** | args, | ||
const char * | msg | ||
) |
Go through the arguments of a function and check if any of them are JSON.
If a JSON argument is found, raise a warning saying that this operation is not supported yet. This function is used to notify users that they are comparing JSON values using a mechanism that has not yet been updated to use the JSON comparator. JSON values are typically handled as strings in that case.
arg_count | the number of arguments |
args | the arguments to go through looking for JSON values |
msg | the message that explains what is not supported |
|
static |
Add field into table read set.
field | field to be added to the table read set. |
void uuid_short_init | ( | ) |
|
static |
|
static |
|
static |
mysql_mutex_t LOCK_item_func_sleep |
Lock which is used to implement interruptible wait for SLEEP() function.
|
static |
ulonglong uuid_value |