summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2019-09-28 12:34:57 +0400
committerAlexander Barkov <bar@mariadb.com>2019-09-28 12:34:57 +0400
commitf1dcbc2d9a36b00fad4acee447b5c5066725fa7b (patch)
tree879dbc83932bd069bfb6a9d6469a2746bfed5dec
parent9b5cdeeb0f3fa9540df50d7feec8a703db4777ab (diff)
downloadmariadb-git-f1dcbc2d9a36b00fad4acee447b5c5066725fa7b.tar.gz
MDEV-20639 ASAN SEGV in get_prefix upon modifying base column type with existing indexed virtual column
-rw-r--r--mysql-test/suite/vcol/r/vcol_sql_mode_timestamp.result17
-rw-r--r--mysql-test/suite/vcol/t/vcol_sql_mode_timestamp.test12
-rw-r--r--sql/table.cc9
3 files changed, 38 insertions, 0 deletions
diff --git a/mysql-test/suite/vcol/r/vcol_sql_mode_timestamp.result b/mysql-test/suite/vcol/r/vcol_sql_mode_timestamp.result
index d9a74708477..7c82856717d 100644
--- a/mysql-test/suite/vcol/r/vcol_sql_mode_timestamp.result
+++ b/mysql-test/suite/vcol/r/vcol_sql_mode_timestamp.result
@@ -97,5 +97,22 @@ UPDATE IGNORE t1 SET d = NOW();
DROP TABLE t1;
SET sql_mode=DEFAULT;
#
+# MDEV-20639 ASAN SEGV in get_prefix upon modifying base column type with existing indexed virtual column
+#
+CREATE TABLE t1 (
+a TIMESTAMP,
+b TIMESTAMP AS (a) VIRTUAL,
+KEY (b)
+);
+ALTER TABLE t1 MODIFY a BLOB FIRST;
+Warnings:
+Warning 1901 Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `b`
+Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL
+Warning 1901 Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `b`
+Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL
+Warning 1901 Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `b`
+Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL
+DROP TABLE t1;
+#
# End of 10.4 tests
#
diff --git a/mysql-test/suite/vcol/t/vcol_sql_mode_timestamp.test b/mysql-test/suite/vcol/t/vcol_sql_mode_timestamp.test
index cd7f1125840..4f38da75948 100644
--- a/mysql-test/suite/vcol/t/vcol_sql_mode_timestamp.test
+++ b/mysql-test/suite/vcol/t/vcol_sql_mode_timestamp.test
@@ -106,6 +106,18 @@ UPDATE IGNORE t1 SET d = NOW();
DROP TABLE t1;
SET sql_mode=DEFAULT;
+--echo #
+--echo # MDEV-20639 ASAN SEGV in get_prefix upon modifying base column type with existing indexed virtual column
+--echo #
+
+CREATE TABLE t1 (
+ a TIMESTAMP,
+ b TIMESTAMP AS (a) VIRTUAL,
+ KEY (b)
+);
+ALTER TABLE t1 MODIFY a BLOB FIRST;
+DROP TABLE t1;
+
--echo #
--echo # End of 10.4 tests
diff --git a/sql/table.cc b/sql/table.cc
index e608bdfcf07..718d0dce072 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -1152,12 +1152,21 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table,
vcol= unpack_vcol_info_from_frm(thd, mem_root, table, &expr_str,
&((*field_ptr)->vcol_info), error_reported);
*(vfield_ptr++)= *field_ptr;
+ DBUG_ASSERT(table->map == 0);
+ /*
+ We need Item_field::const_item() to return false, so
+ datetime_precision() and time_precision() do not try to calculate
+ field values, e.g. val_str().
+ Set table->map to non-zero temporarily.
+ */
+ table->map= 1;
if (vcol && field_ptr[0]->check_vcol_sql_mode_dependency(thd, mode))
{
DBUG_ASSERT(thd->is_error());
*error_reported= true;
goto end;
}
+ table->map= 0;
break;
case VCOL_DEFAULT:
vcol= unpack_vcol_info_from_frm(thd, mem_root, table, &expr_str,