Commit 980aa3e7 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-16888 Add virtual Type_handler::cond_notnull_field_isnull_to_field_eq_zero()

parent 8ecc7537
...@@ -2518,9 +2518,8 @@ class Item_func_isnull :public Item_func_null_predicate ...@@ -2518,9 +2518,8 @@ class Item_func_isnull :public Item_func_null_predicate
{ {
Field *field=((Item_field*) args[0]->real_item())->field; Field *field=((Item_field*) args[0]->real_item())->field;
if (((field->type() == MYSQL_TYPE_DATE) || if ((field->flags & NOT_NULL_FLAG) &&
(field->type() == MYSQL_TYPE_DATETIME)) && field->type_handler()->cond_notnull_field_isnull_to_field_eq_zero())
(field->flags & NOT_NULL_FLAG))
return true; return true;
} }
return false; return false;
......
...@@ -16360,9 +16360,8 @@ Item_func_isnull::remove_eq_conds(THD *thd, Item::cond_result *cond_value, ...@@ -16360,9 +16360,8 @@ Item_func_isnull::remove_eq_conds(THD *thd, Item::cond_result *cond_value,
{ {
Field *field= ((Item_field*) real_item)->field; Field *field= ((Item_field*) real_item)->field;
if (((field->type() == MYSQL_TYPE_DATE) || if ((field->flags & NOT_NULL_FLAG) &&
(field->type() == MYSQL_TYPE_DATETIME)) && field->type_handler()->cond_notnull_field_isnull_to_field_eq_zero())
(field->flags & NOT_NULL_FLAG))
{ {
/* fix to replace 'NULL' dates with '0' (shreeve@uci.edu) */ /* fix to replace 'NULL' dates with '0' (shreeve@uci.edu) */
/* /*
......
...@@ -1399,6 +1399,17 @@ class Type_handler ...@@ -1399,6 +1399,17 @@ class Type_handler
{ {
return false; return false;
} }
/*
Returns true if this data type supports a hack that
WHERE notnull_column IS NULL
finds zero values, e.g.:
WHERE date_notnull_column IS NULL ->
WHERE date_notnull_column = '0000-00-00'
*/
virtual bool cond_notnull_field_isnull_to_field_eq_zero() const
{
return false;
}
/** /**
Check whether a field type can be partially indexed by a key. Check whether a field type can be partially indexed by a key.
@param type field type @param type field type
...@@ -3344,6 +3355,10 @@ class Type_handler_date_common: public Type_handler_temporal_with_date ...@@ -3344,6 +3355,10 @@ class Type_handler_date_common: public Type_handler_temporal_with_date
{ {
return MYSQL_TIMESTAMP_DATE; return MYSQL_TIMESTAMP_DATE;
} }
bool cond_notnull_field_isnull_to_field_eq_zero() const
{
return true;
}
Item_literal *create_literal_item(THD *thd, const char *str, size_t length, Item_literal *create_literal_item(THD *thd, const char *str, size_t length,
CHARSET_INFO *cs, bool send_error) const; CHARSET_INFO *cs, bool send_error) const;
Item *create_typecast_item(THD *thd, Item *item, Item *create_typecast_item(THD *thd, Item *item,
...@@ -3425,6 +3440,10 @@ class Type_handler_datetime_common: public Type_handler_temporal_with_date ...@@ -3425,6 +3440,10 @@ class Type_handler_datetime_common: public Type_handler_temporal_with_date
{ {
return MYSQL_TIMESTAMP_DATETIME; return MYSQL_TIMESTAMP_DATETIME;
} }
bool cond_notnull_field_isnull_to_field_eq_zero() const
{
return true;
}
Item *create_typecast_item(THD *thd, Item *item, Item *create_typecast_item(THD *thd, Item *item,
const Type_cast_attributes &attr) const; const Type_cast_attributes &attr) const;
void Column_definition_implicit_upgrade(Column_definition *c) const; void Column_definition_implicit_upgrade(Column_definition *c) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment