Commit bf262bd9 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-11649 Uninitialized field fts_token->position in innodb_fts.innodb_fts_plugin

The field fts_token->position is not initialized in
row_merge_fts_doc_tokenize(). We cannot have that field
without changing the fulltext parser plugin ABI
(adding st_mysql_ftparser_boolean_info::position,
as it was done in MySQL 5.7 in WL#6943).

The InnoDB fulltext parser plugins "ngram" and "Mecab" that were
introduced in MySQL 5.7 do depend on that field. But the simple_parser
does not. Apparently, simple_parser is leaving the field as 0.

So, in our fix we will assume that the missing position field is 0.
parent dd750879
...@@ -135,12 +135,29 @@ INSERT INTO articles (title, body) VALUES ...@@ -135,12 +135,29 @@ INSERT INTO articles (title, body) VALUES
('How To Use MySQL Well','After you went through a ...'), ('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'), ('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','How to use full-text search engine'), ('1001 MySQL Tricks','How to use full-text search engine'),
('Go MySQL Tricks','How to use full text search engine'); ('Go MariaDB Tricks','How to use full text search engine');
SELECT * FROM articles WHERE
MATCH(title, body) AGAINST('MySQL');
id title body
6 MySQL Tutorial DBMS stands for MySQL DataBase ...
7 How To Use MySQL Well After you went through a ...
8 Optimizing MySQL In this tutorial we will show ...
9 1001 MySQL Tricks How to use full-text search engine
SELECT * FROM articles WHERE
MATCH(title, body) AGAINST('tutorial');
id title body
6 MySQL Tutorial DBMS stands for MySQL DataBase ...
8 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM articles WHERE SELECT * FROM articles WHERE
MATCH(title, body) AGAINST('Tricks'); MATCH(title, body) AGAINST('Tricks');
id title body id title body
9 1001 MySQL Tricks How to use full-text search engine 9 1001 MySQL Tricks How to use full-text search engine
10 Go MySQL Tricks How to use full text search engine 10 Go MariaDB Tricks How to use full text search engine
SELECT * FROM articles WHERE
MATCH(title, body) AGAINST('full text search');
id title body
10 Go MariaDB Tricks How to use full text search engine
9 1001 MySQL Tricks How to use full-text search engine
SELECT COUNT(*) FROM articles; SELECT COUNT(*) FROM articles;
COUNT(*) COUNT(*)
5 5
......
...@@ -145,13 +145,18 @@ INSERT INTO articles (title, body) VALUES ...@@ -145,13 +145,18 @@ INSERT INTO articles (title, body) VALUES
('How To Use MySQL Well','After you went through a ...'), ('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'), ('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','How to use full-text search engine'), ('1001 MySQL Tricks','How to use full-text search engine'),
('Go MySQL Tricks','How to use full text search engine'); ('Go MariaDB Tricks','How to use full text search engine');
--source include/restart_mysqld.inc --source include/restart_mysqld.inc
# Simple term search - 4 records expected SELECT * FROM articles WHERE
MATCH(title, body) AGAINST('MySQL');
SELECT * FROM articles WHERE
MATCH(title, body) AGAINST('tutorial');
SELECT * FROM articles WHERE SELECT * FROM articles WHERE
MATCH(title, body) AGAINST('Tricks'); MATCH(title, body) AGAINST('Tricks');
SELECT * FROM articles WHERE
MATCH(title, body) AGAINST('full text search');
SELECT COUNT(*) FROM articles; SELECT COUNT(*) FROM articles;
DROP TABLE articles; DROP TABLE articles;
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 2010, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2010, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2015, 2016, MariaDB Corporation. Copyright (c) 2015, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -103,7 +103,6 @@ struct fts_psort_t { ...@@ -103,7 +103,6 @@ struct fts_psort_t {
/** Row fts token for plugin parser */ /** Row fts token for plugin parser */
struct row_fts_token_t { struct row_fts_token_t {
fts_string_t* text; /*!< token */ fts_string_t* text; /*!< token */
ulint position; /*!< token position in the document */
UT_LIST_NODE_T(row_fts_token_t) UT_LIST_NODE_T(row_fts_token_t)
token_list; /*!< next token link */ token_list; /*!< next token link */
}; };
......
...@@ -527,7 +527,6 @@ row_merge_fts_doc_tokenize( ...@@ -527,7 +527,6 @@ row_merge_fts_doc_tokenize(
doc id and position to sort buffer */ doc id and position to sort buffer */
while (t_ctx->processed_len < doc->text.f_len) { while (t_ctx->processed_len < doc->text.f_len) {
ulint idx = 0; ulint idx = 0;
ib_uint32_t position;
ulint cur_len; ulint cur_len;
doc_id_t write_doc_id; doc_id_t write_doc_id;
row_fts_token_t* fts_token = NULL; row_fts_token_t* fts_token = NULL;
...@@ -679,20 +678,18 @@ row_merge_fts_doc_tokenize( ...@@ -679,20 +678,18 @@ row_merge_fts_doc_tokenize(
++field; ++field;
/* The third field is the position */ /* The third field is the position.
if (parser != NULL) { MySQL 5.7 changed the fulltext parser plugin interface
mach_write_to_4( by adding MYSQL_FTPARSER_BOOLEAN_INFO::position.
reinterpret_cast<byte*>(&position), Below we assume that the field is always 0. */
(fts_token->position + t_ctx->init_pos)); unsigned pos = t_ctx->init_pos;
} else { byte position[4];
mach_write_to_4( if (parser == NULL) {
reinterpret_cast<byte*>(&position), pos += t_ctx->processed_len + inc - str.f_len;
(t_ctx->processed_len + inc - str.f_len + t_ctx->init_pos));
} }
len = 4;
dfield_set_data(field, &position, sizeof(position)); mach_write_to_4(position, pos);
len = dfield_get_len(field); dfield_set_data(field, &position, len);
ut_ad(len == sizeof(ib_uint32_t));
field->type.mtype = DATA_INT; field->type.mtype = DATA_INT;
field->type.prtype = DATA_NOT_NULL; field->type.prtype = DATA_NOT_NULL;
......
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