Commit 2fa4ed03 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-17483 Insert on delete-marked record can wrongly inherit old values for instantly added column

row_ins_clust_index_entry_low(): Do not call dtuple_t::trim()
before row_ins_clust_index_entry_by_modify(), so that the values
of all columns will be available in row_upd_build_difference_binary().
If applicable, the tuple can be trimmed in btr_cur_optimistic_update()
or btr_cur_pessimistic_update(), which will be called by
row_ins_clust_index_entry_by_modify().
parent c2c1550f
...@@ -471,6 +471,21 @@ Table Op Msg_type Msg_text ...@@ -471,6 +471,21 @@ Table Op Msg_type Msg_text
test.t2 check status OK test.t2 check status OK
test.t1 check status OK test.t1 check status OK
DROP TABLE t2, t1; DROP TABLE t2, t1;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
INSERT INTO t1 SET a = 1;
ALTER TABLE t1 ADD COLUMN b TEXT;
BEGIN;
UPDATE t1 SET b = REPEAT('1', 32768);
UPDATE t1 SET a = 2;
INSERT INTO t1 SET a = 1;
SELECT a,LENGTH(b) FROM t1;
a LENGTH(b)
1 NULL
2 32768
DELETE FROM t1;
COMMIT;
InnoDB 0 transactions not purged
DROP TABLE t1;
CREATE TABLE t1 CREATE TABLE t1
(id INT PRIMARY KEY, c2 INT UNIQUE, (id INT PRIMARY KEY, c2 INT UNIQUE,
c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'), c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'),
...@@ -888,6 +903,21 @@ Table Op Msg_type Msg_text ...@@ -888,6 +903,21 @@ Table Op Msg_type Msg_text
test.t2 check status OK test.t2 check status OK
test.t1 check status OK test.t1 check status OK
DROP TABLE t2, t1; DROP TABLE t2, t1;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPACT;
INSERT INTO t1 SET a = 1;
ALTER TABLE t1 ADD COLUMN b TEXT;
BEGIN;
UPDATE t1 SET b = REPEAT('1', 32768);
UPDATE t1 SET a = 2;
INSERT INTO t1 SET a = 1;
SELECT a,LENGTH(b) FROM t1;
a LENGTH(b)
1 NULL
2 32768
DELETE FROM t1;
COMMIT;
InnoDB 0 transactions not purged
DROP TABLE t1;
CREATE TABLE t1 CREATE TABLE t1
(id INT PRIMARY KEY, c2 INT UNIQUE, (id INT PRIMARY KEY, c2 INT UNIQUE,
c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'), c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'),
...@@ -1305,10 +1335,25 @@ Table Op Msg_type Msg_text ...@@ -1305,10 +1335,25 @@ Table Op Msg_type Msg_text
test.t2 check status OK test.t2 check status OK
test.t1 check status OK test.t1 check status OK
DROP TABLE t2, t1; DROP TABLE t2, t1;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
INSERT INTO t1 SET a = 1;
ALTER TABLE t1 ADD COLUMN b TEXT;
BEGIN;
UPDATE t1 SET b = REPEAT('1', 32768);
UPDATE t1 SET a = 2;
INSERT INTO t1 SET a = 1;
SELECT a,LENGTH(b) FROM t1;
a LENGTH(b)
1 NULL
2 32768
DELETE FROM t1;
COMMIT;
InnoDB 0 transactions not purged
DROP TABLE t1;
disconnect analyze; disconnect analyze;
SELECT variable_value-@old_instant instants SELECT variable_value-@old_instant instants
FROM information_schema.global_status FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column'; WHERE variable_name = 'innodb_instant_alter_column';
instants instants
48 51
SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency; SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency;
...@@ -343,6 +343,24 @@ DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75); ...@@ -343,6 +343,24 @@ DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
CHECK TABLE t2, t1; CHECK TABLE t2, t1;
DROP TABLE t2, t1; DROP TABLE t2, t1;
#
# MDEV-17483 Insert on delete-marked record can wrongly inherit old values
# for instantly added column
#
eval CREATE TABLE t1 (a INT PRIMARY KEY) $engine;
INSERT INTO t1 SET a = 1;
ALTER TABLE t1 ADD COLUMN b TEXT;
BEGIN;
UPDATE t1 SET b = REPEAT('1', 32768);
UPDATE t1 SET a = 2;
INSERT INTO t1 SET a = 1;
SELECT a,LENGTH(b) FROM t1;
DELETE FROM t1;
COMMIT;
--source include/wait_all_purged.inc
DROP TABLE t1;
dec $format; dec $format;
} }
disconnect analyze; disconnect analyze;
......
...@@ -2671,8 +2671,6 @@ row_ins_clust_index_entry_low( ...@@ -2671,8 +2671,6 @@ row_ins_clust_index_entry_low(
} }
} }
if (index->is_instant()) entry->trim(*index);
if (rec_is_metadata(btr_cur_get_rec(cursor), index)) { if (rec_is_metadata(btr_cur_get_rec(cursor), index)) {
goto do_insert; goto do_insert;
} }
...@@ -2739,6 +2737,7 @@ row_ins_clust_index_entry_low( ...@@ -2739,6 +2737,7 @@ row_ins_clust_index_entry_low(
mtr_commit(&mtr); mtr_commit(&mtr);
mem_heap_free(entry_heap); mem_heap_free(entry_heap);
} else { } else {
if (index->is_instant()) entry->trim(*index);
do_insert: do_insert:
rec_t* insert_rec; rec_t* insert_rec;
......
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