MDEV-34123 CONCAT Function Returns Unexpected Empty Set in Query

Search conditions were evaluated using val_int(), which was wrong.
Fixing the code to use val_bool() instead.

Details:
- Adding a new item_base_t::IS_COND flag which marks Items used
  as <search condition> in WHERE, HAVING, JOIN ON, CASE WHEN clauses.
  The flag is at the parse time.
  These expressions must be evaluated using val_bool() rather than val_int().

  Note, the optimizer creates more Items which are used as search conditions.
  Most of these items are not marked with IS_COND yet. This is OK for now,
  but eventually these Items can also be fixed to have the flag.

- Adding a method Item::is_cond() which tests if the Item has the IS_COND flag.

- Implementing Item_cache_bool. It evaluates the cached expression using
  val_bool() rather than val_int().
  Overriding Type_handler_bool::Item_get_cache() to create Item_cache_bool.

- Implementing Item::save_bool_in_field(). It uses val_bool() rather than
  val_int() to evaluate the expression.

- Implementing Type_handler_bool::Item_save_in_field()
  using Item::save_bool_in_field().

- Fixing all Item_bool_func descendants to implement a virtual val_bool()
  rather than a virtual val_int().

- To find places where val_int() should be fixed to val_bool(), a few
  DBUG_ASSERT(!is_cond()) where added into val_int() implementations
  of selected (most frequent) classes:

  Item_field
  Item_str_func
  Item_datefunc
  Item_timefunc
  Item_datetimefunc
  Item_cache_bool
  Item_bool_func
  Item_func_hybrid_field_type
  Item_basic_constant descendants

- Fixing all places where DBUG_ASSERT() happened during an "mtr" run
  to use val_bool() instead of val_int().
This commit is contained in:
Alexander Barkov 2024-05-14 09:19:34 +04:00 committed by Oleksandr Byelkin
parent 6f6c1911dc
commit a931da82fa
52 changed files with 2098 additions and 151 deletions

View file

@ -1964,6 +1964,11 @@ public:
{
return neg ? -to_seconds_abs() : to_seconds_abs();
}
bool to_bool() const
{
return is_valid_time() &&
(TIME_to_ulonglong_time(this) != 0 || second_part != 0);
}
longlong to_longlong() const
{
if (!is_valid_time())
@ -2324,6 +2329,10 @@ public:
DBUG_ASSERT(is_valid_date_slow());
return Temporal::to_packed();
}
bool to_bool() const
{
return to_longlong() != 0;
}
longlong to_longlong() const
{
return is_valid_date() ? (longlong) TIME_to_ulonglong_date(this) : 0LL;
@ -2629,6 +2638,11 @@ public:
ltime->time_type= type;
return false;
}
bool to_bool() const
{
return is_valid_datetime() &&
(TIME_to_ulonglong_datetime(this) != 0 || second_part != 0);
}
longlong to_longlong() const
{
return is_valid_datetime() ?
@ -2857,6 +2871,10 @@ public:
return Datetime::zero();
return Timestamp::to_datetime(thd);
}
bool to_bool() const
{
return !m_is_zero_datetime;
}
bool is_zero_datetime() const { return m_is_zero_datetime; }
void trunc(uint decimals)
{
@ -5840,6 +5858,9 @@ public:
const Type_handler *type_handler_signed() const override;
void Item_update_null_value(Item *item) const override;
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *) const override;
Item_cache *Item_get_cache(THD *thd, const Item *item) const override;
int Item_save_in_field(Item *item, Field *field, bool no_conversions)
const override;
};