MySQL  8.0.27
Source Code Documentation
Arg_comparator Class Reference

#include <item_cmpfunc.h>

Public Member Functions

 Arg_comparator ()=default
 
 Arg_comparator (Item **left, Item **right)
 
bool set_compare_func (Item_result_field *owner, Item_result type)
 
bool set_cmp_func (Item_result_field *owner_arg, Item **left, Item **right, Item_result type)
 Sets compare functions for various datatypes. More...
 
bool set_cmp_func (Item_result_field *owner_arg, Item **left, Item **right, bool set_null_arg)
 
bool set_cmp_func (Item_result_field *owner_arg, Item **left, Item **right, bool set_null_arg, Item_result type)
 
bool inject_cast_nodes ()
 Comparison function are expected to operate on arguments having the same data types. More...
 
int compare ()
 
int compare_string ()
 
int compare_binary_string ()
 Compare strings byte by byte. More...
 
int compare_real ()
 
int compare_decimal ()
 
int compare_int_signed ()
 
int compare_int_signed_unsigned ()
 Compare signed (*left) with unsigned (*B) More...
 
int compare_int_unsigned_signed ()
 Compare unsigned (*left) with signed (*B) More...
 
int compare_int_unsigned ()
 Compare values as BIGINT UNSIGNED. More...
 
int compare_time_packed ()
 Compare arguments using numeric packed temporal representation. More...
 
int compare_row ()
 
int compare_real_fixed ()
 
int compare_datetime ()
 Compare item values as dates. More...
 
int compare_json ()
 Compare two Item objects as JSON. More...
 
bool compare_null_values ()
 Compare NULL values for two arguments. More...
 
Item ** cache_converted_constant (THD *thd, Item **value, Item **cache, Item_result type)
 Convert and cache a constant. More...
 
void set_datetime_cmp_func (Item_result_field *owner_arg, Item **a1, Item **b1)
 
void cleanup ()
 
void set_cmp_context_for_datetime ()
 
Item_result get_compare_type () const
 
uint get_child_comparator_count () const
 
Arg_comparatorget_child_comparators () const
 
bool use_custom_value_extractors () const
 
longlong extract_value_from_argument (THD *thd, Item *item, bool left_argument, bool *is_null) const
 
Item ** get_left_ptr () const
 
Itemget_right () const
 

Static Public Member Functions

static bool can_compare_as_dates (const Item *a, const Item *b)
 Checks whether compare_datetime() can be used to compare items. More...
 

Public Attributes

DTCollation cmp_collation
 
String value1
 
String value2
 

Static Public Attributes

static arg_cmp_func comparator_matrix [5]
 

Private Member Functions

bool try_year_cmp_func (Item_result type)
 

Static Private Member Functions

static bool get_date_from_const (Item *date_arg, Item *str_arg, ulonglong *const_value)
 Check if str_arg is a constant and convert it to datetime packed value. More...
 

Private Attributes

Item ** left {nullptr}
 
Item ** right {nullptr}
 
arg_cmp_func func {nullptr}
 
Item_result_fieldowner {nullptr}
 
Arg_comparatorcomparators {nullptr}
 
uint16 comparator_count {0}
 
double precision {0.0}
 
Itemleft_cache {nullptr}
 
Itemright_cache {nullptr}
 
bool set_null {true}
 
Json_scalar_holderjson_scalar {nullptr}
 Only used by compare_json() in the case where a JSON value is compared to an SQL value. More...
 
longlong(* get_value_a_func )(THD *thd, Item ***item_arg, Item **cache_arg, const Item *warn_item, bool *is_null)
 A function pointer that is used for retrieving the value from argument "left". More...
 
longlong(* get_value_b_func )(THD *thd, Item ***item_arg, Item **cache_arg, const Item *warn_item, bool *is_null)
 
Item_result m_compare_type {INVALID_RESULT}
 

Constructor & Destructor Documentation

◆ Arg_comparator() [1/2]

Arg_comparator::Arg_comparator ( )
default

◆ Arg_comparator() [2/2]

Arg_comparator::Arg_comparator ( Item **  left,
Item **  right 
)
inline

Member Function Documentation

◆ cache_converted_constant()

Item ** Arg_comparator::cache_converted_constant ( THD thd,
Item **  value,
Item **  cache_item,
Item_result  type 
)

Convert and cache a constant.

Parameters
thdThe current session.
valueAn item to cache
[out]cache_itemPlaceholder for the cache item
typeComparison type

When given item is a constant and its type differs from comparison type then cache its value to avoid type conversion of this constant on each evaluation. In this case the value is cached and the reference to the cache is returned. Original value is returned otherwise.

Returns
cache item or original value.

◆ can_compare_as_dates()

bool Arg_comparator::can_compare_as_dates ( const Item left,
const Item right 
)
static

Checks whether compare_datetime() can be used to compare items.

SYNOPSIS Arg_comparator::can_compare_as_dates() left, right [in] items to be compared

