Skip to content

Commit 3b10e8f

Browse files
committed
MDEV-27746 Wrong comparision of BLOB's empty preffix with non-preffixed BLOB causes rows count mismatch for clustered and secondary indexes during non-locking read
row_sel_sec_rec_is_for_clust_rec() treats empty BLOB prefix field in secondary index as a field equal to any external BLOB field in clustered index. Row_sel_get_clust_rec_for_mysql::operator() doesn't zerro out clustered record pointer in row_search_mvcc(), and row_search_mvcc() thinks that delete-marked secondary index record has visible for "CHECK TABLE"'s read view old-versioned clustered index record, and row_scan_index_for_mysql() counts it as a row. The fix is to execute row_sel_sec_rec_is_for_blob() in row_sel_sec_rec_is_for_clust_rec() if clustered field contains BLOB's reference.
1 parent 3a52569 commit 3b10e8f

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
connect prevent_purge,localhost,root,,;
2+
start transaction with consistent snapshot;
3+
connection default;
4+
SET @fill_amount = (@@innodb_page_size / 2 ) + 1;
5+
CREATE TABLE t1 (col_text TEXT NOT NULL, KEY (col_text(9))) ENGINE=InnoDB;
6+
INSERT INTO t1 (col_text) VALUES (REPEAT('x', @fill_amount));
7+
UPDATE t1 SET col_text='';
8+
UPDATE t1 SET col_text=REPEAT('y', @fill_amount);
9+
connect con1,localhost,root,,;
10+
SET @fill_amount = (@@innodb_page_size / 2 ) + 1;
11+
BEGIN;
12+
INSERT INTO t1 (col_text) VALUES (REPEAT('z', @fill_amount));
13+
connection default;
14+
CHECK TABLE t1;
15+
Table Op Msg_type Msg_text
16+
test.t1 check status OK
17+
disconnect con1;
18+
disconnect prevent_purge;
19+
DROP TABLE t1;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--source include/innodb_row_format.inc
2+
--source include/count_sessions.inc
3+
--connect(prevent_purge,localhost,root,,)
4+
start transaction with consistent snapshot;
5+
6+
--connection default
7+
SET @fill_amount = (@@innodb_page_size / 2 ) + 1;
8+
CREATE TABLE t1 (col_text TEXT NOT NULL, KEY (col_text(9))) ENGINE=InnoDB;
9+
10+
INSERT INTO t1 (col_text) VALUES (REPEAT('x', @fill_amount));
11+
UPDATE t1 SET col_text='';
12+
UPDATE t1 SET col_text=REPEAT('y', @fill_amount);
13+
14+
--connect(con1,localhost,root,,)
15+
SET @fill_amount = (@@innodb_page_size / 2 ) + 1;
16+
BEGIN;
17+
INSERT INTO t1 (col_text) VALUES (REPEAT('z', @fill_amount));
18+
19+
--connection default
20+
# If the bug is not fixed, CHECK TABLE will complain about wrong secondary index
21+
# rows count
22+
CHECK TABLE t1;
23+
--disconnect con1
24+
--disconnect prevent_purge
25+
DROP TABLE t1;
26+
--source include/wait_until_count_sessions.inc

storage/innobase/row/row0sel.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,16 @@ row_sel_sec_rec_is_for_clust_rec(
352352
}
353353

354354
len = clust_len;
355+
ulint prefix_len = ifield->prefix_len;
355356
if (rec_offs_nth_extern(clust_offs, clust_pos)) {
357+
/* BLOB can contain prefix. */
356358
len -= BTR_EXTERN_FIELD_REF_SIZE;
359+
if (!len) {
360+
goto compare_blobs;
361+
}
357362
}
358363

359-
if (ulint prefix_len = ifield->prefix_len) {
364+
if (prefix_len) {
360365
len = dtype_get_at_most_n_mbchars(
361366
col->prtype, col->mbminlen,
362367
col->mbmaxlen, prefix_len, len,
@@ -369,6 +374,7 @@ row_sel_sec_rec_is_for_clust_rec(
369374
check_for_blob:
370375
if (rec_offs_nth_extern(clust_offs,
371376
clust_pos)) {
377+
compare_blobs:
372378
if (!row_sel_sec_rec_is_for_blob(
373379
col->mtype, col->prtype,
374380
col->mbminlen,

0 commit comments

Comments
 (0)