summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2020-05-16 10:52:08 +0400
committerAlexander Barkov <bar@mariadb.com>2020-05-16 10:52:08 +0400
commitbf8ae812690a8c20ea17cb5dc24a57be239a8901 (patch)
treee0abd2ff1a154a5b710c9116b35c19b87abf3af3 /sql
parent3f12a5968a56cb5030381a78b313fdb36024c7f9 (diff)
parent3df297271a02ef13babae6ff6a7e47a6bdb7d538 (diff)
downloadmariadb-git-bf8ae812690a8c20ea17cb5dc24a57be239a8901.tar.gz
Merge remote-tracking branch 'origin/10.1' into 10.2
Also, adding 10.2 related changes for MDEV-22579
Diffstat (limited to 'sql')
-rw-r--r--sql/item.h28
-rw-r--r--sql/sql_base.cc22
2 files changed, 36 insertions, 14 deletions
diff --git a/sql/item.h b/sql/item.h
index 1742ff9e23f..4d861623836 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1301,6 +1301,13 @@ public:
a constant expression. Used in the optimizer to propagate basic constants.
*/
virtual bool basic_const_item() const { return 0; }
+ /*
+ Determines if the expression is allowed as
+ a virtual column assignment source:
+ INSERT INTO t1 (vcol) VALUES (10) -> error
+ INSERT INTO t1 (vcol) VALUES (NULL) -> ok
+ */
+ virtual bool vcol_assignment_allowed_value() const { return false; }
/* cloning of constant items (0 if it is not const) */
virtual Item *clone_item(THD *thd) { return 0; }
virtual Item* build_clone(THD *thd, MEM_ROOT *mem_root) { return get_copy(thd, mem_root); }
@@ -2900,6 +2907,7 @@ public:
collation.set(cs, DERIVATION_IGNORABLE, MY_REPERTOIRE_ASCII);
}
enum Type type() const { return NULL_ITEM; }
+ bool vcol_assignment_allowed_value() const { return true; }
bool eq(const Item *item, bool binary_cmp) const { return null_eq(item); }
double val_real();
longlong val_int();
@@ -3082,6 +3090,25 @@ public:
*/
enum enum_indicator_type indicator;
+ bool vcol_assignment_allowed_value() const
+ {
+ switch (state) {
+ case NULL_VALUE:
+ case DEFAULT_VALUE:
+ case IGNORE_VALUE:
+ return true;
+ case NO_VALUE:
+ case INT_VALUE:
+ case REAL_VALUE:
+ case STRING_VALUE:
+ case TIME_VALUE:
+ case LONG_DATA_VALUE:
+ case DECIMAL_VALUE:
+ break;
+ }
+ return false;
+ }
+
/*
A buffer for string and long data values. Historically all allocated
values returned from val_str() were treated as eligible to
@@ -5372,6 +5399,7 @@ public:
(const char *)NULL),
arg(NULL),cached_field(NULL) {}
enum Type type() const { return DEFAULT_VALUE_ITEM; }
+ bool vcol_assignment_allowed_value() const { return arg == NULL; }
bool eq(const Item *item, bool binary_cmp) const;
bool fix_fields(THD *, Item **);
void cleanup();
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 45916220896..765c743aba2 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -8042,10 +8042,8 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
if (table->next_number_field &&
rfield->field_index == table->next_number_field->field_index)
table->auto_increment_field_not_null= TRUE;
- Item::Type type= value->type();
if (rfield->vcol_info &&
- type != Item::DEFAULT_VALUE_ITEM &&
- type != Item::NULL_ITEM &&
+ !value->vcol_assignment_allowed_value() &&
table->s->table_category != TABLE_CATEGORY_TEMPORARY)
{
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
@@ -8289,18 +8287,14 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
value=v++;
if (field->field_index == autoinc_index)
table->auto_increment_field_not_null= TRUE;
- if (field->vcol_info)
+ if (field->vcol_info &&
+ !value->vcol_assignment_allowed_value() &&
+ table->s->table_category != TABLE_CATEGORY_TEMPORARY)
{
- Item::Type type= value->type();
- if (type != Item::DEFAULT_VALUE_ITEM &&
- type != Item::NULL_ITEM &&
- table->s->table_category != TABLE_CATEGORY_TEMPORARY)
- {
- push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
- ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
- ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
- field->field_name, table->s->table_name.str);
- }
+ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
+ ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
+ ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
+ field->field_name, table->s->table_name.str);
}
if (use_value)