1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-23597 Assertion `marked_for_read()' failed while evaluating DEFAULT

The columns that are part of DEFAULT expression were not read-marked
in statements like UPDATE...SET b=DEFAULT.

The problem is `F(DEFAULT)` expression depends of the left-hand side of an
assignment. However, setup_fields accepts only right-hand side value.
Neither Item::fix_fields does.

Suchwise, b=DEFAULT(b) works fine, because Item_default_field has
information on what field it is default of:
    if (thd->mark_used_columns != MARK_COLUMNS_NONE)
      def_field->default_value->expr->update_used_tables();

in Item_default_value::fix_fields().

It is not reasonable to pass a left-hand side to Item:fix_fields, because
the case is rare, so the rewrite
  b= F(DEFAULT)  ->  b= F(DEFAULT(b))

is made instead.

Both UPDATE and multi-UPDATE are affected, however any form of INSERT
is not: it marks all the fields in DEFAULT expressions for read in
TABLE::mark_default_fields_for_write().
This commit is contained in:
Nikita Malyavin
2021-06-26 20:11:56 +03:00
parent 6a89f346de
commit c47e4aab62
11 changed files with 111 additions and 10 deletions

View File

@ -370,6 +370,8 @@ int mysql_update(THD *thd,
DBUG_RETURN(1);
}
setup_defaults(thd, fields, values);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
/* Check values */
table_list->grant.want_privilege= table->grant.want_privilege=
@ -1749,6 +1751,8 @@ int multi_update::prepare(List<Item> &not_used_values,
}
}
setup_defaults(thd, *fields, *values);
/*
We have to check values after setup_tables to get covering_keys right in
reference tables