DESCRIPTION Checks several cases when the DATETIME comparator should be used. The following cases are accepted:

  1. Both left and right is a DATE/DATETIME/TIMESTAMP field/function returning string or int result.
  2. Only left or right is a DATE/DATETIME/TIMESTAMP field/function returning string or int result and the other item (right or left) is an item with string result. This doesn't mean that the string can necessarily be successfully converted to a datetime value. But if it cannot this will lead to an error later,
    See also
    Arg_comparator::get_date_from_const
    In all other cases (date-[int|real|decimal]/[int|real|decimal]-date)
    the comparison is handled by other comparators.
    
    Returns
    true if the Arg_comparator::compare_datetime should be used, false otherwise

◆ cleanup()

void Arg_comparator::cleanup ( )

◆ compare()

int Arg_comparator::compare ( )
inline

◆ compare_binary_string()

int Arg_comparator::compare_binary_string ( )

Compare strings byte by byte.

End spaces are also compared.

Return values
<0*left < *right
0*right == *right
>0*left > *right

◆ compare_datetime()

int Arg_comparator::compare_datetime ( )

Compare item values as dates.

Compare items values as DATE/DATETIME for regular comparison functions. The correct DATETIME values are obtained with help of the get_datetime_value() function.

Returns
-1 left < right or at least one item is null 0 left == right 1 left > right See the table: left_is_null | 1 | 0 | 1 | 0 | right_is_null | 1 | 1 | 0 | 0 | result |-1 |-1 |-1 |-1/0/1|

◆ compare_decimal()

int Arg_comparator::compare_decimal ( )

◆ compare_int_signed()

int Arg_comparator::compare_int_signed ( )

◆ compare_int_signed_unsigned()

int Arg_comparator::compare_int_signed_unsigned ( )

Compare signed (*left) with unsigned (*B)

◆ compare_int_unsigned()

int Arg_comparator::compare_int_unsigned ( )

Compare values as BIGINT UNSIGNED.

◆ compare_int_unsigned_signed()

int Arg_comparator::compare_int_unsigned_signed ( )

Compare unsigned (*left) with signed (*B)

◆ compare_json()

int Arg_comparator::compare_json ( )

Compare two Item objects as JSON.

If one of the arguments is NULL, and the owner is not EQUAL_FUNC, the null_value flag of the owner will be set to true.

Returns
-1 if at least one of the items is NULL or if the first item is less than the second item, 0 if the two items are equal 1 if the first item is greater than the second item.

◆ compare_null_values()

bool Arg_comparator::compare_null_values ( )

Compare NULL values for two arguments.

When called, we know that at least one argument contains a NULL value.

Returns
true if both arguments are NULL, false if one argument is NULL

◆ compare_real()

int Arg_comparator::compare_real ( )

◆ compare_real_fixed()

int Arg_comparator::compare_real_fixed ( )

◆ compare_row()

int Arg_comparator::compare_row ( )

◆ compare_string()

int Arg_comparator::compare_string ( )

◆ compare_time_packed()

int Arg_comparator::compare_time_packed ( )

Compare arguments using numeric packed temporal representation.

◆ extract_value_from_argument()

longlong Arg_comparator::extract_value_from_argument ( THD thd,
Item item,
bool  left_argument,
bool *  is_null 
) const

◆ get_child_comparator_count()

uint Arg_comparator::get_child_comparator_count ( ) const
inline

◆ get_child_comparators()

Arg_comparator* Arg_comparator::get_child_comparators ( ) const
inline

◆ get_compare_type()

Item_result Arg_comparator::get_compare_type ( ) const
inline

◆ get_date_from_const()

bool Arg_comparator::get_date_from_const ( Item date_arg,
Item str_arg,
ulonglong const_value 
)
staticprivate

Check if str_arg is a constant and convert it to datetime packed value.

Note, const_value may stay untouched, so the caller is responsible to initialize it.

Parameters
date_argdate argument, its name is used for error reporting.
str_argstring argument to get datetime value from.
[in,out]const_valueIf not nullptr, the converted value is stored here. To detect that conversion was not possible, the caller is responsible for initializing this value to MYSQL_TIMESTAMP_ERROR before calling and checking the value has changed after the call.
Returns
true on error, false on success, false if str_arg is not a const.

◆ get_left_ptr()

Item** Arg_comparator::get_left_ptr ( ) const
inline

◆ get_right()

Item* Arg_comparator::get_right ( ) const
inline

◆ inject_cast_nodes()

bool Arg_comparator::inject_cast_nodes ( )

Comparison function are expected to operate on arguments having the same data types.

Since MySQL has very loosened up rules, it accepts all kind of arguments which the standard SQL does not allow, and then it converts the arguments internally to ones usable in the comparison. This function transforms these internal conversions to explicit CASTs so that the internally executed query becomes compatible with the standard At the moment nodes are injected only for comparisons between:

