1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-34189 Unexpected error on WHERE inet6col

normalize_cond() translated `WHERE col` into `WHERE col<>0`

But the opetator "not equal to 0" does not necessarily exists
for all data types.

For example, the query:

  SELECT * FROM t1 WHERE inet6col;

was translated to:

  SELECT * FROM t1 WHERE inet6col<>0;

which further failed with this error:

  ERROR : Illegal parameter data types inet6 and bigint for operation '<>'

This patch changes the translation from `col<>0` to `col IS TRUE`.
So now
  SELECT * FROM t1 WHERE inet6col;
gets translated to:
  SELECT * FROM t1 WHERE inet6col IS TRUE;

Details:
1. Implementing methods:
   - Field_longstr::val_bool()
   - Field_string::val_bool()
   - Item::val_int_from_val_str()
   If the input contains bad data,
   these methods raise a better error message:
     Truncated incorrect BOOLEAN value
   Before the change, the error was:
     Truncated incorrect DOUBLE value

2. Fixing normalize_cond() to generate Item_func_istrue/Item_func_isfalse
   instances instead of Item_func_ne/Item_func_eq

3. Making Item_func_truth sargable, so it uses the range optimizer.
   Implementing the following methods:
   - get_mm_tree(), get_mm_leaf(), add_key_fields() in Item_func_truth.
   - get_func_mm_tree(), for all Item_func_truth descendants.

4. Implementing the method negated_item() for all Item_func_truth
   descendants, so the negated item has a chance to be sargable:
   For example,
     WHERE NOT col IS NOT FALSE    -- this notation is not sargable
   is now translated to:
     WHERE col IS FALSE            -- this notation is sargable
This commit is contained in:
Alexander Barkov
2024-12-29 12:50:04 +04:00
parent d1ba623677
commit 5a8e6230d7
47 changed files with 1670 additions and 257 deletions

View File

@@ -281,13 +281,16 @@ protected:
// String-to-number converters with automatic warning generation
class Converter_strntod_with_warn: public Converter_strntod
{
const char *m_data_type;
public:
Converter_strntod_with_warn(THD *thd, Warn_filter filter,
const char *data_type,
CHARSET_INFO *cs,
const char *str, size_t length)
:Converter_strntod(cs, str, length)
:Converter_strntod(cs, str, length),
m_data_type(data_type)
{
check_edom_and_truncation(thd, filter, "DOUBLE", cs, str, length);
check_edom_and_truncation(thd, filter, m_data_type, cs, str, length);
}
};
@@ -354,7 +357,7 @@ protected:
double double_from_string_with_check(CHARSET_INFO *cs, const char *cptr,
const char *end) const
{
return Converter_strntod_with_warn(NULL, Warn_filter_all(),
return Converter_strntod_with_warn(NULL, Warn_filter_all(), "DOUBLE",
cs, cptr, end - cptr).result();
}
my_decimal *decimal_from_string_with_check(my_decimal *decimal_value,
@@ -2326,7 +2329,7 @@ public:
uint32 max_data_length() const override;
void make_send_field(Send_field *) override;
bool send(Protocol *protocol) override;
bool val_bool() override;
bool is_varchar_and_in_write_set() const override
{
DBUG_ASSERT(table && table->write_set);
@@ -4145,6 +4148,7 @@ public:
using Field_str::store;
double val_real() override;
longlong val_int() override;
bool val_bool() override;
String *val_str(String *, String *) override;
my_decimal *val_decimal(my_decimal *) override;
int cmp(const uchar *,const uchar *) const override;