Skip to content

Commit fbde720

Browse files
committed
Bug#22018999: gcols: assertion failed: !error
This problem occurs because we have inconsistent handling of evaluation of various errors when evaluating constant expressions in generated columns: Sometimes such errors are reported as errors, sometimes they are converted to warnings. In strict mode, there is no problem because they are consistently reported as errors. The solution to the problem is to temporarily raise strict mode when checking generated column expressions when creating or altering tables. Note that this is a change of behavior that should be mentioned in manual.
1 parent 66a9355 commit fbde720

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

mysql-test/suite/gcol/r/gcol_bugfixes.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,17 @@ SELECT * FROM t1;
573573
a b c
574574
1 1 11
575575
DROP TABLE t1;
576+
# Bug#22018999: gcols: assertion failed: !error
577+
SET @save_old_sql_mode= @@sql_mode;
578+
SET sql_mode="";
579+
Warnings:
580+
Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
581+
CREATE TABLE t (a INTEGER AS (SUBSTR('','a',1))) engine=innodb;
582+
ERROR 22007: Truncated incorrect INTEGER value: 'a'
583+
CREATE TABLE t (a INTEGER) engine=innodb;
584+
ALTER TABLE t ADD b INTEGER AS (SUBSTR('','a',1));
585+
ERROR 22007: Truncated incorrect INTEGER value: 'a'
586+
DROP TABLE t;
587+
set sql_mode= @save_old_sql_mode;
588+
Warnings:
589+
Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.

mysql-test/suite/gcol/t/gcol_bugfixes.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,20 @@ SELECT * FROM t1;
545545
FLUSH TABLES;
546546
SELECT * FROM t1;
547547
DROP TABLE t1;
548+
549+
--echo # Bug#22018999: gcols: assertion failed: !error
550+
551+
SET @save_old_sql_mode= @@sql_mode;
552+
SET sql_mode="";
553+
554+
--error ER_TRUNCATED_WRONG_VALUE
555+
CREATE TABLE t (a INTEGER AS (SUBSTR('','a',1))) engine=innodb;
556+
557+
CREATE TABLE t (a INTEGER) engine=innodb;
558+
559+
--error ER_TRUNCATED_WRONG_VALUE
560+
ALTER TABLE t ADD b INTEGER AS (SUBSTR('','a',1));
561+
562+
DROP TABLE t;
563+
564+
set sql_mode= @save_old_sql_mode;

sql/table.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,10 @@ static bool unpack_gcol_info_from_frm(THD *thd,
28552855
char *gcol_expr_str;
28562856
int str_len= 0;
28572857
const CHARSET_INFO *old_character_set_client;
2858+
bool disable_strict_mode= false;
2859+
bool status;
2860+
2861+
Strict_error_handler strict_handler;
28582862

28592863
if (!(gcol_expr_str= (char*) alloc_root(&table->mem_root,
28602864
gcol_expr->length +
@@ -2911,8 +2915,23 @@ static bool unpack_gcol_info_from_frm(THD *thd,
29112915
/* From now on use gcol_info generated by the parser. */
29122916
field->gcol_info= thd->lex->gcol_info;
29132917

2918+
/* Use strict mode regardless of strict mode setting when validating */
2919+
if (!thd->is_strict_mode())
2920+
{
2921+
thd->variables.sql_mode|= MODE_STRICT_ALL_TABLES;
2922+
thd->push_internal_handler(&strict_handler);
2923+
disable_strict_mode= true;
2924+
}
2925+
29142926
/* Validate the Item tree. */
2915-
if (fix_fields_gcol_func(thd, field))
2927+
status= fix_fields_gcol_func(thd, field);
2928+
2929+
if (disable_strict_mode)
2930+
{
2931+
thd->pop_internal_handler();
2932+
thd->variables.sql_mode&= ~MODE_STRICT_ALL_TABLES;
2933+
}
2934+
if (status)
29162935
{
29172936
if (is_create_table)
29182937
{

0 commit comments

Comments
 (0)