Skip to content

Commit

Permalink
MDEV-26262 frm is corrupted after ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
Browse files Browse the repository at this point in the history
This is a duplicate of MDEV-18278 89936f1, but I will add an
additional assertion

Description:

The frm corruption should not be reported during CREATE TABLE. Normally
it doesn't, and the data to fill TABLE is taken by open_table_from_share
call. However, the vcol data is stored as SQL string in
table->s->vcol_defs.str and is anyway parsed on each table open.
It is impossible [or hard] to avoid, because it's hard to clone the
expression tree in general (it's easier to parse).

Normally parse_vcol_defs should only fail on semantic errors. If so,
error_reported is set to true. Any other failure is not expected during
table creation. There is either unhandled/unacknowledged error, or
something went really wrong, like memory reject. This all should be
asserted anyway.

Solution:
* Set *error_reported=true for the forward references check;
* Assert for every unacknowledged error during table creation.
  • Loading branch information
FooBarrior committed Oct 20, 2021
1 parent a8401ad commit 1811fd5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mysql-test/suite/gcol/inc/gcol_column_def_options.inc
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,14 @@ ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
--disable_info
DROP TABLE t1;
--enable_warnings

--echo #
--echo # MDEV-26262 frm is corrupted after ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
--echo #

--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
CREATE TABLE MDEV_26262 (a INT,b INT AS (b) VIRTUAL);

--let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err
--let SEARCH_PATTERN=Incorrect information in file: './test/MDEV_26262.frm'
--source include/search_pattern_in_file.inc
6 changes: 6 additions & 0 deletions mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,12 @@ ADD COLUMN c INT AS (1 + DEFAULT(a)) VIRTUAL;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 0
DROP TABLE t1;
#
# MDEV-26262 frm is corrupted after ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
#
CREATE TABLE MDEV_26262 (a INT,b INT AS (b) VIRTUAL);
ERROR 01000: Expression for field `b` is referring to uninitialized field `b`
NOT FOUND /Incorrect information in file: './test/MDEV_26262.frm'/ in mysqld.1.err
DROP VIEW IF EXISTS v1,v2;
DROP TABLE IF EXISTS t1,t2,t3;
DROP PROCEDURE IF EXISTS p1;
Expand Down
6 changes: 6 additions & 0 deletions mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,12 @@ ADD COLUMN c INT AS (1 + DEFAULT(a)) VIRTUAL;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 0
DROP TABLE t1;
#
# MDEV-26262 frm is corrupted after ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
#
CREATE TABLE MDEV_26262 (a INT,b INT AS (b) VIRTUAL);
ERROR 01000: Expression for field `b` is referring to uninitialized field `b`
NOT FOUND /Incorrect information in file: './test/MDEV_26262.frm'/ in mysqld.1.err
DROP VIEW IF EXISTS v1,v2;
DROP TABLE IF EXISTS t1,t2,t3;
DROP PROCEDURE IF EXISTS p1;
Expand Down
3 changes: 3 additions & 0 deletions sql/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,9 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
&error_reported, mode))
{
error= OPEN_FRM_CORRUPTED;
// parse_vcol_defs may fail by semantic reasons, which is ok, but the
// real corruption should never be reported during table creation
DBUG_ASSERT(!is_create_table || !error_reported);
goto err;
}

Expand Down

0 comments on commit 1811fd5

Please sign in to comment.