1) temporal types and numeric data types: in which case the comparison is normally done as DOUBLE, so the arguments which are not floating point, will get converted to DOUBLE, and also for

2) comparisons between temporal types: in which case the comparison happens as DATETIME if the arguments have different data types, so in this case the temporal arguments that are not DATETIME will get wrapped in a CAST to DATETIME.

WL#12108; This function will limit itself to comparison between regular functions, aggregation functions and fields, all of which are constant for execution (so this excludes stored procedures, stored functions, GC, user defined functions, as well as literals). For const arguments, see type conversions done in fold_condition.

Returns
false if successful, true otherwise

◆ set_cmp_context_for_datetime()

void Arg_comparator::set_cmp_context_for_datetime ( )
inline

◆ set_cmp_func() [1/3]

bool Arg_comparator::set_cmp_func ( Item_result_field owner_arg,
Item **  left,
Item **  right,
bool  set_null_arg 
)

◆ set_cmp_func() [2/3]

bool Arg_comparator::set_cmp_func ( Item_result_field owner_arg,
Item **  left,
Item **  right,
bool  set_null_arg,
Item_result  type 
)

◆ set_cmp_func() [3/3]

bool Arg_comparator::set_cmp_func ( Item_result_field owner_arg,
Item **  left_arg,
Item **  right_arg,
Item_result  type 
)

Sets compare functions for various datatypes.

NOTE The result type of a comparison is chosen by item_cmp_type(). Here we override the chosen result type for certain expression containing date or time or decimal expressions.

◆ set_compare_func()

bool Arg_comparator::set_compare_func ( Item_result_field owner,
Item_result  type 
)

◆ set_datetime_cmp_func()

void Arg_comparator::set_datetime_cmp_func ( Item_result_field owner_arg,
Item **  a1,
Item **  b1 
)

◆ try_year_cmp_func()

bool Arg_comparator::try_year_cmp_func ( Item_result  type)
private

◆ use_custom_value_extractors()

bool Arg_comparator::use_custom_value_extractors ( ) const
inline
Returns
true if the class has decided that values should be extracted from the Items using function pointers set up by this class.

Member Data Documentation

◆ cmp_collation

DTCollation Arg_comparator::cmp_collation

◆ comparator_count

uint16 Arg_comparator::comparator_count {0}
private

◆ comparator_matrix

arg_cmp_func Arg_comparator::comparator_matrix
static
Initial value:
= {
int compare_int_signed()
Definition: item_cmpfunc.cc:1813
int compare_real()
Definition: item_cmpfunc.cc:1760
int compare_string()
Definition: item_cmpfunc.cc:1710
int compare_decimal()
Definition: item_cmpfunc.cc:1778
int compare_row()
Definition: item_cmpfunc.cc:1929

◆ comparators

Arg_comparator* Arg_comparator::comparators {nullptr}
private

◆ func

arg_cmp_func Arg_comparator::func {nullptr}
private

◆ get_value_a_func

longlong(* Arg_comparator::get_value_a_func) (THD *thd, Item ***item_arg, Item **cache_arg, const Item *warn_item, bool *is_null)
inlineprivate

A function pointer that is used for retrieving the value from argument "left".

This function is only used when we are comparing in a datetime context, and it retrieves the value as a DATE, TIME, DATETIME or YEAR, depending on the comparison context.

Parameters
thdthread handle. Used to retrieve the SQL mode among other things
item_argthe item to retrieve the value from
cache_arga pointer to an Item where we can cache the value from "item_arg". Can be nullptr
warn_itemif rasing an conversion warning, the warning gets the data type and item name from this item
is_nullwhether or not "item_arg" returned SQL NULL
Returns
a DATE/TIME/YEAR/DATETIME value, in packed format

◆ get_value_b_func

longlong(* Arg_comparator::get_value_b_func) (THD *thd, Item ***item_arg, Item **cache_arg, const Item *warn_item, bool *is_null)
inlineprivate

◆ json_scalar

Json_scalar_holder* Arg_comparator::json_scalar {nullptr}
private

Only used by compare_json() in the case where a JSON value is compared to an SQL value.

This member points to pre-allocated memory that can be used instead of the heap when converting the SQL value to a JSON value.

◆ left

Item** Arg_comparator::left {nullptr}
private

◆ left_cache

Item* Arg_comparator::left_cache {nullptr}
private

◆ m_compare_type

Item_result Arg_comparator::m_compare_type {INVALID_RESULT}
private

◆ owner

Item_result_field* Arg_comparator::owner {nullptr}
private

◆ precision

double Arg_comparator::precision {0.0}
private

◆ right

Item** Arg_comparator::right {nullptr}
private

◆ right_cache

Item* Arg_comparator::right_cache {nullptr}
private

◆ set_null

bool Arg_comparator::set_null {true}
private

◆ value1

String Arg_comparator::value1

◆ value2

String Arg_comparator::value2

The documentation for this class was generated from the following files: