MDEV-19869 Port innodb_fts.fulltext2 from mysql to mariadb.

- Ported mysql Bug#20597981 test case to mariadb-10.2
- InnoDB never used fts_doc_id_in_read_set. Basically it tells
innodb to read the fts_doc_id from the index record itself.
parent 723a4b1d
...@@ -242,3 +242,33 @@ a ...@@ -242,3 +242,33 @@ a
„MySQL“ „MySQL“
DROP TABLE t1; DROP TABLE t1;
SET NAMES latin1; SET NAMES latin1;
CREATE TABLE t1 (
FTS_DOC_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
id int(10) not null ,
first_name varchar(50) NOT NULL,
last_name varchar(50) NOT NULL,
PRIMARY KEY (FTS_DOC_ID),
UNIQUE KEY idx_1 (first_name, last_name),
FULLTEXT KEY `idx_2` (first_name)
) ENGINE=InnoDB;
INSERT INTO t1 (id, first_name, last_name) VALUES
(10, 'Bart', 'Simpson'),
(11, 'Homer', 'Simpson'),
(12, 'Marge', 'Simpson'),
(13, 'Lisa', 'Simpson'),
(14, 'Maggie', 'Simpson'),
(15, 'Ned', 'Flanders'),
(16, 'Nelson', 'Muntz');
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SELECT fts_doc_id, first_name, last_name, MATCH(first_name) AGAINST('Homer' IN BOOLEAN MODE) AS score FROM t1;
fts_doc_id first_name last_name score
1 Bart Simpson 0
2 Homer Simpson 0.7141907215118408
4 Lisa Simpson 0
5 Maggie Simpson 0
3 Marge Simpson 0
6 Ned Flanders 0
7 Nelson Muntz 0
DROP TABLE t1;
...@@ -11,11 +11,6 @@ ...@@ -11,11 +11,6 @@
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1;
--enable_warnings --enable_warnings
if (`select plugin_auth_version <= "5.6.10" from information_schema.plugins where plugin_name='innodb'`)
{
--skip Not fixed in InnoDB 5.6.10 or earlier
}
CREATE TABLE t1 ( CREATE TABLE t1 (
i int(10) unsigned not null auto_increment primary key, i int(10) unsigned not null auto_increment primary key,
a varchar(255) not null, a varchar(255) not null,
...@@ -239,3 +234,29 @@ INSERT INTO t1 VALUES('„MySQL“'); ...@@ -239,3 +234,29 @@ INSERT INTO t1 VALUES('„MySQL“');
SELECT a FROM t1 WHERE MATCH a AGAINST('“MySQL„' IN BOOLEAN MODE); SELECT a FROM t1 WHERE MATCH a AGAINST('“MySQL„' IN BOOLEAN MODE);
DROP TABLE t1; DROP TABLE t1;
SET NAMES latin1; SET NAMES latin1;
#
# Bug #20597981 - WRONG RELEVANCE RANKING FOR FULL TEXT SEARCHES
# WHEN FTS_DOC_ID IS PRIMARY KEY
CREATE TABLE t1 (
FTS_DOC_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
id int(10) not null ,
first_name varchar(50) NOT NULL,
last_name varchar(50) NOT NULL,
PRIMARY KEY (FTS_DOC_ID),
UNIQUE KEY idx_1 (first_name, last_name),
FULLTEXT KEY `idx_2` (first_name)
) ENGINE=InnoDB;
INSERT INTO t1 (id, first_name, last_name) VALUES
(10, 'Bart', 'Simpson'),
(11, 'Homer', 'Simpson'),
(12, 'Marge', 'Simpson'),
(13, 'Lisa', 'Simpson'),
(14, 'Maggie', 'Simpson'),
(15, 'Ned', 'Flanders'),
(16, 'Nelson', 'Muntz');
analyze table t1;
SELECT fts_doc_id, first_name, last_name, MATCH(first_name) AGAINST('Homer' IN BOOLEAN MODE) AS score FROM t1;
DROP TABLE t1;
...@@ -9688,14 +9688,16 @@ ha_innobase::change_active_index( ...@@ -9688,14 +9688,16 @@ ha_innobase::change_active_index(
since FT search returns rank only. In addition engine should since FT search returns rank only. In addition engine should
be able to retrieve FTS_DOC_ID column value if necessary. */ be able to retrieve FTS_DOC_ID column value if necessary. */
if ((m_prebuilt->index->type & DICT_FTS)) { if ((m_prebuilt->index->type & DICT_FTS)) {
#ifdef MYSQL_STORE_FTS_DOC_ID
if (table->fts_doc_id_field for (ulint i = 0; i < table->s->fields; i++) {
&& bitmap_is_set(table->read_set, if (m_prebuilt->read_just_key
table->fts_doc_id_field->field_index && bitmap_get_next_set(table->read_set, i)
&& m_prebuilt->read_just_key)) { && !strcmp(table->s->field[i]->field_name,
m_prebuilt->fts_doc_id_in_read_set = 1; FTS_DOC_ID_COL_NAME)){
m_prebuilt->fts_doc_id_in_read_set = true;
break;
}
} }
#endif
} else { } else {
dtuple_set_n_fields(m_prebuilt->search_tuple, dtuple_set_n_fields(m_prebuilt->search_tuple,
m_prebuilt->index->n_fields); m_prebuilt->index->n_fields);
...@@ -9706,13 +9708,12 @@ ha_innobase::change_active_index( ...@@ -9706,13 +9708,12 @@ ha_innobase::change_active_index(
/* If it's FTS query and FTS_DOC_ID exists FTS_DOC_ID field is /* If it's FTS query and FTS_DOC_ID exists FTS_DOC_ID field is
always added to read_set. */ always added to read_set. */
m_prebuilt->fts_doc_id_in_read_set = m_prebuilt->in_fts_query
#ifdef MYSQL_STORE_FTS_DOC_ID && m_prebuilt->read_just_key
m_prebuilt->fts_doc_id_in_read_set = && dict_index_contains_col_or_prefix(
(m_prebuilt->read_just_key && table->fts_doc_id_field m_prebuilt->index,
&& m_prebuilt->in_fts_query); m_prebuilt->table->fts->doc_col,
#endif false);
} }
/* MySQL changes the active index for a handle also during some /* MySQL changes the active index for a handle also during some
......
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