mirror of
https://github.com/MariaDB/server.git
synced 2025-11-02 02:53:04 +03:00
1. In case of system-versioned table add row_end into FTS_DOC_ID index
in fts_create_common_tables() and innobase_create_key_defs().
fts_n_uniq() returns 1 or 2 depending on whether the table is
system-versioned.
After this patch recreate of FTS_DOC_ID index is required for
existing system-versioned tables. If you see this message in error
log or server warnings: "InnoDB: Table db/t1 contains 2 indexes
inside InnoDB, which is different from the number of indexes 1
defined in the MariaDB" use this command to fix the table:
ALTER TABLE db.t1 FORCE;
2. Fix duplicate history for secondary unique index like it was done
in MDEV-23644 for clustered index (932ec586aa). In case of
existing history row which conflicts with currently inseted row we
check in row_ins_scan_sec_index_for_duplicate() whether that row
was inserted as part of current transaction. In that case we
indicate with DB_FOREIGN_DUPLICATE_KEY that new history row is not
needed and should be silently skipped.
3. Some parts of MDEV-21138 (7410ff436e) reverted. Skipping of
FTS_DOC_ID index for history rows made problems with purge
system. Now this is fixed differently by p.2.
4. wait_all_purged.inc checks that we didn't affect non-history rows
so they are deleted and purged correctly.
Additional FTS fixes
fts_init_get_doc_id(): exclude history rows from max_doc_id
calculation. fts_init_get_doc_id() callback is used only for crash
recovery.
fts_add_doc_by_id(): set max value for row_end field.
fts_read_stopword(): stopwords table can be system-versioned too. We
now read stopwords only for current data.
row_insert_for_mysql(): exclude history rows from doc_id validation.
row_merge_read_clustered_index(): exclude history_rows from doc_id
processing.
fts_load_user_stopword(): for versioned table retrieve row_end field
and skip history rows. For non-versioned table we retrieve 'value'
field twice (just for uniformity).
FTS tests for System Versioning now include maybe_versioning.inc which
adds 3 combinations:
'vers' for debug build sets sysvers_force and
sysvers_hide. sysvers_force makes every created table
system-versioned, sysvers_hide hides WITH SYSTEM VERSIONING
for SHOW CREATE.
Note: basic.test, stopword.test and versioning.test do not
require debug for 'vers' combination. This is controlled by
$modify_create_table in maybe_versioning.inc and these
tests run WITH SYSTEM VERSIONING explicitly which allows to
test 'vers' combination on non-debug builds.
'vers_trx' like 'vers' sets sysvers_force_trx and sysvers_hide. That
tests FTS with trx_id-based System Versioning.
'orig' works like before: no System Versioning is added, no debug is
required.
Upgrade/downgrade test for System Versioning is done by
innodb_fts.versioning. It has 2 combinations:
'prepare' makes binaries in std_data (requires old server and OLD_BINDIR).
It tests upgrade/downgrade against old server as well.
'upgrade' tests upgrade against binaries in std_data.
Cleanups:
Removed innodb-fts-stopword.test as it duplicates stopword.test
288 lines
9.8 KiB
Plaintext
288 lines
9.8 KiB
Plaintext
#
|
||
# test of new fulltext search features
|
||
#
|
||
|
||
#
|
||
# two-level tree
|
||
#
|
||
|
||
--source include/have_innodb.inc
|
||
--source include/maybe_versioning.inc
|
||
|
||
CREATE TABLE t1 (
|
||
i int(10) unsigned not null auto_increment primary key,
|
||
a varchar(255) not null,
|
||
FULLTEXT KEY (a)
|
||
) ENGINE = INNODB;
|
||
|
||
# two-level entry, second-level tree with depth 2
|
||
--disable_query_log
|
||
let $1=260;
|
||
while ($1)
|
||
{
|
||
eval insert t1 (a) values ('aaaxxx');
|
||
dec $1;
|
||
}
|
||
|
||
# two-level entry, second-level tree has only one page
|
||
let $1=255;
|
||
while ($1)
|
||
{
|
||
eval insert t1 (a) values ('aaazzz');
|
||
dec $1;
|
||
}
|
||
|
||
# one-level entry (entries)
|
||
let $1=250;
|
||
while ($1)
|
||
{
|
||
eval insert t1 (a) values ('aaayyy');
|
||
dec $1;
|
||
}
|
||
--enable_query_log
|
||
|
||
# converting to two-level
|
||
# INNODB_FTS: Do not support repair
|
||
#repair table t1 quick;
|
||
check table t1;
|
||
#optimize table t1; # BUG#5327 - mi_sort_index() of 2-level tree
|
||
#check table t1;
|
||
|
||
select count(*) from t1 where match a against ('aaaxxx');
|
||
select count(*) from t1 where match a against ('aaayyy');
|
||
select count(*) from t1 where match a against ('aaazzz');
|
||
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz');
|
||
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz' in boolean mode);
|
||
|
||
select count(*) from t1 where match a against ('aaax*' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaay*' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaa*' in boolean mode);
|
||
|
||
# mi_write:
|
||
|
||
insert t1 (a) values ('aaaxxx'),('aaayyy');
|
||
# call to enlarge_root() below
|
||
insert t1 (a) values ('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz');
|
||
select count(*) from t1 where match a against ('aaaxxx');
|
||
select count(*) from t1 where match a against ('aaayyy');
|
||
select count(*) from t1 where match a against ('aaazzz');
|
||
|
||
# mi_delete
|
||
insert t1 (a) values ('aaaxxx 000000');
|
||
select count(*) from t1 where match a against ('000000');
|
||
delete from t1 where match a against ('000000');
|
||
select count(*) from t1 where match a against ('000000');
|
||
select count(*) from t1 where match a against ('aaaxxx');
|
||
delete from t1 where match a against ('aaazzz');
|
||
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
|
||
# double-check without index
|
||
select count(*) from t1 where a = 'aaaxxx';
|
||
select count(*) from t1 where a = 'aaayyy';
|
||
select count(*) from t1 where a = 'aaazzz';
|
||
|
||
# update
|
||
insert t1 (a) values ('aaaxxx 000000');
|
||
select count(*) from t1 where match a against ('000000');
|
||
update t1 set a='aaazzz' where match a against ('000000');
|
||
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
|
||
update t1 set a='aaazzz' where a = 'aaaxxx';
|
||
update t1 set a='aaaxxx' where a = 'aaayyy';
|
||
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
|
||
|
||
drop table t1;
|
||
|
||
CREATE TABLE t1 (
|
||
i int(10) unsigned not null auto_increment primary key,
|
||
a varchar(255) not null,
|
||
FULLTEXT KEY (a)
|
||
) ENGINE = INNODB;
|
||
|
||
#
|
||
# now same as about but w/o repair table
|
||
# 2-level tree created by mi_write
|
||
#
|
||
|
||
# two-level entry, second-level tree with depth 2
|
||
--disable_query_log
|
||
let $1=260;
|
||
while ($1)
|
||
{
|
||
eval insert t1 (a) values ('aaaxxx');
|
||
dec $1;
|
||
}
|
||
let $1=255;
|
||
while ($1)
|
||
{
|
||
eval insert t1 (a) values ('aaazzz');
|
||
dec $1;
|
||
}
|
||
let $1=250;
|
||
while ($1)
|
||
{
|
||
eval insert t1 (a) values ('aaayyy');
|
||
dec $1;
|
||
}
|
||
--enable_query_log
|
||
|
||
select count(*) from t1 where match a against ('aaaxxx');
|
||
select count(*) from t1 where match a against ('aaayyy');
|
||
select count(*) from t1 where match a against ('aaazzz');
|
||
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz');
|
||
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz' in boolean mode);
|
||
|
||
select count(*) from t1 where match a against ('aaax*' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaay*' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaa*' in boolean mode);
|
||
|
||
# mi_write:
|
||
|
||
insert t1 (a) values ('aaaxxx'),('aaayyy');
|
||
insert t1 (a) values ('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz');
|
||
select count(*) from t1 where match a against ('aaaxxx');
|
||
select count(*) from t1 where match a against ('aaayyy');
|
||
select count(*) from t1 where match a against ('aaazzz');
|
||
|
||
# mi_delete
|
||
insert t1 (a) values ('aaaxxx 000000');
|
||
select count(*) from t1 where match a against ('000000');
|
||
delete from t1 where match a against ('000000');
|
||
select count(*) from t1 where match a against ('000000');
|
||
select count(*) from t1 where match a against ('aaaxxx');
|
||
delete from t1 where match a against ('aaazzz');
|
||
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
|
||
# double-check without index
|
||
select count(*) from t1 where a = 'aaaxxx';
|
||
select count(*) from t1 where a = 'aaayyy';
|
||
select count(*) from t1 where a = 'aaazzz';
|
||
|
||
# update
|
||
insert t1 (a) values ('aaaxxx 000000');
|
||
select count(*) from t1 where match a against ('000000');
|
||
update t1 set a='aaazzz' where match a against ('000000');
|
||
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
|
||
update t1 set a='aaazzz' where a = 'aaaxxx';
|
||
update t1 set a='aaaxxx' where a = 'aaayyy';
|
||
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
|
||
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
|
||
drop table t1;
|
||
|
||
#
|
||
# BUG#11336
|
||
#
|
||
# for uca collation isalnum and strnncollsp don't agree on whether
|
||
# 0xC2A0 is a space (strnncollsp is right, isalnum is wrong).
|
||
#
|
||
# they still don't, the bug was fixed by avoiding strnncollsp
|
||
#
|
||
|
||
set names utf8;
|
||
eval create table t1(a text,fulltext(a)) ENGINE = INNODB collate=utf8_swedish_ci;
|
||
insert into t1 values('test test '),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
|
||
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test');
|
||
delete from t1 limit 1;
|
||
|
||
#
|
||
# BUG#16489: utf8 + fulltext leads to corrupt index file.
|
||
#
|
||
truncate table t1;
|
||
insert into t1 values('ab c d');
|
||
update t1 set a='ab c d';
|
||
select * from t1 where match a against('ab c' in boolean mode);
|
||
select * from t1 where match a against('ab c' in boolean mode);
|
||
drop table t1;
|
||
set names latin1;
|
||
|
||
# End of 4.1 tests
|
||
|
||
#
|
||
# BUG#19580 - FULLTEXT search produces wrong results on UTF-8 columns
|
||
# INNODB_FTS: Investigate
|
||
SET NAMES utf8;
|
||
CREATE TABLE t1(a VARCHAR(255), FULLTEXT(a)) ENGINE = INNODB DEFAULT CHARSET=utf8;
|
||
INSERT INTO t1 VALUES('„MySQL“');
|
||
SELECT a FROM t1 WHERE MATCH a AGAINST('“MySQL„' IN BOOLEAN MODE);
|
||
DROP TABLE t1;
|
||
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;
|
||
|
||
#
|
||
# MDEV-28912 NON-UNIQUE FTS_DOC_ID mistaken as FTS_DOC_ID_INDEX
|
||
#
|
||
CREATE TABLE t1(a INT, b TEXT, FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
|
||
KEY FTS_DOC_ID_INDEX(FTS_DOC_ID))ENGINE=InnoDB;
|
||
ALTER TABLE t1 ADD COLUMN c INT as (a) VIRTUAL;
|
||
ALTER TABLE t1 ADD d INT NULL;
|
||
--error ER_INNODB_FT_WRONG_DOCID_INDEX
|
||
ALTER TABLE t1 ADD FULLTEXT(b);
|
||
DROP TABLE t1;
|
||
|
||
--echo #
|
||
--echo # MDEV-29169 Using MATCH returns NULL for Virtual Column
|
||
--echo #
|
||
CREATE TABLE t (a TEXT DEFAULT NULL,
|
||
b TEXT AS (a),
|
||
c TEXT AS (concat(a, '1')),
|
||
d int AS (111) VIRTUAL,
|
||
FULLTEXT KEY `a` (`a`)
|
||
) ENGINE=InnoDB;
|
||
|
||
INSERT INTO t (a) VALUES ('test');
|
||
SELECT * FROM t;
|
||
SELECT * FROM t WHERE MATCH(a) AGAINST('test');
|
||
|
||
DROP TABLE t;
|