From f144ce2cfa086182fbd2b44408c70bd3456408f2 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 5 Jan 2021 11:42:34 +0100 Subject: [PATCH] MDEV-20763 Table corruption or Assertion `btr_validate_index(index, 0, false)' failed in row_upd_sec_index_entry with virtual column and EMPTY_STRING_IS_NULL SQL mode unset empty_string_is_null mode when parsing generated columns in a table, this mode affects pasring. --- mysql-test/main/empty_string_literal.result | 29 +++++++++++++++++++++ mysql-test/main/empty_string_literal.test | 19 ++++++++++++++ sql/table.cc | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/empty_string_literal.result b/mysql-test/main/empty_string_literal.result index 2ca491a7dd8..bbcf27cf993 100644 --- a/mysql-test/main/empty_string_literal.result +++ b/mysql-test/main/empty_string_literal.result @@ -179,3 +179,32 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1003 select NULL AS `NULL` +# +# MDEV-20763 Table corruption or Assertion `btr_validate_index(index, 0, false)' failed in row_upd_sec_index_entry with virtual column and EMPTY_STRING_IS_NULL SQL mode +# +create table t1 (a int, b binary(1) generated always as (''), key(a,b)); +insert into t1 (a) values (1); +set sql_mode= default; +flush tables; +update t1 set a = 2; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` binary(1) GENERATED ALWAYS AS (NULL) VIRTUAL, + KEY `a` (`a`,`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (a int, b binary(1) generated always as (''), key(a,b)); +insert into t1 (a) values (1); +set sql_mode= 'empty_string_is_null'; +flush tables; +update t1 set a = 2; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` binary(1) GENERATED ALWAYS AS ('') VIRTUAL, + KEY `a` (`a`,`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; diff --git a/mysql-test/main/empty_string_literal.test b/mysql-test/main/empty_string_literal.test index 71e98d872bb..9174a7714a2 100644 --- a/mysql-test/main/empty_string_literal.test +++ b/mysql-test/main/empty_string_literal.test @@ -6,3 +6,22 @@ USE test; set @mode='EMPTY_STRING_IS_NULL'; --source include/empty_string_literal.inc + +--echo # +--echo # MDEV-20763 Table corruption or Assertion `btr_validate_index(index, 0, false)' failed in row_upd_sec_index_entry with virtual column and EMPTY_STRING_IS_NULL SQL mode +--echo # +create table t1 (a int, b binary(1) generated always as (''), key(a,b)); +insert into t1 (a) values (1); +set sql_mode= default; +flush tables; +update t1 set a = 2; +show create table t1; +drop table t1; + +create table t1 (a int, b binary(1) generated always as (''), key(a,b)); +insert into t1 (a) values (1); +set sql_mode= 'empty_string_is_null'; +flush tables; +update t1 set a = 2; +show create table t1; +drop table t1; diff --git a/sql/table.cc b/sql/table.cc index 403b68551a0..22cf3357ac7 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1051,7 +1051,7 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table, thd->stmt_arena= table->expr_arena; thd->update_charset(&my_charset_utf8mb4_general_ci, table->s->table_charset); expr_str.append(&parse_vcol_keyword); - thd->variables.sql_mode &= ~MODE_NO_BACKSLASH_ESCAPES; + thd->variables.sql_mode &= ~(MODE_NO_BACKSLASH_ESCAPES | MODE_EMPTY_STRING_IS_NULL); while (pos < end) {