Skip to content

Commit

Permalink
Bug #21869656 UNDO LOG DOES NOT CONTAIN ENOUGH INFORMATION ON INDEXED
Browse files Browse the repository at this point in the history
VIRTUAL COLUMNS

Reviewed-by: Marko Makela <[email protected]>
(cherry picked from commit ccdfdec5527ac0ea559c7b5a51febcd5def73782)
  • Loading branch information
Jimmy Yang authored and bjornmu committed Sep 28, 2015
1 parent 9c509d6 commit 02f8eaa
Show file tree
Hide file tree
Showing 9 changed files with 757 additions and 67 deletions.
131 changes: 131 additions & 0 deletions mysql-test/suite/innodb/r/virtual_purge.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#
# Bug#21869656 UNDO LOG DOES NOT CONTAIN ENOUGH INFORMATION
# ON INDEXED VIRTUAL COLUMNS
#
CREATE TABLE t1 (a INT, b INT,
a1 INT GENERATED ALWAYS AS (a) VIRTUAL, INDEX(a1)
) ENGINE=InnoDB;
INSERT INTO t1 (a,b) VALUES(1,1);
CREATE TABLE t0 (a INT) ENGINE=InnoDB;
BEGIN;
SELECT * FROM t0;
a
UPDATE t1 SET a=0;
ALTER TABLE t1 DROP COLUMN a1, ALGORITHM=INPLACE;
ALTER TABLE t1 ADD COLUMN b1 INT GENERATED ALWAYS AS (b) VIRTUAL, ADD
INDEX(b1),
ALGORITHM=INPLACE;
COMMIT;
Timeout in wait_innodb_all_purged.inc for INNODB_PURGE_TRX_ID_AGE = 1
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT b1 FROM t1;
b1
1
ALTER TABLE t1
ADD COLUMN a1 INT GENERATED ALWAYS AS (a) VIRTUAL,
ADD COLUMN a2 INT GENERATED ALWAYS AS (a + b) VIRTUAL,
ADD COLUMN a3 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
ADD COLUMN a4 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
ADD INDEX(a1), ADD INDEX(a2), ADD INDEX(a3), ALGORITHM=INPLACE;
CREATE TABLE t2 (
a BLOB,
b BLOB,
c BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
h VARCHAR(10) DEFAULT NULL
) ENGINE=InnoDB;
INSERT INTO t2 VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, 'kk');
INSERT INTO t2 VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, 'mm');
CREATE INDEX idx ON t2(c(100));
INSERT INTO t1 (a, b) VALUES(1,1);
BEGIN;
SELECT * FROM t0;
a
UPDATE t1 SET a=0;
affected rows: 1
info: Rows matched: 2 Changed: 1 Warnings: 0
UPDATE t1 SET b=0;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t1 DROP COLUMN a3, ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET a=2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t1 DROP COLUMN a2, ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET b=3;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t1 ADD COLUMN b2 INT GENERATED ALWAYS AS (b) VIRTUAL,
ADD INDEX(b2), ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET b=9;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t1 ADD COLUMN b3 INT GENERATED ALWAYS AS (a) VIRTUAL,
ADD INDEX(b3), ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET b=10;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t2 DROP COLUMN c;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t2 SET a = REPEAT('s', 6000) WHERE a like 'aaa%';
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
ALTER TABLE t2 ADD COLUMN x1 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
ADD COLUMN x2 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
ADD INDEX(x1(100), x2(120)), ADD INDEX (x1(20));
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET a=5;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
UPDATE t2 SET a = REPEAT('m', 16000) WHERE a like 'sss%';
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
ALTER TABLE t1 DROP COLUMN b2, ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET a=6;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t2 DROP COLUMN x1, DROP COLUMN x2, ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t2 SET a = REPEAT('x', 1000) WHERE a like 'mmm%';
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
ALTER TABLE t1 DROP INDEX b3;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET a=100;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
COMMIT;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT b1 FROM t1;
b1
10
10
SELECT * FROM t1;
a b b1 a1 a4 b3
100 10 10 100 90 100
100 10 10 100 90 100
CHECK TABLE t2;
Table Op Msg_type Msg_text
test.t2 check status OK
DROP TABLE t2, t1, t0;
CREATE TABLE t1 (a VARCHAR(30), b INT, a2 VARCHAR(30) GENERATED ALWAYS AS (a) VIRTUAL);
CREATE INDEX idx ON t1(a2(10), b, a2(20));
ERROR 42S21: Duplicate column name 'a2'
DROP TABLE t1;
137 changes: 137 additions & 0 deletions mysql-test/suite/innodb/t/virtual_purge.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
--source include/have_innodb.inc
--source include/count_sessions.inc

