diff options
author | Nikita Malyavin <nikitamalyavin@gmail.com> | 2021-06-21 17:48:45 +0300 |
---|---|---|
committer | Nikita Malyavin <nikitamalyavin@gmail.com> | 2021-07-12 22:00:39 +0300 |
commit | 7d9ba57da4843c05a4d11e63159a961c4eb79a04 (patch) | |
tree | 9f7d76b7961cfdcbdf9eb877c427d23a6e5e2245 | |
parent | 0e9ba176bf2ad4d44e62b8f6e4e1916b39c5bf33 (diff) | |
download | mariadb-git-7d9ba57da4843c05a4d11e63159a961c4eb79a04.tar.gz |
[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.
-rw-r--r-- | mysql-test/suite/gcol/inc/gcol_partition.inc | 16 | ||||
-rw-r--r-- | mysql-test/suite/gcol/inc/gcol_view.inc | 29 | ||||
-rw-r--r-- | mysql-test/suite/gcol/r/gcol_partition_innodb.result | 15 | ||||
-rw-r--r-- | mysql-test/suite/gcol/r/gcol_partition_myisam.result | 15 | ||||
-rw-r--r-- | mysql-test/suite/gcol/r/gcol_view_innodb.result | 20 | ||||
-rw-r--r-- | mysql-test/suite/gcol/r/gcol_view_myisam.result | 20 | ||||
-rw-r--r-- | mysql-test/suite/vcol/r/binlog.result | 14 | ||||
-rw-r--r-- | mysql-test/suite/vcol/t/binlog.test | 14 | ||||
-rw-r--r-- | sql/ha_partition.cc | 3 | ||||
-rw-r--r-- | sql/sql_base.cc | 2 | ||||
-rw-r--r-- | sql/table.cc | 2 |
11 files changed, 146 insertions, 4 deletions
diff --git a/mysql-test/suite/gcol/inc/gcol_partition.inc b/mysql-test/suite/gcol/inc/gcol_partition.inc index df199e86c68..4e4af4f0023 100644 --- a/mysql-test/suite/gcol/inc/gcol_partition.inc +++ b/mysql-test/suite/gcol/inc/gcol_partition.inc @@ -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; diff --git a/mysql-test/suite/gcol/inc/gcol_view.inc b/mysql-test/suite/gcol/inc/gcol_view.inc index 51cb9b5d725..5e5afcb5ab1 100644 --- a/mysql-test/suite/gcol/inc/gcol_view.inc +++ b/mysql-test/suite/gcol/inc/gcol_view.inc @@ -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; diff --git a/mysql-test/suite/gcol/r/gcol_partition_innodb.result b/mysql-test/suite/gcol/r/gcol_partition_innodb.result index e5a68cdb177..d3f211c9b9a 100644 --- a/mysql-test/suite/gcol/r/gcol_partition_innodb.result +++ b/mysql-test/suite/gcol/r/gcol_partition_innodb.result @@ -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 # diff --git a/mysql-test/suite/gcol/r/gcol_partition_myisam.result b/mysql-test/suite/gcol/r/gcol_partition_myisam.result index 81324da6fcd..75e216f903b 100644 --- a/mysql-test/suite/gcol/r/gcol_partition_myisam.result +++ b/mysql-test/suite/gcol/r/gcol_partition_myisam.result @@ -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; diff --git a/mysql-test/suite/gcol/r/gcol_view_innodb.result b/mysql-test/suite/gcol/r/gcol_view_innodb.result index ec82c792493..2690c60f634 100644 --- a/mysql-test/suite/gcol/r/gcol_view_innodb.result +++ b/mysql-test/suite/gcol/r/gcol_view_innodb.result @@ -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; diff --git a/mysql-test/suite/gcol/r/gcol_view_myisam.result b/mysql-test/suite/gcol/r/gcol_view_myisam.result index 13cb74ebcb5..b2856e36d13 100644 --- a/mysql-test/suite/gcol/r/gcol_view_myisam.result +++ b/mysql-test/suite/gcol/r/gcol_view_myisam.result @@ -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; diff --git a/mysql-test/suite/vcol/r/binlog.result b/mysql-test/suite/vcol/r/binlog.result index d4893b7ed3c..463928b97b8 100644 --- a/mysql-test/suite/vcol/r/binlog.result +++ b/mysql-test/suite/vcol/r/binlog.result @@ -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 diff --git a/mysql-test/suite/vcol/t/binlog.test b/mysql-test/suite/vcol/t/binlog.test index aa939086f12..edf0a8957b9 100644 --- a/mysql-test/suite/vcol/t/binlog.test +++ b/mysql-test/suite/vcol/t/binlog.test @@ -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 diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index ad020acf5c4..6f50d078dff 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -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); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 11f4cb9890b..3471297ac7d 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -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); } diff --git a/sql/table.cc b/sql/table.cc index 1004f583448..2666523f092 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -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); } } |