Commit bd22650b authored by Thirunarayanan Balathandayuthapani's avatar Thirunarayanan Balathandayuthapani Committed by Marko Mäkelä

MDEV-19073 FTS row mismatch after crash recovery

InnoDB stores synced_doc_id + 1 value in FTS_CONFIG table. But
while reading the synced doc id from FTS_CONFIG table after restart,
InnoDB should read synced_doc_id - 1 to get the actual synced
doc id value.
parent 790a74d2
...@@ -67,6 +67,31 @@ INSERT INTO articles VALUES ...@@ -67,6 +67,31 @@ INSERT INTO articles VALUES
BEGIN; BEGIN;
INSERT INTO articles VALUES INSERT INTO articles VALUES
(100, 200, 'MySQL Tutorial','DBMS stands for DataBase ...'); (100, 200, 'MySQL Tutorial','DBMS stands for DataBase ...');
#
# MDEV-19073 FTS row mismatch after crash recovery
#
CREATE TABLE mdev19073(id SERIAL, title VARCHAR(200), body TEXT,
FULLTEXT(title,body)) ENGINE=InnoDB;
INSERT INTO mdev19073 (title, body) VALUES
('MySQL Tutorial', 'DBMS stands for Database...');
CREATE FULLTEXT INDEX idx ON mdev19073(title, body);
CREATE TABLE mdev19073_2 LIKE mdev19073;
INSERT INTO mdev19073_2 (title, body) VALUES
('MySQL Tutorial', 'DBMS stands for Database...');
INSERT INTO mdev19073 (title, body) VALUES
('MariaDB Tutorial', 'DB means Database ...');
INSERT INTO mdev19073_2 (title, body) VALUES
('MariaDB Tutorial', 'DB means Database ...');
SELECT * FROM mdev19073 WHERE MATCH (title, body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for Database...
2 MariaDB Tutorial DB means Database ...
SELECT * FROM mdev19073_2 WHERE MATCH (title, body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for Database...
2 MariaDB Tutorial DB means Database ...
# Kill and restart # Kill and restart
INSERT INTO articles VALUES (8, 12, 'MySQL Tutorial','DBMS stands for DataBase ...'); INSERT INTO articles VALUES (8, 12, 'MySQL Tutorial','DBMS stands for DataBase ...');
SELECT * FROM articles WHERE MATCH (title, body) SELECT * FROM articles WHERE MATCH (title, body)
...@@ -76,3 +101,14 @@ id FTS_DOC_ID title body ...@@ -76,3 +101,14 @@ id FTS_DOC_ID title body
1 10 MySQL Tutorial DBMS stands for DataBase ... 1 10 MySQL Tutorial DBMS stands for DataBase ...
8 12 MySQL Tutorial DBMS stands for DataBase ... 8 12 MySQL Tutorial DBMS stands for DataBase ...
DROP TABLE articles; DROP TABLE articles;
SELECT * FROM mdev19073 WHERE MATCH (title, body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for Database...
2 MariaDB Tutorial DB means Database ...
SELECT * FROM mdev19073_2 WHERE MATCH (title, body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for Database...
2 MariaDB Tutorial DB means Database ...
DROP TABLE mdev19073, mdev19073_2;
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
--source include/have_innodb.inc --source include/have_innodb.inc
# The embedded server tests do not support restarting. # The embedded server tests do not support restarting.
--source include/not_embedded.inc --source include/not_embedded.inc
--source include/maybe_debug.inc
# Following are test for crash recovery on FTS index, the first scenario # Following are test for crash recovery on FTS index, the first scenario
# is for bug Bug #14586855 INNODB: FAILING ASSERTION: (DICT_INDEX_GET_N_UNIQUE( # is for bug Bug #14586855 INNODB: FAILING ASSERTION: (DICT_INDEX_GET_N_UNIQUE(
...@@ -62,13 +63,17 @@ INSERT INTO articles (title,body) VALUES ...@@ -62,13 +63,17 @@ INSERT INTO articles (title,body) VALUES
('MySQL vs. YourSQL','In the following database comparison ...'), ('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...'); ('MySQL Security','When configured properly, MySQL ...');
connect(dml, localhost, root,,);
BEGIN; BEGIN;
INSERT INTO articles (title,body) VALUES INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'); ('MySQL Tutorial','DBMS stands for DataBase ...');
connection default;
--source include/kill_and_restart_mysqld.inc --source include/kill_and_restart_mysqld.inc
disconnect dml;
# This insert will re-initialize the Doc ID counter, it should not crash # This insert will re-initialize the Doc ID counter, it should not crash
INSERT INTO articles (title,body) VALUES INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'); ('MySQL Tutorial','DBMS stands for DataBase ...');
...@@ -101,12 +106,55 @@ INSERT INTO articles VALUES ...@@ -101,12 +106,55 @@ INSERT INTO articles VALUES
(5, 6, 'MySQL vs. YourSQL','In the following database comparison ...'), (5, 6, 'MySQL vs. YourSQL','In the following database comparison ...'),
(7, 4, 'MySQL Security','When configured properly, MySQL ...'); (7, 4, 'MySQL Security','When configured properly, MySQL ...');
connect(dml, localhost, root,,);
BEGIN; BEGIN;
INSERT INTO articles VALUES INSERT INTO articles VALUES
(100, 200, 'MySQL Tutorial','DBMS stands for DataBase ...'); (100, 200, 'MySQL Tutorial','DBMS stands for DataBase ...');
connect(dml2, localhost, root,,);
--echo #
--echo # MDEV-19073 FTS row mismatch after crash recovery
--echo #
CREATE TABLE mdev19073(id SERIAL, title VARCHAR(200), body TEXT,
FULLTEXT(title,body)) ENGINE=InnoDB;
INSERT INTO mdev19073 (title, body) VALUES
('MySQL Tutorial', 'DBMS stands for Database...');
CREATE FULLTEXT INDEX idx ON mdev19073(title, body);
CREATE TABLE mdev19073_2 LIKE mdev19073;
if ($have_debug)
{
--disable_query_log
SET @saved_dbug = @@debug_dbug;
SET DEBUG_DBUG = '+d,fts_instrument_sync_debug';
--enable_query_log
}
INSERT INTO mdev19073_2 (title, body) VALUES
('MySQL Tutorial', 'DBMS stands for Database...');
if ($have_debug)
{
--disable_query_log
SET DEBUG_DBUG = @saved_dbug;
--enable_query_log
}
INSERT INTO mdev19073 (title, body) VALUES
('MariaDB Tutorial', 'DB means Database ...');
INSERT INTO mdev19073_2 (title, body) VALUES
('MariaDB Tutorial', 'DB means Database ...');
# Should return 2 rows
SELECT * FROM mdev19073 WHERE MATCH (title, body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
SELECT * FROM mdev19073_2 WHERE MATCH (title, body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
connection default;
--source include/kill_and_restart_mysqld.inc --source include/kill_and_restart_mysqld.inc
disconnect dml;
disconnect dml2;
# This would re-initialize the FTS index and do the re-tokenization # This would re-initialize the FTS index and do the re-tokenization
# of above records # of above records
...@@ -116,3 +164,10 @@ SELECT * FROM articles WHERE MATCH (title, body) ...@@ -116,3 +164,10 @@ SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE); AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DROP TABLE articles; DROP TABLE articles;
# Should return 2 rows
SELECT * FROM mdev19073 WHERE MATCH (title, body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
SELECT * FROM mdev19073_2 WHERE MATCH (title, body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
DROP TABLE mdev19073, mdev19073_2;
...@@ -2739,6 +2739,10 @@ fts_cmp_set_sync_doc_id( ...@@ -2739,6 +2739,10 @@ fts_cmp_set_sync_doc_id(
} }
if (read_only) { if (read_only) {
/* InnoDB stores actual synced_doc_id value + 1 in
FTS_CONFIG table. Reduce the value by 1 while reading
after startup. */
if (*doc_id) *doc_id -= 1;
goto func_exit; goto func_exit;
} }
......
...@@ -2739,6 +2739,10 @@ fts_cmp_set_sync_doc_id( ...@@ -2739,6 +2739,10 @@ fts_cmp_set_sync_doc_id(
} }
if (read_only) { if (read_only) {
/* InnoDB stores actual synced_doc_id value + 1 in
FTS_CONFIG table. Reduce the value by 1 while reading
after startup. */
if (*doc_id) *doc_id -= 1;
goto func_exit; goto func_exit;
} }
......
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