Skip to content

Commit

Permalink
MDEV-25872 InnoDB: Assertion failure in row_merge_read_clustered_inde…
Browse files Browse the repository at this point in the history
…x upon ALTER on table with indexed virtual columns

- InnoDB fails to check DB_COMPUTE_VALUE_FAILED error in
row_merge_read_clustered_index() and wrongly asserts that
the buffer shouldn't be ran out of memory. Alter table
should give warning when the column value is being
truncated.
  • Loading branch information
Thirunarayanan committed Jun 15, 2021
1 parent 8c7d8b7 commit 7229107
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 16 deletions.
2 changes: 2 additions & 0 deletions mysql-test/suite/gcol/r/gcol_keys_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ a b c
1 127 0
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
ALTER TABLE t ADD UNIQUE INDEX (c(1));
Warnings:
Warning 1264 Out of range value for column 'b' at row 1
SELECT * FROM t WHERE c = '0';
a b c
1 127 0
Expand Down
20 changes: 20 additions & 0 deletions mysql-test/suite/gcol/r/innodb_virtual_index.result
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,23 @@ CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1;
#
# MDEV-25872 InnoDB: Assertion failure in row_merge_read_clustered_index
# upon ALTER on table with indexed virtual columns
#
CREATE TABLE t1 (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
a INT,
va INT ZEROFILL AS (a) VIRTUAL,
b TIMESTAMP,
c CHAR(204),
vc CHAR(8),
KEY(vc,c(64),b,va)
) ENGINE=InnoDB CHARACTER SET utf32;
INSERT INTO t1 (id) SELECT NULL FROM seq_1_to_75;
INSERT IGNORE INTO t1 (id, a) VALUES (NULL, -1);
Warnings:
Warning 1264 Out of range value for column 'va' at row 1
ALTER TABLE t1 FORCE;
ERROR 22003: Out of range value for column 'va' at row 1
DROP TABLE t1;
1 change: 1 addition & 0 deletions mysql-test/suite/gcol/t/innodb_virtual_index.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--innodb_sort_buffer_size=64k
21 changes: 21 additions & 0 deletions mysql-test/suite/gcol/t/innodb_virtual_index.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
--source include/have_innodb.inc
--source include/have_sequence.inc

# Ensure that the history list length will actually be decremented by purge.
SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency;
Expand Down Expand Up @@ -281,3 +282,23 @@ ROLLBACK;
SELECT * FROM t1;
CHECK TABLE t1;
DROP TABLE t1;

--echo #
--echo # MDEV-25872 InnoDB: Assertion failure in row_merge_read_clustered_index
--echo # upon ALTER on table with indexed virtual columns
--echo #

CREATE TABLE t1 (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
a INT,
va INT ZEROFILL AS (a) VIRTUAL,
b TIMESTAMP,
c CHAR(204),
vc CHAR(8),
KEY(vc,c(64),b,va)
) ENGINE=InnoDB CHARACTER SET utf32;
INSERT INTO t1 (id) SELECT NULL FROM seq_1_to_75;
INSERT IGNORE INTO t1 (id, a) VALUES (NULL, -1);
--error ER_WARN_DATA_OUT_OF_RANGE
ALTER TABLE t1 FORCE;
DROP TABLE t1;
8 changes: 6 additions & 2 deletions mysql-test/suite/innodb/r/innodb-alter.result
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,9 @@ CREATE TABLE t1 (a INT NOT NULL DEFAULT 0) ENGINE=InnoDB;
iNSERT INTO t1 VALUES (10);
ALTER TABLE t1 ADD b DATE NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001-01-01 10:20:30',0);
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
info: Records: 0 Duplicates: 0 Warnings: 1
Warnings:
Note 1265 Data truncated for column 'b' at row 1
SELECT * FROM t1;
a b
10 2001-01-01
Expand All @@ -1050,7 +1052,9 @@ CREATE TABLE t1 (a INT NOT NULL DEFAULT 0) ENGINE=InnoDB;
iNSERT INTO t1 VALUES (10);
ALTER TABLE t1 ADD b TIME NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001-01-01 10:20:30',0);
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
info: Records: 0 Duplicates: 0 Warnings: 1
Warnings:
Note 1265 Data truncated for column 'b' at row 1
SELECT * FROM t1;
a b
10 10:20:30
Expand Down
8 changes: 8 additions & 0 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9680,9 +9680,17 @@ do_continue:;
if (use_inplace)
{
table->s->frm_image= &frm;
enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
/*
Set the truncated column values of thd as warning for alter table.
*/
thd->count_cuted_fields= CHECK_FIELD_WARN;
int res= mysql_inplace_alter_table(thd, table_list, table, altered_table,
&ha_alter_info, inplace_supported,
&target_mdl_request, &alter_ctx);

thd->count_cuted_fields= save_count_cuted_fields;

my_free(const_cast<uchar*>(frm.str));

if (res)
Expand Down
27 changes: 13 additions & 14 deletions storage/innobase/row/row0merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ row_merge_buf_add(
DBUG_ENTER("row_merge_buf_add");

if (buf->n_tuples >= buf->max_tuples) {
DBUG_RETURN(0);
error:
n_row_added = 0;
goto end;
}

DBUG_EXECUTE_IF(
Expand Down Expand Up @@ -845,11 +847,6 @@ row_merge_buf_add(
if (vcol_storage.innobase_record)
innobase_free_row_for_vcol(&vcol_storage);
DBUG_RETURN(n_row_added);

error:
if (vcol_storage.innobase_record)
innobase_free_row_for_vcol(&vcol_storage);
DBUG_RETURN(0);
}

/*************************************************************//**
Expand Down Expand Up @@ -2567,16 +2564,18 @@ row_merge_read_clustered_index(
new_table, psort_info, row, ext,
&doc_id, conv_heap,
&err, &v_heap, eval_table, trx)))) {
/* An empty buffer should have enough
room for at least one record. */
ut_error;
}

if (err != DB_SUCCESS) {
break;
/* An empty buffer should have enough
room for at least one record. */
ut_ad(err == DB_COMPUTE_VALUE_FAILED
|| err == DB_OUT_OF_MEMORY
|| err == DB_TOO_BIG_RECORD);
} else if (err == DB_SUCCESS) {
file->n_rec += rows_added;
continue;
}

file->n_rec += rows_added;
trx->error_key_num = i;
break;
}
}

Expand Down

0 comments on commit 7229107

Please sign in to comment.