Commit 7d9ba57d authored by Nikita Malyavin's avatar Nikita Malyavin

[1/2] MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols

This is a 10.2+ part of a jira task

The two bugs regarding virtual column marking have been fixed:

1. UPDATE of a partitioned table, where the optimizer has chosen a
 secondary index to make a filesort;
2. INSERT into a table with a nonblob field generated from a blob, with
 binlog enabled and binlog_row_image=noblob.

3. DELETE from a view on a table with virtual column.

Generally the assertion happens from update_virtual_fields() call

These bugs are root-caused by missing field marking for dependant fields
of a virtual column.

Therefore a fix is: mark all the fields involved in the vcol expression by
calling field->register_field_in_read_map() instead just setting a single
bit.

3 was reproducible only on 10.4+, however the problem might has just been
invisible in the earlier versions. The fix is applicable to 10.2-10.3 as
well.
parent 0e9ba176
......@@ -153,3 +153,19 @@ CHECK TABLE t EXTENDED;
FLUSH TABLES;
CHECK TABLE t EXTENDED;
DROP TABLE t;
--echo #
--echo # MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
--echo #
CREATE TABLE t1 (
a INT,
b INT,
c BIT(4) NOT NULL DEFAULT b'0',
pk INTEGER AUTO_INCREMENT,
d BIT(4) AS (c) VIRTUAL,
PRIMARY KEY(pk),
KEY (b,d)
) PARTITION BY HASH(pk);
INSERT INTO t1 () VALUES (),();
UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk;
DROP TABLE t1;
......@@ -221,3 +221,32 @@ select * from t1;
drop view v1;
drop table t1;
--echo #
--echo # MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
--echo #
CREATE TABLE t1 (d DATETIME(3), v DATETIME(2) AS (d));
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 (d) VALUES ('2004-04-19 15:37:39.123'),
('1985-12-24 10:15:08.456');
DELETE FROM v1 ORDER BY v LIMIT 4;
# Cleanup
DROP VIEW v1;
DROP TABLE t1;
--echo #
--echo # [duplicate] MDEV-19306 Assertion `marked_for_read()' failed in
--echo # Field_blob::val_str with virtual columns and views
--echo #
CREATE TABLE t1 (a BLOB, b TEXT AS (a) VIRTUAL);
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 (a) VALUES ('foo'),('bar');
DELETE FROM v1 ORDER BY b LIMIT 2;
# Cleanup
DROP VIEW v1;
DROP TABLE t1;
......@@ -89,6 +89,21 @@ Table Op Msg_type Msg_text
test.t check status OK
DROP TABLE t;
#
# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
#
CREATE TABLE t1 (
a INT,
b INT,
c BIT(4) NOT NULL DEFAULT b'0',
pk INTEGER AUTO_INCREMENT,
d BIT(4) AS (c) VIRTUAL,
PRIMARY KEY(pk),
KEY (b,d)
) PARTITION BY HASH(pk);
INSERT INTO t1 () VALUES (),();
UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk;
DROP TABLE t1;
#
# MDEV-16980 Wrongly set tablename len while opening the
# table for purge thread
#
......
......@@ -86,6 +86,21 @@ CHECK TABLE t EXTENDED;
Table Op Msg_type Msg_text
test.t check status OK
DROP TABLE t;
#
# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
#
CREATE TABLE t1 (
a INT,
b INT,
c BIT(4) NOT NULL DEFAULT b'0',
pk INTEGER AUTO_INCREMENT,
d BIT(4) AS (c) VIRTUAL,
PRIMARY KEY(pk),
KEY (b,d)
) PARTITION BY HASH(pk);
INSERT INTO t1 () VALUES (),();
UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk;
DROP TABLE t1;
DROP VIEW IF EXISTS v1,v2;
DROP TABLE IF EXISTS t1,t2,t3;
DROP PROCEDURE IF EXISTS p1;
......
......@@ -271,6 +271,26 @@ a b c
1 -1 -1
drop view v1;
drop table t1;
#
# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
#
CREATE TABLE t1 (d DATETIME(3), v DATETIME(2) AS (d));
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 (d) VALUES ('2004-04-19 15:37:39.123'),
('1985-12-24 10:15:08.456');
DELETE FROM v1 ORDER BY v LIMIT 4;
DROP VIEW v1;
DROP TABLE t1;
#
# [duplicate] MDEV-19306 Assertion `marked_for_read()' failed in
# Field_blob::val_str with virtual columns and views
#
CREATE TABLE t1 (a BLOB, b TEXT AS (a) VIRTUAL);
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 (a) VALUES ('foo'),('bar');
DELETE FROM v1 ORDER BY b LIMIT 2;
DROP VIEW v1;
DROP TABLE t1;
DROP VIEW IF EXISTS v1,v2;
DROP TABLE IF EXISTS t1,t2,t3;
DROP PROCEDURE IF EXISTS p1;
......
......@@ -271,6 +271,26 @@ a b c
1 -1 -1
drop view v1;
drop table t1;
#
# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
#
CREATE TABLE t1 (d DATETIME(3), v DATETIME(2) AS (d));
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 (d) VALUES ('2004-04-19 15:37:39.123'),
('1985-12-24 10:15:08.456');
DELETE FROM v1 ORDER BY v LIMIT 4;
DROP VIEW v1;
DROP TABLE t1;
#
# [duplicate] MDEV-19306 Assertion `marked_for_read()' failed in
# Field_blob::val_str with virtual columns and views
#
CREATE TABLE t1 (a BLOB, b TEXT AS (a) VIRTUAL);
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 (a) VALUES ('foo'),('bar');
DELETE FROM v1 ORDER BY b LIMIT 2;
DROP VIEW v1;
DROP TABLE t1;
DROP VIEW IF EXISTS v1,v2;
DROP TABLE IF EXISTS t1,t2,t3;
DROP PROCEDURE IF EXISTS p1;
......
......@@ -80,4 +80,18 @@ Warnings:
Warning 1265 Data truncated for column 'b' at row 1
Warning 1265 Data truncated for column 'b' at row 2
DROP TABLE t1;
#
# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
#
SET SESSION binlog_row_image= noblob;
CREATE TEMPORARY TABLE t1 SELECT UUID();
show create table t1;
Table Create Table
t1 CREATE TEMPORARY TABLE `t1` (
`UUID()` varchar(36) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE t2 (a INT PRIMARY KEY, b TEXT, c INT GENERATED ALWAYS AS(b));
INSERT INTO t2 (a,b) VALUES (1,1);
SET SESSION binlog_row_image= default;
DROP TABLE t2;
include/rpl_end.inc
......@@ -66,4 +66,18 @@ UPDATE IGNORE t1 SET a = NULL;
DROP TABLE t1;
--echo #
--echo # MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
--echo #
SET SESSION binlog_row_image= noblob;
CREATE TEMPORARY TABLE t1 SELECT UUID();
show create table t1;
CREATE TABLE t2 (a INT PRIMARY KEY, b TEXT, c INT GENERATED ALWAYS AS(b));
INSERT INTO t2 (a,b) VALUES (1,1);
SET SESSION binlog_row_image= default;
DROP TABLE t2;
--source include/rpl_end.inc
......@@ -5255,8 +5255,7 @@ int ha_partition::index_init(uint inx, bool sorted)
do
{
for (i= 0; i < (*key_info)->user_defined_key_parts; i++)
bitmap_set_bit(table->read_set,
(*key_info)->key_part[i].field->field_index);
(*key_info)->key_part[i].field->register_field_in_read_map();
} while (*(++key_info));
}
for (i= bitmap_get_first_set(&m_part_info->read_partitions);
......
......@@ -5839,7 +5839,7 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
{
TABLE *table= field_to_set->table;
if (thd->mark_used_columns == MARK_COLUMNS_READ)
bitmap_set_bit(table->read_set, field_to_set->field_index);
field_to_set->register_field_in_read_map();
else
bitmap_set_bit(table->write_set, field_to_set->field_index);
}
......
......@@ -6717,7 +6717,7 @@ void TABLE::mark_columns_per_binlog_row_image()
if ((my_field->flags & PRI_KEY_FLAG) ||
(my_field->type() != MYSQL_TYPE_BLOB))
{
bitmap_set_bit(read_set, my_field->field_index);
my_field->register_field_in_read_map();
bitmap_set_bit(rpl_write_set, my_field->field_index);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment