MySQL 9.0.0
Source Code Documentation
|
Enumerations | |
enum | Range_placement { RP_OUTSIDE_HIGH , RP_OUTSIDE_LOW , RP_ON_MIN , RP_ON_MAX , RP_INSIDE , RP_INSIDE_TRUNCATED , RP_INSIDE_YEAR_HOLE , RP_ROUNDED_DOWN , RP_ROUNDED_UP } |
fold_condition uses analyze_field_constant to analyze constants in comparisons expressions with a view to fold the expression. More... | |
Functions | |
static bool | round_fold_or_convert_dec (THD *thd, Item **const_val, Range_placement *place, Item_field *f, my_decimal *d, bool up, bool *discount_equal) |
Minion of analyze_int_field_constant. More... | |
static bool | fold_or_convert_dec (THD *thd, Item **const_val, Range_placement *place, Item_field *f, my_decimal *d) |
Minion of analyze_int_field_constant. More... | |
static bool | analyze_int_field_constant (THD *thd, Item_field *f, Item **const_val, Item_func::Functype ft, bool left_has_field, Range_placement *place, bool *discount_equal) |
Minion of analyze_field_constant for integer type fields. More... | |
static bool | analyze_decimal_field_constant (THD *thd, const Item_field *f, Item **const_val, Item_func::Functype ft, Range_placement *place, bool *negative) |
Minion of analyze_field_constant for decimal type fields. More... | |
static bool | analyze_real_field_constant (THD *thd, Item_field *f, Item **const_val, Range_placement *place) |
Minion of analyze_field_constant for real type fields. More... | |
static bool | analyze_year_field_constant (THD *thd, Item **const_val, Range_placement *place) |
Minion of analyze_field_constant for YEAR type fields. More... | |
static bool | analyze_timestamp_field_constant (THD *thd, const Item_field *f, Item **const_val, Range_placement *place) |
Minion of analyze_field_constant for TIMESTAMP, DATETIME, DATE fields. More... | |
static bool | analyze_time_field_constant (THD *thd, Item **const_val) |
static bool | analyze_field_constant (THD *thd, Item_field *f, Item **const_val, Item_func *func, bool left_has_field, Range_placement *place, bool *discount_equal, bool *negative) |
Analyze a constant's placement within (or without) the type range of the field f. More... | |
static bool | fold_or_simplify (THD *thd, Item *ref_or_field, Item_func::Functype ft, bool always_true, bool manifest_result, Item **retcond, Item::cond_result *cond_value) |
We have found that the constant's value makes the predicate always true or false (modulo field nullability), so simplify or remove the condition according to this table: More... | |
static bool | fold_arguments (THD *thd, Item_func *func) |
static bool | fold_arguments (THD *thd, Item_cond *cond) |
Call fold_condition on all the conditions's arguments. More... | |
static Range_placement | map_less_to_greater (Range_placement place) |
Switch places of low, high, max and min. More... | |
static bool | adjust_cmp_op (THD *thd, Item_func *func, bool left_has_field, bool inverse, Item *ref_or_field, Item *c, Item **retcond) |
Possibly change comparison operator because we have rounded the constant in some direction. More... | |
static bool | simplify_to_equal (THD *thd, Item *ref_or_field, Item *c, Item **retcond, Item::cond_result *cond_value) |
Replace condition in retcond with "=" (i.e. Item_func_eq) and set cond_value to Item::COND_OK. More... | |
bool | fold_condition (THD *thd, Item *cond, Item **retcond, Item::cond_result *cond_value, bool manifest_result) |
Fold boolean condition {=, <>, >, >=, <, <=, <=>} involving constants and fields (or references to fields), possibly determining if the condition is always true or false based on type range of the field, or possibly simplifying >=, <= to = if constant lies on the range border. More... | |
enum Range_placement |
fold_condition uses analyze_field_constant to analyze constants in comparisons expressions with a view to fold the expression.
The analysis will determine the range characteristic of the constant, as represented by one value of this set. In the simple case, if the constant is within the range of the field to which it is being compared, the value used is RP_INSIDE.
|
static |
Possibly change comparison operator because we have rounded the constant in some direction.
Depending on the case, we change:
< to <= > to >= <= to < >= to >
[in] | thd | session thread |
[in] | func | the comparison operator |
[in] | left_has_field | true if <field> <cmp> <const>, false if inverse |
[in] | inverse | invert the logic |
[in] | ref_or_field | the field or a ref to it |
[in] | c | the constant |
[in,out] | retcond | the resulting condition |
|
static |
Minion of analyze_field_constant for decimal type fields.
Analyze a constant's placement inside (or outside) the type range of the field f. Also normalize the given constant to the type of the field if applicable.
thd | the session context | |
f | the decimal typed field | |
[out] | const_val | a pointer to an item tree pointer containing the constant (at execution time). May be modified if we replace or fold the constant. |
ft | the function type of the comparison | |
[out] | place | the placement of the const_val relative to the range of f |
[out] | negative | true if the constant has a (minus) sign |
|
static |
Analyze a constant's placement within (or without) the type range of the field f.
Also normalize the given constant to the type of the field if applicable.
thd | the session context | |
f | the field | |
[out] | const_val | a pointer to an item tree pointer containing the constant (at execution time). May be modified if we replace or fold the constant. |
func | the function of the comparison | |
left_has_field | the field is the left operand | |
[out] | place | the placement of the const_val relative to the range of f |
[out] | discount_equal | set to true: caller should replace GE with GT or LE with LT. |
[out] | negative | true if the constant (decimal) is has a (minus) sign |
|
static |
Minion of analyze_field_constant for integer type fields.
Analyze a constant's placement within (or without) the type range of the field f. Also normalize the given constant to the type of the field if applicable.
thd | the session context | |
f | the integer typed field | |
[out] | const_val | a pointer to an item tree pointer containing the constant (at execution time). May be modified if we replace or fold the constant. |
ft | the function type of the comparison | |
left_has_field | the field is the left operand | |
[out] | place | the placement of the const_val relative to the range of f |
[out] | discount_equal | set to true: caller should replace GE with GT or LE with LT. |
|
static |
Minion of analyze_field_constant for real type fields.
Analyze a constant's placement within (or without) the type range of the field f. Also normalize the given constant to the type of the field if applicable.
thd | the session context | |
f | the real (FLOAT, DOUBLE) typed field | |
[out] | const_val | a pointer to an item tree pointer containing the constant (at execution time). May be modified if we replace or fold the constant. |
[out] | place | the placement of the const_val relative to |
|
static |
Minion of analyze_field_constant for TIMESTAMP, DATETIME, DATE fields.
Analyze a constant's placement within (or without) the type range of the field f. Also normalize the given constant to the type of the field if applicable.
thd | the session context | |
f | the field | |
[out] | const_val | a pointer to an item tree pointer containing the constant (at execution time). May be modified if we replace or fold the constant. |
[out] | place | the placement of the const_val relative to |
|
static |
Minion of analyze_field_constant for YEAR type fields.
Analyze a constant's placement within (or without) the type range of the field f. Also normalize the given constant to the type of the field if applicable.
thd | the session context | |
[out] | const_val | a pointer to an item tree pointer containing the constant (at execution time). May be modified if we replace or fold the constant. |
[out] | place | the placement of the const_val relative to |
Call fold_condition on all the conditions's arguments.
thd | the session state |
cond | the condition |
bool fold_condition | ( | THD * | thd, |
Item * | cond, | ||
Item ** | retcond, | ||
Item::cond_result * | cond_value, | ||
bool | manifest_result = false |
||
) |
Fold boolean condition {=, <>, >, >=, <, <=, <=>} involving constants and fields (or references to fields), possibly determining if the condition is always true or false based on type range of the field, or possibly simplifying >=, <= to = if constant lies on the range border.
Also fold such conditions if they are present as arguments of other functions in the same way, except there we replace the arguments with manifest FALSE or field <> field to exclude NULLs if the field is nullable, cf. ignore_unknown().
The constants are always converted to constants of the type of the field, no widening of the field type in therefore necessary after this folding for comparison to occur. When converting constants to decimal (when the field is a decimal), the constant will receive the same number of fractional decimals as the field. If decimal constant fraction truncation occurs, the comparison {GT,GE,LT,LE} logic is adjusted to preserve semantics without widening the field's type.
thd | session state | |
cond | the condition to handle | |
[out] | retcond | condition after const removal |
[out] | cond_value | resulting value of the condition
|
manifest_result | For IS NOT NULL on a not nullable item, if true, return item TRUE (1), else remove condition and return COND_TRUE. For cmp items, this is determined by Item_bool_func2::ignore_unknown. |
|
static |
Minion of analyze_int_field_constant.
Analyze decimal d. Convert decimal constant d to int if d has a zero fraction part and is within integer range. If it can't be converted to int, it is out of range, and we set place accordingly. If it has a non-zero fraction part, we fold. Used for = and <>.
[in] | thd | the session context |
[in,out] | const_val | the constant we are folding |
[in,out] | place | the range placement of the constant as analyzed |
[in] | f | the field the constant is being compared to |
[in] | d | the decimal value of the constant |
|
static |
We have found that the constant's value makes the predicate always true or false (modulo field nullability), so simplify or remove the condition according to this table:
always_true == true !top_level_item top_level_item ------------------------------------------ nullable | IF(NULL, NULL, 1) | IS NOT NULL | !nullable | TRUE (1) | COND_TRUE | ------------------------------------------ always_true == false !top_level_item top_level_item ------------------------------------------ nullable | field <> field [*] | COND_FALSE | !nullable | FALSE (0) | COND_FALSE | ------------------------------------------ [*] for the "<=>" operator, we fold to FALSE (0) in this case.
thd | current session context | |
ref_or_field | a field (that is being being compared to a constant) or a ref to such a field. | |
ft | function type | |
always_true | true if the predicate is found to be always true | |
manifest_result | true if we should create an item to represent the truth value (and replace the condition with it) instead of returning nullptr in *cond_value and {Item::COND_TRUE, Item::COND_FALSE} in *cond_value | |
[out] | retcond | a pointer to the condition altered by this method |
[out] | cond_value | the resulting condition value |
|
static |
Switch places of low, high, max and min.
|
static |
Minion of analyze_int_field_constant.
Round up or down decimal d, then convert constant to int if possible. If d has a fraction part, set discount_equal. If it can't be converted to int, it is out of range, and we fold by setting place accordingly.
[in] | thd | the session context |
[in,out] | const_val | the constant we are folding |
[in,out] | place | the range placement of the constant as analyzed |
[in] | f | the field the constant is being compared to |
[in] | d | the decimal value of the constant |
[in] | up | true if we are to round up, else we round down |
[out] | discount_equal | set to true of d has a non-zero fraction part |
|
static |
Replace condition in retcond with "=" (i.e. Item_func_eq) and set cond_value to Item::COND_OK.
thd | session context | |
ref_or_field | the field being compared to a constant in the retcond | |
c | the constant being compared to a field in the retcond | |
[in,out] | retcond | the comparison condition |
[out] | cond_value | the resulting condition value |