MySQL  8.0.17
Source Code Documentation
item.h File Reference
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <new>
#include <string>
#include "field_types.h"
#include "lex_string.h"
#include "m_ctype.h"
#include "m_string.h"
#include "memory_debugging.h"
#include "my_alloc.h"
#include "my_bitmap.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_double2ulonglong.h"
#include "my_inttypes.h"
#include "my_sys.h"
#include "my_table_map.h"
#include "my_time.h"
#include "mysql/udf_registration_types.h"
#include "mysql_com.h"
#include "mysql_time.h"
#include "sql/enum_query_type.h"
#include "sql/field.h"
#include "sql/mem_root_array.h"
#include "sql/my_decimal.h"
#include "sql/parse_tree_node_base.h"
#include "sql/sql_array.h"
#include "sql/sql_const.h"
#include "sql/table.h"
#include "sql/table_trigger_field_support.h"
#include "sql/thr_malloc.h"
#include "sql/trigger_def.h"
#include "sql_string.h"
#include "template_utils.h"

Go to the source code of this file.

Classes

class  List< T >
 
class  List_iterator< T >
 
class  SQL_I_List< T >
 Simple intrusive linked list. More...
 
class  DTCollation
 
class  Mark_field
 Class used as argument to Item::walk() together with mark_field_in_map() More...
 
class  Used_tables
 Class used as argument to Item::walk() together with used_tables_for_level() More...
 
class  Name_string
 Storage for name strings. More...
 
class  Item_name_string
 Storage for Item names. More...
 
struct  Name_resolution_context
 
struct  Check_function_as_value_generator_parameters
 Struct used to pass around arguments to/from check_function_as_value_generator. More...
 
class  Name_resolution_context_state
 
class  Bool3
 A type for SQL-like 3-valued Booleans: true/false/unknown. More...
 
class  Settable_routine_parameter
 
class  Item
 
struct  Item::Cleanup_after_removal_context
 
struct  cache_const_expr_arg
 Descriptor of what and how to cache for Item::cache_const_expr_transformer/analyzer. More...
 
class  Item_basic_constant
 
class  Item_sp_variable
 
class  Item_splocal
 
class  Item_case_expr
 
class  Item_name_const
 
class  Item_num
 
class  Item_ident
 
class  Item_ident_for_show
 
class  Item_field
 
class  Item_null
 
class  Item_null_result
 An item representing NULL values for use with ROLLUP. More...
 
class  Item_param
 Placeholder ('?') of prepared statement. More...
 
class  Item_int
 
class  Item_int_0
 Item_int with value==0 and length==1. More...
 
class  Item_temporal
 
class  Item_uint
 
class  Item_decimal
 
class  Item_float
 
class  Item_func_pi
 
class  Item_string
 
class  Item_static_string_func
 
class  Item_partition_func_safe_string
 
class  Item_blob
 
class  Item_empty_string
 Item_empty_string – is a utility class to put an item into List<Item> which is then used in protocol.send_result_set_metadata() when sending SHOW output to the client. More...
 
class  Item_return_int
 
class  Item_hex_string
 
class  Item_bin_string
 
class  Item_result_field
 Item with result field. More...
 
class  Item_ref
 
class  Item_view_ref
 Class for fields from derived tables and views. More...
 
class  Item_outer_ref
 
class  Item_ref_null_helper
 
class  Item_int_with_ref
 
class  Item_temporal_with_ref
 
class  Item_datetime_with_ref
 
class  Item_time_with_ref
 
class  Item_copy
 Base class to implement typed value caching Item classes. More...
 
class  Item_copy_string
 
Implementation of a string cache. More...
 
class  Item_copy_json
 
class  Item_copy_int
 
class  Item_copy_uint
 
class  Item_copy_float
 
class  Item_copy_decimal
 
