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

@@ -264,6 +264,19 @@ public:
bool fix_length_and_dec(THD *thd) override;
void print(String *str, enum_query_type query_type) override;
enum precedence precedence() const override { return CMP_PRECEDENCE; }
bool count_sargable_conds(void *arg) override;
SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param, Item **cond_ptr) override;
SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param, Field *field,
KEY_PART *key_part,
Item_func::Functype type, Item *value) override;
void add_key_fields(JOIN *join, KEY_FIELD **key_fields,
uint *and_level, table_map usable_tables,
SARGABLE_PARAM **sargables) override;
virtual Item *negated_item(THD *thd) const = 0;
Item *neg_transformer(THD *thd) override
{
return negated_item(thd);
}
protected:
Item_func_truth(THD *thd, Item *a, bool a_value, bool a_affirmative):
@@ -298,6 +311,9 @@ public:
static LEX_CSTRING name= {STRING_WITH_LEN("istrue") };
return name;
}
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
Field *field, Item *value) override;
Item *negated_item(THD *thd) const override;
Item *do_get_copy(THD *thd) const override
{ return get_item_copy<Item_func_istrue>(thd, this); }
};
@@ -318,6 +334,9 @@ public:
static LEX_CSTRING name= {STRING_WITH_LEN("isnottrue") };
return name;
}
Item *negated_item(THD *thd) const override;
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
Field *field, Item *value) override;
bool find_not_null_fields(table_map allowed) override { return false; }
Item *do_get_copy(THD *thd) const override
{ return get_item_copy<Item_func_isnottrue>(thd, this); }
@@ -340,6 +359,9 @@ public:
static LEX_CSTRING name= {STRING_WITH_LEN("isfalse") };
return name;
}
Item *negated_item(THD *thd) const override;
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
Field *field, Item *value) override;
Item *do_get_copy(THD *thd) const override
{ return get_item_copy<Item_func_isfalse>(thd, this); }
};
@@ -360,7 +382,10 @@ public:
static LEX_CSTRING name= {STRING_WITH_LEN("isnotfalse") };
return name;
}
Item *negated_item(THD *thd) const override;
bool find_not_null_fields(table_map allowed) override { return false; }
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
Field *field, Item *value) override;
Item *do_get_copy(THD *thd) const override
{ return get_item_copy<Item_func_isnotfalse>(thd, this); }
bool eval_not_null_tables(void *) override