MySQL  8.0.18
Source Code Documentation
item_func.cc File Reference

This file defines all numerical Items. More...

#include "sql/item_func.h"
#include <string.h>
#include <time.h>
#include <algorithm>
#include <atomic>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iosfwd>
#include <limits>
#include <memory>
#include <new>
#include <string>
#include <unordered_map>
#include <utility>
#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_macros.h"
#include "my_psi_config.h"
#include "my_sqlcommand.h"
#include "my_systime.h"
#include "my_thread.h"
#include "my_user.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/components/services/mysql_cond_bits.h"
#include "mysql/components/services/mysql_mutex_bits.h"
#include "mysql/components/services/psi_mutex_bits.h"
#include "mysql/plugin_audit.h"
#include "mysql/psi/mysql_cond.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/psi_base.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/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/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/json_dom.h"
#include "sql/key.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/parse_tree_helpers.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/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_error.h"
#include "sql/sql_exchange.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/val_int_compare.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)
 
bool check_reserved_words (const char *name)
 
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...
 
Item_fieldget_gc_for_expr (Item_func **func, Field *fld, Item_result type, Field **found)
 Return new Item_field if given expression matches GC. More...
 
static bool substitute_gc_expression (Item_func **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 **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...
 
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)
 
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_entryget_variable (THD *thd, const Name_string &name, const CHARSET_INFO *cs)
 
static int get_var_with_binlog (THD *thd, enum_sql_command sql_command, 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...
 
static void update_table_read_set (Field *field)
 Add field into table read set. More...
 
Itemget_system_var (Parse_context *pc, enum_var_type var_type, LEX_STRING name, LEX_STRING component)
 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
 

Detailed Description

This file defines all numerical Items.

Function Documentation

◆ check_and_convert_ull_name()

static bool check_and_convert_ull_name ( char *  buff,
const String org_name 
)
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.

Parameters
buffBuffer for lowercased name in system charset of NAME_LEN + 1 bytes length.
org_nameOriginal string passed as name parameter to user-level lock function.
Returns
True in case of error, false on success.

◆ check_reserved_words()

bool check_reserved_words ( const char *  name)

◆ check_table_and_trigger_access()

static bool check_table_and_trigger_access ( Item **  args,
bool  check_trigger_acl,
bool null_value 
)
static

◆ eval_const_cond()

bool eval_const_cond ( THD thd,
Item cond,
bool value 
)

Evaluate a constant condition, represented by an Item tree.

Parameters
thdThread handler
condThe constant condition to evaluate
[out]valueReturned value, either true or false
Returns
false if evaluation is successful, true otherwise

◆ free_user_var()

static void free_user_var ( user_var_entry entry)
static

◆ gc_subst_overlaps_contains()

static void gc_subst_overlaps_contains ( Item_func **  func,
Item **  vals,
Json_wrapper vals_wr,
List< Field > *  gc_fields 
)
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.

Parameters
funcFunction to replace
valsArgs to replace
vals_wrJson_wrapper containing array of values for index lookup
gc_fieldsList of generated fields to look the function's substitute in

◆ get_gc_for_expr()

Item_field* get_gc_for_expr ( Item_func **  func,
Field fld,
Item_result  type,
Field **  found 
)

Return new Item_field if given expression matches GC.

See also
substitute_gc()
Parameters
funcExpression to be replaced
fldGCs field
typeResult type to match with Field
[out]foundIf given, just return found field, without Item_field
Returns
item new Item_field for matched GC NULL otherwise

◆ get_system_var()

Item* get_system_var ( Parse_context pc,
enum_var_type  var_type,
LEX_STRING  name,
LEX_STRING  component 
)

Return value of an system variable base[.name] as a constant item.

Parameters
pcCurrent parse context
var_typeglobal / session
nameName of base or system variable
componentComponent.
Note
If component.str = 0 then the variable name is in 'name'
Returns
  • 0 : error
  • # : constant item

◆ get_table_statistics()

static ulonglong get_table_statistics ( Item **  args,
uint  arg_count,
dd::info_schema::enum_table_stats_type  stype,
bool null_value 
)
static

Get table statistics from dd::info_schema::get_table_statistics.

Parameters
argsList 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_countNumber of arguments in 'args'
stypeType of statistics that is requested
[out]null_valueMarked true indicating NULL, if there is no value.
Returns
ulonglong representing the statistics requested.

◆ get_var_with_binlog()

static int get_var_with_binlog ( THD thd,
enum_sql_command  sql_command,
Name_string name,
user_var_entry **  out_entry 
)
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).

Parameters
thdCurrent session.
sql_commandThe command the variable participates in.
nameVariable name
[out]out_entryvariable structure or NULL. The pointer is set regardless of whether function succeeded or not.
Return values
0OK
1Failed to put appropriate record into binary log

