Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/10.4' into 10.5
Browse files Browse the repository at this point in the history
  • Loading branch information
abarkov committed May 19, 2020
2 parents 3ea05d0 + 810b7f8 commit 49b29e3
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 100 deletions.
11 changes: 11 additions & 0 deletions mysql-test/main/table_value_constr.result
Expand Up @@ -2610,3 +2610,14 @@ $$
a
0
1
#
# MDEV-21995 Server crashes in Item_field::real_type_handler with table value constructor
#
VALUES (IGNORE);
ERROR HY000: 'ignore' is not allowed in this context
VALUES (DEFAULT);
ERROR HY000: 'default' is not allowed in this context
EXECUTE IMMEDIATE 'VALUES (?)' USING IGNORE;
ERROR HY000: 'ignore' is not allowed in this context
EXECUTE IMMEDIATE 'VALUES (?)' USING DEFAULT;
ERROR HY000: 'default' is not allowed in this context
14 changes: 14 additions & 0 deletions mysql-test/main/table_value_constr.test
Expand Up @@ -1339,3 +1339,17 @@ BEGIN NOT ATOMIC
END;
$$
DELIMITER ;$$


--echo #
--echo # MDEV-21995 Server crashes in Item_field::real_type_handler with table value constructor
--echo #

--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
VALUES (IGNORE);
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
VALUES (DEFAULT);
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
EXECUTE IMMEDIATE 'VALUES (?)' USING IGNORE;
--error ER_NOT_ALLOWED_IN_THIS_CONTEXT
EXECUTE IMMEDIATE 'VALUES (?)' USING DEFAULT;
107 changes: 30 additions & 77 deletions sql/item.cc
Expand Up @@ -99,6 +99,13 @@ void item_init(void)
}


void Item::raise_error_not_evaluable()
{
Item::Print tmp(this, QT_ORDINARY);
my_error(ER_NOT_ALLOWED_IN_THIS_CONTEXT, MYF(0), tmp.ptr());
}


void Item::push_note_converted_to_negative_complement(THD *thd)
{
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_UNKNOWN_ERROR,
Expand Down Expand Up @@ -4298,6 +4305,23 @@ int Item_param::save_in_field(Field *field, bool no_conversions)
}


bool Item_param::is_evaluable_expression() const
{
switch (state) {
case SHORT_DATA_VALUE:
case LONG_DATA_VALUE:
case NULL_VALUE:
return true;
case NO_VALUE:
return true; // Not assigned yet, so we don't know
case IGNORE_VALUE:
case DEFAULT_VALUE:
break;
}
return false;
}


bool Item_param::can_return_value() const
{
// There's no "default". See comments in Item_param::save_in_field().
Expand Down Expand Up @@ -9229,12 +9253,7 @@ bool Item_default_value::fix_fields(THD *thd, Item **items)
Item_field *field_arg;
Field *def_field;
DBUG_ASSERT(fixed == 0);

if (!arg)
{
fixed= 1;
return FALSE;
}
DBUG_ASSERT(arg);

/*
DEFAULT() do not need table field so should not ask handler to bring
Expand Down Expand Up @@ -9309,11 +9328,7 @@ void Item_default_value::cleanup()

void Item_default_value::print(String *str, enum_query_type query_type)
{
if (!arg)
{
str->append(STRING_WITH_LEN("default"));
return;
}
DBUG_ASSERT(arg);
str->append(STRING_WITH_LEN("default("));
/*
We take DEFAULT from a field so do not need it value in case of const
Expand All @@ -9327,6 +9342,7 @@ void Item_default_value::print(String *str, enum_query_type query_type)

void Item_default_value::calculate()
{
DBUG_ASSERT(arg);
if (field->default_value)
field->set_default();
DEBUG_SYNC(field->table->in_use, "after_Item_default_value_calculate");
Expand Down Expand Up @@ -9370,14 +9386,8 @@ bool Item_default_value::send(Protocol *protocol, st_value *buffer)

int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
{
if (arg)
{
calculate();
return Item_field::save_in_field(field_arg, no_conversions);
}

return field_arg->save_in_field_default_value(context->error_processor ==
&view_error_processor);
calculate();
return Item_field::save_in_field(field_arg, no_conversions);
}

table_map Item_default_value::used_tables() const
Expand All @@ -9398,13 +9408,7 @@ Item *Item_default_value::transform(THD *thd, Item_transformer transformer,
uchar *args)
{
DBUG_ASSERT(!thd->stmt_arena->is_stmt_prepare());

/*
If the value of arg is NULL, then this object represents a constant,
so further transformation is unnecessary (and impossible).
*/
if (!arg)
return 0;
DBUG_ASSERT(arg);

Item *new_item= arg->transform(thd, transformer, args);
if (!new_item)
Expand All @@ -9421,57 +9425,6 @@ Item *Item_default_value::transform(THD *thd, Item_transformer transformer,
return (this->*transformer)(thd, args);
}

void Item_ignore_value::print(String *str, enum_query_type query_type)
{
str->append(STRING_WITH_LEN("ignore"));
}

int Item_ignore_value::save_in_field(Field *field_arg, bool no_conversions)
{
return field_arg->save_in_field_ignore_value(context->error_processor ==
&view_error_processor);
}

String *Item_ignore_value::val_str(String *str)
{
DBUG_ASSERT(0); // never should be called
null_value= 1;
return 0;
}

double Item_ignore_value::val_real()
{
DBUG_ASSERT(0); // never should be called
null_value= 1;
return 0.0;
}

longlong Item_ignore_value::val_int()
{
DBUG_ASSERT(0); // never should be called
null_value= 1;
return 0;
}

my_decimal *Item_ignore_value::val_decimal(my_decimal *decimal_value)
{
DBUG_ASSERT(0); // never should be called
null_value= 1;
return 0;
}

bool Item_ignore_value::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)
{
DBUG_ASSERT(0); // never should be called
null_value= 1;
return TRUE;
}

bool Item_ignore_value::send(Protocol *protocol, st_value *buffer)
{
DBUG_ASSERT(0); // never should be called
return TRUE;
}

bool Item_insert_value::eq(const Item *item, bool binary_cmp) const
{
Expand Down

0 comments on commit 49b29e3

Please sign in to comment.