--echo #
--echo # Bug#21869656 UNDO LOG DOES NOT CONTAIN ENOUGH INFORMATION
--echo # ON INDEXED VIRTUAL COLUMNS
--echo #

CREATE TABLE t1 (a INT, b INT,
a1 INT GENERATED ALWAYS AS (a) VIRTUAL, INDEX(a1)
) ENGINE=InnoDB;

INSERT INTO t1 (a,b) VALUES(1,1);

connect (con1,localhost,root,,);
# disable purge
CREATE TABLE t0 (a INT) ENGINE=InnoDB;
BEGIN; SELECT * FROM t0;

connection default;
# write the problematic update_undo log record
UPDATE t1 SET a=0;

ALTER TABLE t1 DROP COLUMN a1, ALGORITHM=INPLACE;
ALTER TABLE t1 ADD COLUMN b1 INT GENERATED ALWAYS AS (b) VIRTUAL, ADD
INDEX(b1),
ALGORITHM=INPLACE;

connection con1;
# enable purge
COMMIT;

connection default;
# wait for purge to process the update_undo record.
--source include/wait_innodb_all_purged.inc

CHECK TABLE t1;
SELECT b1 FROM t1;


# Create multi-virtual column, more ADD/DROP to test it
ALTER TABLE t1
ADD COLUMN a1 INT GENERATED ALWAYS AS (a) VIRTUAL,
ADD COLUMN a2 INT GENERATED ALWAYS AS (a + b) VIRTUAL,
ADD COLUMN a3 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
ADD COLUMN a4 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
ADD INDEX(a1), ADD INDEX(a2), ADD INDEX(a3), ALGORITHM=INPLACE;

CREATE TABLE t2 (
a BLOB,
b BLOB,
c BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
h VARCHAR(10) DEFAULT NULL
) ENGINE=InnoDB;

INSERT INTO t2 VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, 'kk');

INSERT INTO t2 VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, 'mm');

CREATE INDEX idx ON t2(c(100));

INSERT INTO t1 (a, b) VALUES(1,1);

connection con1;
# disable purge
BEGIN; SELECT * FROM t0;

connection default;
--enable_info

# write the problematic update_undo log record
UPDATE t1 SET a=0;
UPDATE t1 SET b=0;

ALTER TABLE t1 DROP COLUMN a3, ALGORITHM=INPLACE;

UPDATE t1 SET a=2;
ALTER TABLE t1 DROP COLUMN a2, ALGORITHM=INPLACE;
UPDATE t1 SET b=3;

ALTER TABLE t1 ADD COLUMN b2 INT GENERATED ALWAYS AS (b) VIRTUAL,
ADD INDEX(b2), ALGORITHM=INPLACE;
UPDATE t1 SET b=9;

ALTER TABLE t1 ADD COLUMN b3 INT GENERATED ALWAYS AS (a) VIRTUAL,
ADD INDEX(b3), ALGORITHM=INPLACE;

UPDATE t1 SET b=10;

ALTER TABLE t2 DROP COLUMN c;

UPDATE t2 SET a = REPEAT('s', 6000) WHERE a like 'aaa%';

ALTER TABLE t2 ADD COLUMN x1 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
ADD COLUMN x2 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
ADD INDEX(x1(100), x2(120)), ADD INDEX (x1(20));

UPDATE t1 SET a=5;

