Commit f151c5f3 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-34025 Virtual columns do not check assignment cast validity

It was possible to create virtual columns with incompatible
GENERATED ALWAYS expression data types:

  CREATE TABLE t1 (a INT, b POINT GENERATED ALWAYS AS (a));
  CREATE TABLE t1 (a POINT, b INT GENERATED ALWAYS AS (a));

These data type combinations are not allowed in other cases,
e.g. INSERT, UPDATE, SP variable assignment.

Fix:

Disallowing bad combinations of the column data type and its
GENERATED ALWAYS expression data type.
parent f582ea4d
......@@ -5501,5 +5501,12 @@ DROP TABLE t2,t3,t4,t5,t6,t7,t8,t9;
DROP VIEW v2,v3,v4,v5,v6,v7,v8,v9;
DROP TABLE t1;
#
# MDEV-34025 Virtual columns do not check assignment cast validity
#
CREATE TABLE t1 (a INT, b POINT GENERATED ALWAYS AS (a));
ERROR HY000: Cannot cast 'int' as 'point' in assignment of `test`.`t1`.`b`
CREATE TABLE t1 (a POINT, b INT GENERATED ALWAYS AS (a));
ERROR HY000: Cannot cast 'point' as 'int' in assignment of `test`.`t1`.`b`
#
# End of 11.5 tests
#
......@@ -3499,6 +3499,18 @@ DROP TABLE t2,t3,t4,t5,t6,t7,t8,t9;
DROP VIEW v2,v3,v4,v5,v6,v7,v8,v9;
DROP TABLE t1;
--echo #
--echo # MDEV-34025 Virtual columns do not check assignment cast validity
--echo #
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CREATE TABLE t1 (a INT, b POINT GENERATED ALWAYS AS (a));
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CREATE TABLE t1 (a POINT, b INT GENERATED ALWAYS AS (a));
--echo #
--echo # End of 11.5 tests
--echo #
......@@ -1237,7 +1237,9 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table,
Set table->map to non-zero temporarily.
*/
table->map= 1;
if (vcol && field_ptr[0]->check_vcol_sql_mode_dependency(thd, mode))
if (vcol &&
(field_ptr[0]->check_vcol_sql_mode_dependency(thd, mode) ||
vcol->expr->check_assignability_to(field_ptr[0], false)))
{
DBUG_ASSERT(thd->is_error());
*error_reported= true;
......
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