MySQL 8.4.3
Source Code Documentation
|
#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... | |
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_comparator * | get_child_comparators () const |
bool | compare_as_json () 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 |
Item * | get_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_field * | owner {nullptr} |
Arg_comparator * | comparators {nullptr} |
uint16 | comparator_count {0} |
double | precision {0.0} |
Item * | left_cache {nullptr} |
Item * | right_cache {nullptr} |
bool | set_null {true} |
Json_scalar_holder * | json_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} |
|
default |
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:
In all other cases (date-[int|real|decimal]/[int|real|decimal]-date) the comparison is handled by other comparators.
void Arg_comparator::cleanup | ( | ) |
|
inline |
|
inline |
int Arg_comparator::compare_binary_string | ( | ) |
Compare strings byte by byte.
End spaces are also compared.
<0 | *left < *right |
0 | *right == *right |
>0 | *left > *right |
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.
int Arg_comparator::compare_decimal | ( | ) |
int Arg_comparator::compare_int_signed | ( | ) |
int Arg_comparator::compare_int_signed_unsigned | ( | ) |
Compare signed (*left) with unsigned (*B)
int Arg_comparator::compare_int_unsigned | ( | ) |
Compare values as BIGINT UNSIGNED.
int Arg_comparator::compare_int_unsigned_signed | ( | ) |
Compare unsigned (*left) with signed (*B)
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.
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.
int Arg_comparator::compare_real | ( | ) |
int Arg_comparator::compare_real_fixed | ( | ) |
int Arg_comparator::compare_row | ( | ) |
int Arg_comparator::compare_string | ( | ) |
int Arg_comparator::compare_time_packed | ( | ) |
Compare arguments using numeric packed temporal representation.
longlong Arg_comparator::extract_value_from_argument | ( | THD * | thd, |
Item * | item, | ||
bool | left_argument, | ||
bool * | is_null | ||
) | const |
|
inline |
|
inline |
|
inline |
|
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.
date_arg | date argument, its name is used for error reporting. | |
str_arg | string argument to get datetime value from. | |
[in,out] | const_value | If 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. |
|
inline |
|
inline |
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.
|
inline |
bool Arg_comparator::set_cmp_func | ( | Item_result_field * | owner_arg, |
Item ** | left, | ||
Item ** | right, | ||
bool | set_null_arg | ||
) |
bool Arg_comparator::set_cmp_func | ( | Item_result_field * | owner_arg, |
Item ** | left, | ||
Item ** | right, | ||
bool | set_null_arg, | ||
Item_result | type | ||
) |
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.
It additionally sets up Item_cache objects for caching any constant values that need conversion to a type compatible with the comparator type, to avoid the need for performing the conversion again each time the comparator is invoked.
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.
bool Arg_comparator::set_compare_func | ( | Item_result_field * | owner, |
Item_result | type | ||
) |
void Arg_comparator::set_datetime_cmp_func | ( | Item_result_field * | owner_arg, |
Item ** | a1, | ||
Item ** | b1 | ||
) |
|
private |
|
inline |
DTCollation Arg_comparator::cmp_collation |
|
private |
|
static |
|
private |
|
private |
|
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.
thd | thread handle. Used to retrieve the SQL mode among other things |
item_arg | the item to retrieve the value from |
cache_arg | a pointer to an Item where we can cache the value from "item_arg". Can be nullptr |
warn_item | if raising an conversion warning, the warning gets the data type and item name from this item |
is_null | whether or not "item_arg" returned SQL NULL |
|
inlineprivate |
|
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.
|
private |
|
private |
|
private |
|
private |
String Arg_comparator::value1 |
String Arg_comparator::value2 |