UPDATE t2 SET a = REPEAT('m', 16000) WHERE a like 'sss%';

ALTER TABLE t1 DROP COLUMN b2, ALGORITHM=INPLACE;

UPDATE t1 SET a=6;

ALTER TABLE t2 DROP COLUMN x1, DROP COLUMN x2, ALGORITHM=INPLACE;

UPDATE t2 SET a = REPEAT('x', 1000) WHERE a like 'mmm%';

ALTER TABLE t1 DROP INDEX b3;
UPDATE t1 SET a=100;
--disable_info

connection con1;
# enable purge
COMMIT;
disconnect con1;

connection default;
# wait for purge to process the update_undo record.
--source include/wait_innodb_all_purged.inc

CHECK TABLE t1;
SELECT b1 FROM t1;

SELECT * FROM t1;
CHECK TABLE t2;
DROP TABLE t2, t1, t0;

CREATE TABLE t1 (a VARCHAR(30), b INT, a2 VARCHAR(30) GENERATED ALWAYS AS (a) VIRTUAL);

--error ER_DUP_FIELDNAME
CREATE INDEX idx ON t1(a2(10), b, a2(20));

DROP TABLE t1;

--source include/wait_until_count_sessions.inc
49 changes: 49 additions & 0 deletions storage/innobase/dict/dict0dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,39 @@ dict_index_remove_from_cache_low(
/* Remove the index from the list of indexes of the table */
UT_LIST_REMOVE(table->indexes, index);

/* Remove the index from affected virtual column index list */
if (dict_index_has_virtual(index)) {
const dict_col_t* col;
const dict_v_col_t* vcol;

for (ulint i = 0; i < dict_index_get_n_fields(index); i++) {
col = dict_index_get_nth_col(index, i);
if (dict_col_is_virtual(col)) {
vcol = reinterpret_cast<const dict_v_col_t*>(
col);

/* This could be NULL, when we do add virtual
column, add index together. We do not need to
track this virtual column's index */
if (vcol->v_indexes == NULL) {
continue;
}

dict_v_idx_list::iterator it;

for (it = vcol->v_indexes->begin();
it != vcol->v_indexes->end(); ++it) {
dict_v_idx_t v_index = *it;
if (v_index.index == index) {
vcol->v_indexes->erase(it);
break;
}
}
}

}
}

size = mem_heap_get_size(index->heap);

ut_ad(!dict_table_is_intrinsic(table));
Expand Down Expand Up @@ -2910,6 +2943,22 @@ dict_index_add_col(
const char* col_name;

if (dict_col_is_virtual(col)) {
dict_v_col_t* v_col = reinterpret_cast<dict_v_col_t*>(col);

/* When v_col->v_indexes==NULL,
ha_innobase::commit_inplace_alter_table(commit=true)
will evict and reload the table definition, and
v_col->v_indexes will not be NULL for the new table. */
if (v_col->v_indexes != NULL) {
/* Register the index with the virtual column index
list */
struct dict_v_idx_t new_idx
= {index, index->n_def};

v_col->v_indexes->push_back(new_idx);

}

col_name = dict_table_get_v_col_name_mysql(
table, dict_col_get_no(col));
} else {
Expand Down
13 changes: 13 additions & 0 deletions storage/innobase/dict/dict0mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ dict_mem_table_free(

ut_free(table->name.m_name);
table->name.m_name = NULL;

/* Clean up virtual index info structures that are registered
with virtual columns */
for (ulint i = 0; i < table->n_v_def; i++) {
dict_v_col_t* vcol
= dict_table_get_nth_v_col(table, i);

UT_DELETE(vcol->v_indexes);
}

mem_heap_free(table->heap);
}

Expand Down Expand Up @@ -378,6 +388,9 @@ dict_mem_table_add_v_col(

v_col->num_base = num_base;

/* Initialize the index list for virtual columns */
v_col->v_indexes = UT_NEW_NOKEY(dict_v_idx_list());

return(v_col);
}

Expand Down
Loading

0 comments on commit 02f8eaa

Please sign in to comment.