class  Cached_item
 This is used for segregating rows in groups (e.g. More...
 
class  Cached_item_str
 
class  Cached_item_json
 Cached_item subclass for JSON values. More...
 
class  Cached_item_real
 
class  Cached_item_int
 
class  Cached_item_temporal
 
class  Cached_item_decimal
 
class  Item_default_value
 
class  Item_insert_value
 
class  Item_trigger_field
 Represents NEW/OLD version of field of row which is changed/read in trigger. More...
 
class  Item_cache
 
class  Item_cache_int
 
class  Item_cache_real
 
class  Item_cache_decimal
 
class  Item_cache_str
 
class  Item_cache_row
 
class  Item_cache_datetime
 
class  Item_cache_json
 An item cache for values of type JSON. More...
 
class  Item_type_holder
 Item_type_holder stores type, name, length of Item for UNIONS & derived tables. More...
 
class  Item_json
 A class that represents a constant JSON value. More...
 

Macros

#define COND_FILTER_ALLPASS   1.0f
 Default condition filtering (selectivity) values used by get_filtering_effect() and friends when better estimates (statistics) are not available for a predicate. More...
 
#define COND_FILTER_EQUALITY   0.1f
 Filtering effect for equalities: col1 = col2. More...
 
#define COND_FILTER_INEQUALITY   0.3333f
 Filtering effect for inequalities: col1 > col2. More...
 
#define COND_FILTER_BETWEEN   0.1111f
 Filtering effect for between: col1 BETWEEN a AND b. More...
 
#define COND_FILTER_STALE   -1.0f
 Value is out-of-date, will need recalculation. More...
 
#define COND_FILTER_STALE_NO_CONST   -2.0f
 A special subcase of the above: More...
 
#define MY_COLL_ALLOW_SUPERSET_CONV   1
 
#define MY_COLL_ALLOW_COERCIBLE_CONV   2
 
#define MY_COLL_DISALLOW_NONE   4
 
#define MY_COLL_ALLOW_NUMERIC_CONV   8
 
#define MY_COLL_ALLOW_CONV   (MY_COLL_ALLOW_SUPERSET_CONV | MY_COLL_ALLOW_COERCIBLE_CONV)
 
#define MY_COLL_CMP_CONV   (MY_COLL_ALLOW_CONV | MY_COLL_DISALLOW_NONE)
 
#define NAME_STRING(x)   Name_string(STRING_WITH_LEN(x))
 
#define NO_CACHED_FIELD_INDEX   ((uint)(-1))
 

Typedefs

typedef Bounds_checked_array< Item * > Ref_item_array
 
typedef enum monotonicity_info enum_monotonicity_info
 
typedef bool(Item::* Item_analyzer) (uchar **argp)
 
typedef Item *(Item::* Item_transformer) (uchar *arg)
 
typedef void(* Cond_traverser) (const Item *item, void *arg)
 

Enumerations

enum  monotonicity_info {
  NON_MONOTONIC, MONOTONIC_INCREASING, MONOTONIC_INCREASING_NOT_NULL, MONOTONIC_STRICT_INCREASING,
  MONOTONIC_STRICT_INCREASING_NOT_NULL
}
 

Functions

void item_init (void)
 Init all special items. More...
 
static uint32 char_to_byte_length_safe (uint32 char_length_arg, uint32 mbmaxlen_arg)
 
Item_result numeric_context_result_type (enum_field_types data_type, Item_result result_type, uint8 decimals)
 
template<class T >
bool WalkItem (Item *item, enum_walk walk, T &&functor)
 A helper class to give in a functor to Item::walk(). More...
 
bool agg_item_collations_for_comparison (DTCollation &c, const char *name, Item **items, uint nitems, uint flags)
 
bool agg_item_set_converter (DTCollation &coll, const char *fname, Item **args, uint nargs, uint flags, int item_sep)
 
bool agg_item_charsets (DTCollation &c, const char *name, Item **items, uint nitems, uint flags, int item_sep)
 
bool agg_item_charsets_for_string_result (DTCollation &c, const char *name, Item **items, uint nitems, int item_sep=1)
 
bool agg_item_charsets_for_comparison (DTCollation &c, const char *name, Item **items, uint nitems, int item_sep=1)
 
bool agg_item_charsets_for_string_result_with_comparison (DTCollation &c, const char *name, Item **items, uint nitems, int item_sep=1)
 
longlong longlong_from_string_with_check (const CHARSET_INFO *cs, const char *cptr, const char *end)
 
double double_from_string_with_check (const CHARSET_INFO *cs, const char *cptr, const char *end)
 
Cached_itemnew_Cached_item (THD *thd, Item *item)
 Create right type of Cached_item for an item. More...
 
Item_result item_cmp_type (Item_result a, Item_result b)
 
bool resolve_const_item (THD *thd, Item **ref, Item *cmp_item)
 Substitute a const item with a simpler const item, if possible. More...
 
int stored_field_cmp_to_item (THD *thd, Field *field, Item *item)
 Compare the value stored in field with the expression from the query. More...
 
bool is_null_on_empty_table (THD *thd, Item_field *i)
 Check if the column reference that is currently being resolved, will be set to NULL if its qualifying query returns zero rows. More...
 
void convert_and_print (const String *from_str, String *to_str, const CHARSET_INFO *to_cs)
 Helper method: Convert string to the given charset, then print. More...
 
std::string ItemToString (Item *item)
 

Variables

const Name_string null_name_string
 
const String my_null_string
 

Macro Definition Documentation

◆ COND_FILTER_ALLPASS

#define COND_FILTER_ALLPASS   1.0f

Default condition filtering (selectivity) values used by get_filtering_effect() and friends when better estimates (statistics) are not available for a predicate.

For predicates that are always satisfied. Must be 1.0 or the filter calculation logic will break down.

◆ COND_FILTER_BETWEEN

#define COND_FILTER_BETWEEN   0.1111f

Filtering effect for between: col1 BETWEEN a AND b.

◆ COND_FILTER_EQUALITY

#define COND_FILTER_EQUALITY   0.1f

Filtering effect for equalities: col1 = col2.

◆ COND_FILTER_INEQUALITY

#define COND_FILTER_INEQUALITY   0.3333f

Filtering effect for inequalities: col1 > col2.

◆ COND_FILTER_STALE

#define COND_FILTER_STALE   -1.0f

Value is out-of-date, will need recalculation.

This is used by post-greedy-search logic which changes the access method and thus makes obsolete the filtering value calculated by best_access_path(). For example, test_if_skip_sort_order().

◆ COND_FILTER_STALE_NO_CONST

#define COND_FILTER_STALE_NO_CONST   -2.0f

A special subcase of the above:

  • if this is table/index/range scan, and
  • rows_fetched is how many rows we will examine, and
  • rows_fetched is less than the number of rows in the table (as determined by test_if_cheaper_ordering() and test_if_skip_sort_order()). Unlike the ordinary case where rows_fetched:
  • is set by calculate_scan_cost(), and
  • is how many rows pass the constant condition (so, less than we will examine), and
  • the actual rows_fetched to show in EXPLAIN is the number of rows in the table (== rows which we will examine), and
  • the constant condition's effect has to be moved to filter_effect for EXPLAIN.

◆ MY_COLL_ALLOW_COERCIBLE_CONV

#define MY_COLL_ALLOW_COERCIBLE_CONV   2

◆ MY_COLL_ALLOW_CONV

#define MY_COLL_ALLOW_CONV   (MY_COLL_ALLOW_SUPERSET_CONV | MY_COLL_ALLOW_COERCIBLE_CONV)

◆ MY_COLL_ALLOW_NUMERIC_CONV

#define MY_COLL_ALLOW_NUMERIC_CONV   8

◆ MY_COLL_ALLOW_SUPERSET_CONV

#define MY_COLL_ALLOW_SUPERSET_CONV   1

◆ MY_COLL_CMP_CONV

#define MY_COLL_CMP_CONV   (MY_COLL_ALLOW_CONV | MY_COLL_DISALLOW_NONE)

◆ MY_COLL_DISALLOW_NONE

#define MY_COLL_DISALLOW_NONE   4

◆ NAME_STRING

#define NAME_STRING (   x)    Name_string(STRING_WITH_LEN(x))

◆ NO_CACHED_FIELD_INDEX

#define NO_CACHED_FIELD_INDEX   ((uint)(-1))

Typedef Documentation

◆ Cond_traverser

typedef void(* Cond_traverser) (const Item *item, void *arg)

◆ enum_monotonicity_info

◆ Item_analyzer

typedef bool(Item::* Item_analyzer) (uchar **argp)

◆ Item_transformer

typedef Item*(Item::* Item_transformer) (uchar *arg)

◆ Ref_item_array

Enumeration Type Documentation

◆ monotonicity_info

Enumerator
NON_MONOTONIC 
MONOTONIC_INCREASING 
MONOTONIC_INCREASING_NOT_NULL 
MONOTONIC_STRICT_INCREASING 
MONOTONIC_STRICT_INCREASING_NOT_NULL 

Function Documentation

◆ agg_item_charsets()

bool agg_item_charsets ( DTCollation c,
const char *  name,
Item **  items,
uint  nitems,
uint  flags,
int  item_sep 
)

◆ agg_item_charsets_for_comparison()

bool agg_item_charsets_for_comparison ( DTCollation c,
const char *  name,
Item **  items,
uint  nitems,
int  item_sep = 1 
)
inline

◆ agg_item_charsets_for_string_result()

bool agg_item_charsets_for_string_result ( DTCollation c,
const char *  name,
Item **  items,
uint  nitems,
int  item_sep = 1 
)
inline

◆ agg_item_charsets_for_string_result_with_comparison()

bool agg_item_charsets_for_string_result_with_comparison ( DTCollation c,
const char *  name,
Item **  items,
uint  nitems,
int  item_sep = 1 
)
inline

◆ agg_item_collations_for_comparison()

bool agg_item_collations_for_comparison ( DTCollation c,
const char *  name,
Item **  items,
uint  nitems,
uint  flags 
)

◆ agg_item_set_converter()

bool agg_item_set_converter ( DTCollation coll,
const char *  fname,
Item **  args,
uint  nargs,
uint  flags,
int  item_sep 
)

◆ char_to_byte_length_safe()

static uint32 char_to_byte_length_safe ( uint32  char_length_arg,
uint32  mbmaxlen_arg 
)
inlinestatic

◆ convert_and_print()

void convert_and_print ( const String from_str,
String to_str,
const CHARSET_INFO to_cs 
)

Helper method: Convert string to the given charset, then print.

Parameters
from_strString to be converted.
to_strQuery string.
to_csCharacter set to which the string is to be converted.

◆ double_from_string_with_check()

double double_from_string_with_check ( const CHARSET_INFO cs,
const char *  cptr,
const char *  end 
)

◆ is_null_on_empty_table()

bool is_null_on_empty_table ( THD thd,
Item_field i 
)

Check if the column reference that is currently being resolved, will be set to NULL if its qualifying query returns zero rows.

This is true for non-aggregated column references in the SELECT list, if the query block uses aggregation without grouping. For example:

SELECT COUNT(*), col FROM t WHERE some_condition

Here, if the table t is empty, or some_condition doesn't match any rows in t, the query returns one row where col is NULL, even if col is a not-nullable column.

Such column references are rejected if the ONLY_FULL_GROUP_BY SQL mode is enabled, in a later resolution phase.

◆ item_cmp_type()

Item_result item_cmp_type ( Item_result  a,
Item_result  b 
)

◆ item_init()

void item_init ( void  )

Init all special items.

◆ ItemToString()

std::string ItemToString ( Item item)

◆ longlong_from_string_with_check()

longlong longlong_from_string_with_check ( const CHARSET_INFO cs,
const char *  cptr,
const char *  end 
)

◆ new_Cached_item()

Cached_item* new_Cached_item ( THD thd,
Item item 
)

Create right type of Cached_item for an item.

◆ numeric_context_result_type()

Item_result numeric_context_result_type ( enum_field_types  data_type,
Item_result  result_type,
uint8  decimals 
)
inline

◆ resolve_const_item()

bool resolve_const_item ( THD thd,
Item **  ref,
Item comp_item 
)

Substitute a const item with a simpler const item, if possible.

Parameters
thdCurrent session.
[in,out]refConst item to be processed, contains simplest possible item on return.
comp_itemItem that provides result type for generated const item
Returns
false if success, true if error

◆ stored_field_cmp_to_item()

int stored_field_cmp_to_item ( THD thd,
Field field,
Item item 
)

Compare the value stored in field with the expression from the query.

Parameters
thdCurrent session.
fieldField which the Item is stored in after conversion
itemOriginal expression from query
Returns
Returns an integer greater than, equal to, or less than 0 if the value stored in the field is greater than, equal to, or less than the original Item. A 0 may also be returned if out of memory.
Note
We use this in the range optimizer/partition pruning, because in some cases we can't store the value in the field without some precision/character loss.

We similarly use it to verify that expressions like BIGINT_FIELD <cmp> <literal value> is done correctly (as int/decimal/float according to literal type).

◆ WalkItem()

template<class T >
bool WalkItem ( Item item,
enum_walk  walk,
T &&  functor 
)
inline

A helper class to give in a functor to Item::walk().

Use as e.g.:

bool result = WalkItem(root_item, enum_walk::POSTFIX, [](Item *item) { ... });

TODO: Make Item::walk() just take in a functor in the first place, instead of a pointer-to-member and an opaque argument.

Variable Documentation

◆ my_null_string

const String my_null_string

◆ null_name_string

const Name_string null_name_string