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:
39
sql/field.cc
39
sql/field.cc
@@ -1132,6 +1132,20 @@ Field_longstr::pack_sort_string(uchar *to, const SORT_FIELD_ATTR *sort_field)
|
||||
}
|
||||
|
||||
|
||||
bool Field_longstr::val_bool()
|
||||
{
|
||||
DBUG_ASSERT(marked_for_read());
|
||||
THD *thd= get_thd();
|
||||
StringBuffer<STRING_BUFFER_USUAL_SIZE> str;
|
||||
val_str(&str, &str);
|
||||
double res= Converter_strntod_with_warn(thd, Warn_filter(thd),
|
||||
"BOOLEAN",
|
||||
charset(),
|
||||
str.ptr(), str.length()).result();
|
||||
return res != 0.0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@brief
|
||||
Determine the relative position of the field value in a numeric interval
|
||||
@@ -7682,11 +7696,26 @@ double Field_string::val_real(void)
|
||||
const LEX_CSTRING str= to_lex_cstring();
|
||||
return Converter_strntod_with_warn(thd,
|
||||
Warn_filter_string(thd, this),
|
||||
"DOUBLE",
|
||||
Field_string::charset(),
|
||||
str.str, str.length).result();
|
||||
}
|
||||
|
||||
|
||||
bool Field_string::val_bool()
|
||||
{
|
||||
DBUG_ASSERT(marked_for_read());
|
||||
THD *thd= get_thd();
|
||||
const LEX_CSTRING str= to_lex_cstring();
|
||||
double res= Converter_strntod_with_warn(thd,
|
||||
Warn_filter_string(thd, this),
|
||||
"BOOLEAN",
|
||||
Field_string::charset(),
|
||||
str.str, str.length).result();
|
||||
return res != 0.0;
|
||||
}
|
||||
|
||||
|
||||
longlong Field_string::val_int(void)
|
||||
{
|
||||
DBUG_ASSERT(marked_for_read());
|
||||
@@ -8090,7 +8119,7 @@ double Field_varstring::val_real(void)
|
||||
{
|
||||
DBUG_ASSERT(marked_for_read());
|
||||
THD *thd= get_thd();
|
||||
return Converter_strntod_with_warn(thd, Warn_filter(thd),
|
||||
return Converter_strntod_with_warn(thd, Warn_filter(thd), "DOUBLE",
|
||||
Field_varstring::charset(),
|
||||
(const char *) get_data(),
|
||||
get_length()).result();
|
||||
@@ -8702,7 +8731,8 @@ double Field_varstring_compressed::val_real(void)
|
||||
THD *thd= get_thd();
|
||||
String buf;
|
||||
val_str(&buf, &buf);
|
||||
return Converter_strntod_with_warn(thd, Warn_filter(thd), field_charset(),
|
||||
return Converter_strntod_with_warn(thd, Warn_filter(thd), "DOUBLE",
|
||||
field_charset(),
|
||||
buf.ptr(), buf.length()).result();
|
||||
}
|
||||
|
||||
@@ -8926,7 +8956,7 @@ double Field_blob::val_real(void)
|
||||
if (!blob)
|
||||
return 0.0;
|
||||
THD *thd= get_thd();
|
||||
return Converter_strntod_with_warn(thd, Warn_filter(thd),
|
||||
return Converter_strntod_with_warn(thd, Warn_filter(thd), "DOUBLE",
|
||||
Field_blob::charset(),
|
||||
blob, get_length(ptr)).result();
|
||||
}
|
||||
@@ -9394,7 +9424,8 @@ double Field_blob_compressed::val_real(void)
|
||||
THD *thd= get_thd();
|
||||
String buf;
|
||||
val_str(&buf, &buf);
|
||||
return Converter_strntod_with_warn(thd, Warn_filter(thd), field_charset(),
|
||||
return Converter_strntod_with_warn(thd, Warn_filter(thd), "DOUBLE",
|
||||
field_charset(),
|
||||
buf.ptr(), buf.length()).result();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user