Commit 5f206259 authored by Nikita Malyavin's avatar Nikita Malyavin Committed by Sergei Golubchik

MDEV-30985 Replica stops with error on ALTER ONLINE with Geometry Types

The bug is inherent for row-based replication as well.
To reproduce, a virtual (not stored) field of a blob type computed from
another field of a different blob type is required.

The following happens during an update or delete row event:
1. A row is unpacked.
2. Virtual fields are updated. Field b1 stores the pointer in
   Field_blob::value and references it in table->record[0].
3. record[0] is stored to record[1] in Rows_log_event::find_row.
4. A new record is fetched from handler. (e.g. ha_rnd_next)
5. Virtual columns are updated (only non-stored).
6. Field b1 receives new value. Old value is deallocated
   (Field_blob::val_str).
7. record_compare is called. record[0] and record[1] are compared.
8. record[1] contains a reference to a freed value.

record_compare is used in replication to find a matching record for update
or delete. Virtual columns that are not stored should be definitely skipped
both for correctness, and for this bug fix.

STORED virtual columns, on the other hand, may be required and shouldn't be
skipped. Stored columns are not affected, since they are not updated after
handler's fetch.
parent 3ad0e7ed
...@@ -173,3 +173,21 @@ DROP TABLE IF EXISTS test.t1; ...@@ -173,3 +173,21 @@ DROP TABLE IF EXISTS test.t1;
DROP TABLE IF EXISTS test.t2; DROP TABLE IF EXISTS test.t2;
# ensure cleanup on slave as well: # ensure cleanup on slave as well:
--sync_slave_with_master --sync_slave_with_master
--echo #
--echo # MDEV-30985 Replica stops with error on ALTER ONLINE with Geometry Types
--echo #
--connection master
CREATE TABLE t(txt TEXT DEFAULT '111111111', blb LONGBLOB AS (txt));
INSERT INTO t () VALUES (),(),();
DELETE FROM t;
DROP TABLE t;
--sync_slave_with_master
--connection master
CREATE TABLE t(txt TEXT DEFAULT '111111111', blb LONGBLOB AS (txt) STORED);
INSERT INTO t () VALUES (),(),();
DELETE FROM t;
DROP TABLE t;
--sync_slave_with_master
...@@ -361,4 +361,16 @@ connection master; ...@@ -361,4 +361,16 @@ connection master;
connection slave; connection slave;
connection master; connection master;
drop table t; drop table t;
#
# MDEV-30985 Replica stops with error on ALTER ONLINE with Geometry Types
#
create table t(geo geometrycollection default st_geomfromtext('point(1 1)'));
insert into t () values (),(),();
connection slave;
alter table t add vcol9 point as (geo), add key(vcol9);
connection master;
delete from t;
connection slave;
connection master;
drop table t;
include/rpl_end.inc include/rpl_end.inc
...@@ -14,4 +14,14 @@ insert into t2(c) values (null); ...@@ -14,4 +14,14 @@ insert into t2(c) values (null);
connection slave; connection slave;
connection master; connection master;
drop table t1, t2; drop table t1, t2;
#
# MDEV-30985 Replica stops with error on ALTER ONLINE with Geometry Types
#
create table t(geo geometrycollection default st_geomfromtext('point(1 1)'),
vc point as (geo));
insert into t () values (),(),();
delete from t;
connection slave;
connection master;
drop table t;
include/rpl_end.inc include/rpl_end.inc
...@@ -160,4 +160,19 @@ connection master; ...@@ -160,4 +160,19 @@ connection master;
DROP TABLE IF EXISTS test.t1; DROP TABLE IF EXISTS test.t1;
DROP TABLE IF EXISTS test.t2; DROP TABLE IF EXISTS test.t2;
connection slave; connection slave;
#
# MDEV-30985 Replica stops with error on ALTER ONLINE with Geometry Types
#
connection master;
CREATE TABLE t(txt TEXT DEFAULT '111111111', blb LONGBLOB AS (txt));
INSERT INTO t () VALUES (),(),();
DELETE FROM t;
DROP TABLE t;
connection slave;
connection master;
CREATE TABLE t(txt TEXT DEFAULT '111111111', blb LONGBLOB AS (txt) STORED);
INSERT INTO t () VALUES (),(),();
DELETE FROM t;
DROP TABLE t;
connection slave;
include/rpl_end.inc include/rpl_end.inc
...@@ -160,4 +160,19 @@ connection master; ...@@ -160,4 +160,19 @@ connection master;
DROP TABLE IF EXISTS test.t1; DROP TABLE IF EXISTS test.t1;
DROP TABLE IF EXISTS test.t2; DROP TABLE IF EXISTS test.t2;
connection slave; connection slave;
#
# MDEV-30985 Replica stops with error on ALTER ONLINE with Geometry Types
#
connection master;
CREATE TABLE t(txt TEXT DEFAULT '111111111', blb LONGBLOB AS (txt));
INSERT INTO t () VALUES (),(),();
DELETE FROM t;
DROP TABLE t;
connection slave;
connection master;
CREATE TABLE t(txt TEXT DEFAULT '111111111', blb LONGBLOB AS (txt) STORED);
INSERT INTO t () VALUES (),(),();
DELETE FROM t;
DROP TABLE t;
connection slave;
include/rpl_end.inc include/rpl_end.inc
...@@ -261,4 +261,19 @@ select * from t; ...@@ -261,4 +261,19 @@ select * from t;
--connection master --connection master
drop table t; drop table t;
--echo #
--echo # MDEV-30985 Replica stops with error on ALTER ONLINE with Geometry Types
--echo #
create table t(geo geometrycollection default st_geomfromtext('point(1 1)'));
insert into t () values (),(),();
--sync_slave_with_master
alter table t add vcol9 point as (geo), add key(vcol9);
--connection master
delete from t;
--sync_slave_with_master
--connection master
drop table t;
--source include/rpl_end.inc --source include/rpl_end.inc
...@@ -23,4 +23,17 @@ sync_slave_with_master; ...@@ -23,4 +23,17 @@ sync_slave_with_master;
connection master; connection master;
drop table t1, t2; drop table t1, t2;
--echo #
--echo # MDEV-30985 Replica stops with error on ALTER ONLINE with Geometry Types
--echo #
create table t(geo geometrycollection default st_geomfromtext('point(1 1)'),
vc point as (geo));
insert into t () values (),(),();
delete from t;
sync_slave_with_master;
connection master;
drop table t;
--source include/rpl_end.inc --source include/rpl_end.inc
...@@ -7094,7 +7094,8 @@ static bool record_compare(TABLE *table, bool vers_from_plain= false) ...@@ -7094,7 +7094,8 @@ static bool record_compare(TABLE *table, bool vers_from_plain= false)
goto record_compare_differ; goto record_compare_differ;
} }
if (!f->is_null() && f->cmp_binary_offset(table->s->rec_buff_length)) if (!f->is_null() && !f->vcol_info &&
f->cmp_binary_offset(table->s->rec_buff_length))
goto record_compare_differ; goto record_compare_differ;
} }
......
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