◆ get_variable()

static user_var_entry* get_variable ( THD thd,
const Name_string name,
const CHARSET_INFO cs 
)
static

◆ init_item_func_sleep_psi_keys()

static void init_item_func_sleep_psi_keys ( )
static

◆ is_hidden_by_ndb()

static bool is_hidden_by_ndb ( THD thd,
String schema_name,
String table_name 
)
inlinestatic

Check if schema and table are hidden by NDB engine.

Parameters
thdThread handle.
schema_nameSchema name.
table_nameTable name.
Return values
trueIf schema and table are hidden by NDB.
falseIf schema and table are not hidden by NDB.

◆ Item_func_bit_two_param::eval_int_op< std::bit_and< ulonglong > >()

template longlong Item_func_bit_two_param::eval_int_op< std::bit_and< ulonglong > > ( std::bit_and< ulonglong )

◆ Item_func_bit_two_param::eval_int_op< std::bit_or< ulonglong > >()

template longlong Item_func_bit_two_param::eval_int_op< std::bit_or< ulonglong > > ( std::bit_or< ulonglong )

Instantiations of the above.

◆ Item_func_bit_two_param::eval_int_op< std::bit_xor< ulonglong > >()

template longlong Item_func_bit_two_param::eval_int_op< std::bit_xor< ulonglong > > ( std::bit_xor< ulonglong )

◆ item_func_sleep_free()

void item_func_sleep_free ( )

◆ item_func_sleep_init()

void item_func_sleep_init ( )

◆ my_double_round()

double my_double_round ( double  value,
longlong  dec,
bool  dec_unsigned,
bool  truncate 
)

◆ my_missing_function_error()

static void my_missing_function_error ( const LEX_STRING token,
const char *  func_name 
)
static

◆ my_unsigned_round()

static ulonglong my_unsigned_round ( ulonglong  value,
ulonglong  to 
)
inlinestatic

◆ mysql_ull_cleanup()

void mysql_ull_cleanup ( THD thd)

Release all user level locks for this THD.

◆ mysql_ull_set_explicit_lock_duration()

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.

◆ reject_geometry_args()

bool reject_geometry_args ( uint  arg_count,
Item **  args,
Item_result_field me 
)

◆ retrieve_tablespace_statistics()

void retrieve_tablespace_statistics ( THD thd,
Item **  args,
bool null_value 
)

Retrieve tablespace statistics from SE.

Parameters
thdThe current thread.
argsList of parameters in following order,
                   - Tablespace_name
                   - Engine_name
                   - Tablespace_se_private_data
[out]null_valueMarked true indicating NULL, if there is no value.
Returns
void

◆ substitute_gc_expression()

static bool substitute_gc_expression ( Item_func **  expr,
Item **  value,
List< Field > *  gc_fields,
Item_result  type,
Item_func predicate 
)
static

Attempt to substitute an expression with an equivalent generated column in a predicate.

Parameters
exprthe expression that should be substituted
valueif given, value will be coerced to GC field's type and the result will substitute the original value. Used by multi-valued index.
gc_fieldslist of indexed generated columns to check for equivalence with the expression
typethe acceptable type of the generated column that replaces the expression
predicatethe predicate in which the substitution is done
Returns
true on error, false on success

◆ test_if_sum_overflows_ull()

static bool test_if_sum_overflows_ull ( ulonglong  arg1,
ulonglong  arg2 
)
inlinestatic

Test if the sum of arguments overflows the ulonglong range.

◆ unsupported_json_comparison()

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.

Parameters
arg_countthe number of arguments
argsthe arguments to go through looking for JSON values
msgthe message that explains what is not supported

◆ update_table_read_set()

static void update_table_read_set ( Field field)
static

Add field into table read set.

Parameters
fieldfield to be added to the table read set.

◆ uuid_short_init()

void uuid_short_init ( )

Variable Documentation

◆ item_func_sleep_inited

bool item_func_sleep_inited = false
static

◆ item_func_sleep_mutexes

PSI_mutex_info item_func_sleep_mutexes[]
static
Initial value:
= {
{&key_LOCK_item_func_sleep, "LOCK_item_func_sleep", PSI_FLAG_SINGLETON, 0,
#define PSI_FLAG_SINGLETON
Singleton flag.
Definition: psi_base.h:54
static PSI_mutex_key key_LOCK_item_func_sleep
Definition: item_func.cc:5180
#define PSI_DOCUMENT_ME
Definition: psi_base.h:46

◆ key_LOCK_item_func_sleep

PSI_mutex_key key_LOCK_item_func_sleep
static

◆ LOCK_item_func_sleep

mysql_mutex_t LOCK_item_func_sleep

Lock which is used to implement interruptible wait for SLEEP() function.

◆ separator

const char separator = ','
static

◆ uuid_value

ulonglong uuid_value