config root man

Current Path : /home/usr.opt/mysql57/mysql-test/suite/innodb_fts/r/

FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64
Upload File :
Current File : //home/usr.opt/mysql57/mysql-test/suite/innodb_fts/r/opt.result

CREATE TABLE wp(
FTS_DOC_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL DEFAULT '',
text MEDIUMTEXT NOT NULL,
dummy INTEGER,
PRIMARY KEY (FTS_DOC_ID),
UNIQUE KEY FTS_DOC_ID_INDEX (FTS_DOC_ID),
FULLTEXT KEY idx (title,text) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO wp (title, text) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database to database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
CREATE TABLE t1 (i INTEGER);
INSERT INTO t1 SELECT FTS_DOC_ID FROM wp;
ANALYZE TABLE t1;
ANALYZE TABLE wp;
SELECT FTS_DOC_ID, title, MATCH(title, text) AGAINST ('database') AS score1,
MATCH(title, text) AGAINST ('mysql') AS score2 
FROM wp;
FTS_DOC_ID	title	score1	score2
1	MySQL Tutorial	0.22764469683170319	0.000000003771856604828372
2	How To Use MySQL Well	0	0.000000001885928302414186
3	Optimizing MySQL	0	0.000000001885928302414186
4	1001 MySQL Tricks	0	0.000000001885928302414186
5	MySQL vs. YourSQL	0.45528939366340637	0.000000001885928302414186
6	MySQL Security	0	0.000000003771856604828372
No sorting for this query
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database')
ORDER BY score DESC;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
No sorting for this query even if MATCH is part of an expression
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database') > 0.1
ORDER BY score DESC;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
No sorting even if there are several MATCH expressions as long as the
right one is used in ORDER BY
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score1,
MATCH(title, text) AGAINST ('mysql') AS score2
FROM wp
WHERE MATCH(title, text) AGAINST ('database')
ORDER BY score1 DESC;
title	score1	score2
MySQL vs. YourSQL	0.45528939366340637	0.000000001885928302414186
MySQL Tutorial	0.22764469683170319	0.000000003771856604828372
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
No Sorting since FT table is first table in query
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score
FROM wp, t1
WHERE MATCH(title, text) AGAINST ('database') AND FTS_DOC_ID = t1.i
ORDER BY score DESC;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
SHOW SESSION STATUS LIKE 'Sort_rows%';
Variable_name	Value
Sort_rows	0
Sorting since there is no WHERE clause
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score
FROM wp
ORDER BY score DESC;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
How To Use MySQL Well	0
Optimizing MySQL	0
1001 MySQL Tricks	0
MySQL Security	0
SHOW SESSION STATUS LIKE 'Sort_rows%';
Variable_name	Value
Sort_rows	6
Sorting since ordering on multiple columns
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database')
ORDER BY score DESC, FTS_DOC_ID;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
SHOW SESSION STATUS LIKE 'Sort_rows%';
Variable_name	Value
Sort_rows	2
Sorting since ordering is not descending
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database')
ORDER BY score ASC;
title	score
MySQL Tutorial	0.22764469683170319
MySQL vs. YourSQL	0.45528939366340637
SHOW SESSION STATUS LIKE 'Sort_rows%';
Variable_name	Value
Sort_rows	2
Sorting because one is ordering on a different MATCH expression
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('mysql') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database')
ORDER BY score DESC;
title	score
MySQL Tutorial	0.000000003771856604828372
MySQL vs. YourSQL	0.000000001885928302414186
SHOW SESSION STATUS LIKE 'Sort_rows%';
Variable_name	Value
Sort_rows	2
No sorting for this query
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score
FROM wp
ORDER BY score DESC LIMIT 2;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
Revert to table scan and sorting for this query since not
enough matching rows to satisfy LIMIT clause
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score
FROM wp
ORDER BY score DESC LIMIT 3;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
How To Use MySQL Well	0
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	1
Handler_read_key	4
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	3
Handler_read_rnd_next	7
SHOW SESSION STATUS LIKE 'Sort_rows%';
Variable_name	Value
Sort_rows	3
Sorting since no LIMIT clause
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score
FROM wp
ORDER BY score DESC;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
How To Use MySQL Well	0
Optimizing MySQL	0
1001 MySQL Tricks	0
MySQL Security	0
SHOW SESSION STATUS LIKE 'Sort_rows%';
Variable_name	Value
Sort_rows	6
Sorting since there is a WHERE clause
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score 
FROM wp
WHERE dummy IS NULL
ORDER BY score DESC LIMIT 2;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
SHOW SESSION STATUS LIKE 'Sort_rows%';
Variable_name	Value
Sort_rows	2
Sorting since ordering is not on a simple MATCH expressions
FLUSH STATUS;
SELECT title, (MATCH(title, text) AGAINST ('database')) * 100 AS score
FROM wp
ORDER BY score DESC LIMIT 2;
title	score
MySQL vs. YourSQL	45.52893936634064
MySQL Tutorial	22.76446968317032
SHOW SESSION STATUS LIKE 'Sort_rows%';
Variable_name	Value
Sort_rows	2
No ordinary handler accesses when only accessing FTS_DOC_ID and MATCH
FLUSH STATUS;
SELECT FTS_DOC_ID docid, MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database');
docid	score
5	0.45528939366340637
1	0.22764469683170319
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
Still no handler accesses when adding FTS_DOC_ID to WHERE clause
FLUSH STATUS;
SELECT FTS_DOC_ID docid, MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database') AND FTS_DOC_ID > 2;
docid	score
5	0.45528939366340637
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
Still no handler accesses when ordering by MATCH expression
FLUSH STATUS;
SELECT FTS_DOC_ID docid, MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database')
ORDER BY score;
docid	score
1	0.22764469683170319
5	0.45528939366340637
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	2
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	2
Handler_read_rnd_next	0
Optimization is disabled when ordering on FTS_DOC_ID
FLUSH STATUS;
SELECT FTS_DOC_ID docid, MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database')
ORDER BY 1 DESC;
docid	score
5	0.45528939366340637
1	0.22764469683170319
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	2
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	2
Handler_read_rnd_next	0
Optimization also work with several MATCH expressions
FLUSH STATUS;
SELECT FTS_DOC_ID docid, MATCH(title, text) AGAINST ('database') AS score1,
MATCH(title, text) AGAINST ('mysql') AS score2
FROM wp
WHERE MATCH(title, text) AGAINST ('database');
docid	score1	score2
5	0.45528939366340637	0.000000001885928302414186
1	0.22764469683170319	0.000000003771856604828372
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
Optimization does not apply if sorting on a different MATCH expressions
from the one used to access the
FLUSH STATUS;
SELECT FTS_DOC_ID docid, MATCH(title, text) AGAINST ('database') AS score1,
MATCH(title, text) AGAINST ('mysql') AS score2
FROM wp
WHERE MATCH(title, text) AGAINST ('database')
ORDER BY score2 DESC;
docid	score1	score2
1	0.22764469683170319	0.000000003771856604828372
5	0.45528939366340637	0.000000001885928302414186
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	2
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	2
Handler_read_rnd_next	0
FLUSH STATUS;
Optimization does not apply for GROUP BY
SELECT FTS_DOC_ID, MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database')
GROUP BY score;
FTS_DOC_ID	score
1	0.22764469683170319
5	0.45528939366340637
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	2
Handler_read_rnd_next	3
No sorting and no table access with LIMIT clause and only information
from FTS result
FLUSH STATUS;
SELECT FTS_DOC_ID docid, MATCH(title, text) AGAINST ('database') AS score
FROM wp
ORDER BY score DESC LIMIT 2;
docid	score
5	0.45528939366340637
1	0.22764469683170319
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
If count optimization applies, EXPLAIN shows
"Select tables optimized away."
EXPLAIN SELECT COUNT(*)
FROM wp
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select count(0) AS `COUNT(*)` from `test`.`wp` where (match `test`.`wp`.`title`,`test`.`wp`.`text` against ('database'))
FLUSH STATUS;
SELECT COUNT(*)
FROM wp
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE);
COUNT(*)
2
Verify that there was no table access
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
Optimization applies also to COUNT(expr) as long as expr is not nullable
EXPLAIN SELECT COUNT(title)
FROM wp
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select count(`test`.`wp`.`title`) AS `COUNT(title)` from `test`.`wp` where (match `test`.`wp`.`title`,`test`.`wp`.`text` against ('database'))
SELECT COUNT(title)
FROM wp
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE);
COUNT(title)
2
Optimization does not apply if not a single table query.
EXPLAIN SELECT count(*)
FROM wp, t1 
WHERE MATCH(title, text) AGAINST ('database');
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	wp	NULL	fulltext	idx	idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using index
1	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
Warnings:
Note	1003	/* select#1 */ select count(0) AS `count(*)` from `test`.`wp` join `test`.`t1` where (match `test`.`wp`.`title`,`test`.`wp`.`text` against ('database'))
SELECT count(*)
FROM wp, t1 
WHERE MATCH(title, text) AGAINST ('database');
count(*)
12
Optimization does not apply if MATCH is part of an expression
EXPLAIN SELECT COUNT(title) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE) > 0;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	wp	NULL	fulltext	idx	idx	0	const	1	100.00	Using where; Ft_hints: rank > 0
Warnings:
Note	1003	/* select#1 */ select count(`test`.`wp`.`title`) AS `COUNT(title)` from `test`.`wp` where ((match `test`.`wp`.`title`,`test`.`wp`.`text` against ('database')) > 0)
SELECT COUNT(title) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE) > 0;
COUNT(title)
2
Optimization does not apply if MATCH is part of an expression
EXPLAIN SELECT COUNT(title) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE) > 0;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	wp	NULL	fulltext	idx	idx	0	const	1	100.00	Using where; Ft_hints: rank > 0
Warnings:
Note	1003	/* select#1 */ select count(`test`.`wp`.`title`) AS `COUNT(title)` from `test`.`wp` where ((match `test`.`wp`.`title`,`test`.`wp`.`text` against ('database')) > 0)
SELECT COUNT(title) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE) > 0;
COUNT(title)
2
Optimization does not apply if COUNT expression is nullable
EXPLAIN SELECT COUNT(dummy) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	wp	NULL	fulltext	idx	idx	0	const	1	100.00	Using where; Ft_hints: no_ranking
Warnings:
Note	1003	/* select#1 */ select count(`test`.`wp`.`dummy`) AS `COUNT(dummy)` from `test`.`wp` where (match `test`.`wp`.`title`,`test`.`wp`.`text` against ('database'))
SELECT COUNT(dummy) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE);
COUNT(dummy)
0
FLUSH STATUS;
SELECT title,
MATCH(title, text) AGAINST ('database' WITH QUERY EXPANSION) AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database' WITH QUERY EXPANSION)
ORDER BY score DESC;
title	score
MySQL vs. YourSQL	2.2718474864959717
MySQL Tutorial	1.6663280725479126
Optimizing MySQL	0.22764469683170319
MySQL Security	0.000000003771856604828372
How To Use MySQL Well	0.000000001885928302414186
1001 MySQL Tricks	0.000000001885928302414186
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
FLUSH STATUS;
SELECT title,
MATCH(title, text) AGAINST ('database' WITH QUERY EXPANSION) AS score
FROM wp
ORDER BY score DESC LIMIT 2;
title	score
MySQL vs. YourSQL	2.2718474864959717
MySQL Tutorial	1.6663280725479126
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
FLUSH STATUS;
SELECT FTS_DOC_ID docid,
MATCH(title, text) AGAINST ('database' WITH QUERY EXPANSION) AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database');
docid	score
5	2.2718474864959717
1	1.6663280725479126
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
FLUSH STATUS;
SELECT FTS_DOC_ID docid,
MATCH(title, text) AGAINST ('database' WITH QUERY EXPANSION) AS score
FROM wp
ORDER BY score DESC LIMIT 2;
docid	score
5	2.2718474864959717
1	1.6663280725479126
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
EXPLAIN SELECT COUNT(*)
FROM wp
WHERE MATCH(title,text) AGAINST ('database' WITH QUERY EXPANSION);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select count(0) AS `COUNT(*)` from `test`.`wp` where (match `test`.`wp`.`title`,`test`.`wp`.`text` against ('database' with query expansion))
FLUSH STATUS;
SELECT COUNT(*)
FROM wp
WHERE MATCH(title,text) AGAINST ('database' WITH QUERY EXPANSION);
COUNT(*)
6
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
FLUSH STATUS;
SELECT title,
MATCH(title, text) AGAINST ('+MySQL -database' IN BOOLEAN MODE) AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('+MySQL -database' IN BOOLEAN MODE)
ORDER BY score DESC;
title	score
MySQL Security	0.000000003771856604828372
How To Use MySQL Well	0.000000001885928302414186
Optimizing MySQL	0.000000001885928302414186
1001 MySQL Tricks	0.000000001885928302414186
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
FLUSH STATUS;
SELECT title,
MATCH(title, text) AGAINST ('+MySQL -database' IN BOOLEAN MODE) AS score
FROM wp
ORDER BY score DESC LIMIT 2;
title	score
MySQL Security	0.000000003771856604828372
How To Use MySQL Well	0.000000001885928302414186
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
FLUSH STATUS;
SELECT FTS_DOC_ID docid,
MATCH(title, text) AGAINST ('+MySQL -database' IN BOOLEAN MODE) AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('+MySQL -database');
docid	score
5	0
1	0
6	0.000000003771856604828372
2	0.000000001885928302414186
3	0.000000001885928302414186
4	0.000000001885928302414186
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
FLUSH STATUS;
SELECT FTS_DOC_ID docid,
MATCH(title, text) AGAINST ('+MySQL -database' IN BOOLEAN MODE) AS score 
FROM wp 
ORDER BY score DESC LIMIT 2;
docid	score
6	0.000000003771856604828372
2	0.000000001885928302414186
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
EXPLAIN SELECT COUNT(*) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('+MySQL -database' IN BOOLEAN MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select count(0) AS `COUNT(*)` from `test`.`wp` where (match `test`.`wp`.`title`,`test`.`wp`.`text` against ('+MySQL -database' in boolean mode))
FLUSH STATUS;
SELECT COUNT(*) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('+MySQL -database' IN BOOLEAN MODE);
COUNT(*)
4
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
FLUSH STATUS;
SELECT title,
MATCH(title, text) AGAINST ('"MySQL database"@5' IN BOOLEAN MODE) AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('"MySQL database"@5' IN BOOLEAN MODE)
ORDER BY score DESC;
title	score
MySQL Tutorial	0.22764469683170319
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
FLUSH STATUS;
SELECT title,
MATCH(title, text) AGAINST ('"MySQL database"@5' IN BOOLEAN MODE) AS score
FROM wp
ORDER BY score DESC LIMIT 1;
title	score
MySQL Tutorial	0.22764469683170319
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
FLUSH STATUS;
SELECT FTS_DOC_ID docid,
MATCH(title, text) AGAINST ('"MySQL database"@5' IN BOOLEAN MODE) AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('"MySQL database"@5');
docid	score
1	0.22764469683170319
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
FLUSH STATUS;
SELECT FTS_DOC_ID docid,
MATCH(title, text) AGAINST ('"MySQL database"@5' IN BOOLEAN MODE) AS score
FROM wp
ORDER BY score DESC LIMIT 1;
docid	score
1	0.22764469683170319
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
EXPLAIN SELECT COUNT(*)
FROM wp
WHERE MATCH(title,text) AGAINST ('"MySQL database"@5' IN BOOLEAN MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select count(0) AS `COUNT(*)` from `test`.`wp` where (match `test`.`wp`.`title`,`test`.`wp`.`text` against ('"MySQL database"@5' in boolean mode))
FLUSH STATUS;
SELECT COUNT(*)
FROM wp
WHERE MATCH(title,text) AGAINST ('"MySQL database"@5' IN BOOLEAN MODE);
COUNT(*)
1
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
SELECT title,
MATCH(title, text) AGAINST ('database') AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('database' WITH QUERY EXPANSION)
ORDER BY score DESC;
title	score
MySQL vs. YourSQL	0.45528939366340637
MySQL Tutorial	0.22764469683170319
How To Use MySQL Well	0
Optimizing MySQL	0
1001 MySQL Tricks	0
MySQL Security	0
SELECT title,
MATCH(title, text) AGAINST ('+MySQL -database' IN BOOLEAN MODE) AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('MySQL database' WITH QUERY EXPANSION)
ORDER BY score DESC;
title	score
MySQL Security	0.000000003771856604828372
How To Use MySQL Well	0.000000001885928302414186
Optimizing MySQL	0.000000001885928302414186
1001 MySQL Tricks	0.000000001885928302414186
MySQL Tutorial	0
MySQL vs. YourSQL	0
SELECT title,
MATCH(title, text) AGAINST ('+MySQL -database' IN BOOLEAN MODE) AS score
FROM wp
WHERE MATCH(title, text) AGAINST ('"MySQL database"@5' IN BOOLEAN MODE)
ORDER BY score DESC;
title	score
MySQL Tutorial	0
ALTER TABLE wp ENGINE=myisam;
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score 
FROM wp 
WHERE MATCH(title, text) AGAINST ('database')
ORDER BY score DESC;
title	score
MySQL vs. YourSQL	0.9562782645225525
MySQL Tutorial	0.5756555199623108
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	0
Sort_scan	0
FLUSH STATUS;
SELECT title, MATCH(title, text) AGAINST ('database') AS score 
FROM wp 
ORDER BY score DESC LIMIT 2;
title	score
MySQL vs. YourSQL	0.9562782645225525
MySQL Tutorial	0.5756555199623108
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	2
Sort_scan	1
FLUSH STATUS;
SELECT FTS_DOC_ID docid, MATCH(title, text) AGAINST ('database') AS score 
FROM wp 
WHERE MATCH(title, text) AGAINST ('database');
docid	score
5	0.9562782645225525
1	0.5756555199623108
SHOW SESSION STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	3
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
FLUSH STATUS;
SELECT FTS_DOC_ID docid, MATCH(title, text) AGAINST ('database') AS score 
FROM wp 
ORDER BY score DESC LIMIT 2;
docid	score
5	0.9562782645225525
1	0.5756555199623108
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	2
Handler_read_rnd_next	7
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name	Value
Sort_merge_passes	0
Sort_range	0
Sort_rows	2
Sort_scan	1
EXPLAIN SELECT COUNT(*) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	wp	NULL	fulltext	idx	idx	0	const	1	100.00	Using where
Warnings:
Note	1003	/* select#1 */ select count(0) AS `COUNT(*)` from `test`.`wp` where (match `test`.`wp`.`title`,`test`.`wp`.`text` against ('database'))
FLUSH STATUS;
SELECT COUNT(*) 
FROM wp 
WHERE MATCH(title,text) AGAINST ('database' IN NATURAL LANGUAGE MODE);
COUNT(*)
2
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	0
Handler_read_last	0
Handler_read_next	3
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
DROP TABLE wp, t1;
CREATE TABLE t1
(
FTS_DOC_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(255) DEFAULT '',
text MEDIUMTEXT ,
PRIMARY KEY (FTS_DOC_ID),
UNIQUE KEY FTS_DOC_ID_INDEX (FTS_DOC_ID),
FULLTEXT KEY ft_idx (title,text)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO t1 (title, text) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL database','In the following database to database comparison ...'),
('MySQL Security','When configured properly, MySQL ...'),
('InnoDB', 'InnoDB is a transaction-safe (ACID compliant) storage engine'),
('MySQL is a database management system', 'A database is a structured collection of data...'),
('MySQL databases are relational', 'A relational database stores data in separate tables rather than putting all the data in one big storeroom...'),
('MySQL software is Open Source', 'Open Source means that it is possible for anyone to use and modify the software...'),
('The MySQL Database Server is very fast, reliable, scalable, and easy to use', 'MySQL Server can run comfortably on a desktop or laptop...'),
('MySQL Server works in client/server or embedded systems', 'The MySQL Database Software is a client/server system...'),
('MyISAM', 'MyISAM is based on the older (and no longer available) ISAM storage engine but has many useful extensions'),
('A large amount of contributed MySQL software is available', 'MySQL Server has a practical set of features developed in close cooperation with our users'),
(NULL,NULL);
ANALYZE TABLE t1;
# No ranking
EXPLAIN
SELECT count(*) FROM t1 WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select count(0) AS `count(*)` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database'))
SELECT count(*) FROM t1 WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE);
count(*)
6
EXPLAIN
SELECT count(*) FROM t1 WHERE MATCH (title, text) AGAINST ('data*' IN BOOLEAN MODE) ORDER BY title LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select count(0) AS `count(*)` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('data*' in boolean mode)) limit 3
SELECT count(*) FROM t1 WHERE MATCH (title, text) AGAINST ('data*' IN BOOLEAN MODE) ORDER BY title LIMIT 3;
count(*)
6
EXPLAIN
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('+fast +database' IN BOOLEAN MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+fast +database' in boolean mode))
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('+fast +database' IN BOOLEAN MODE);
FTS_DOC_ID	title
11	The MySQL Database Server is very fast, reliable, scalable, and easy to use
EXPLAIN
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: sorted
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion))
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION);
FTS_DOC_ID	title
11	The MySQL Database Server is very fast, reliable, scalable, and easy to use
12	MySQL Server works in client/server or embedded systems
10	MySQL software is Open Source
4	1001 MySQL Tricks
14	A large amount of contributed MySQL software is available
2	How To Use MySQL Well
13	MyISAM
5	MySQL vs. YourSQL database
8	MySQL is a database management system
1	MySQL Tutorial
9	MySQL databases are relational
6	MySQL Security
3	Optimizing MySQL
EXPLAIN
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('"very fast"@3' IN BOOLEAN MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('"very fast"@3' in boolean mode))
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('"very fast"@3' IN BOOLEAN MODE);
FTS_DOC_ID	title
11	The MySQL Database Server is very fast, reliable, scalable, and easy to use
EXPLAIN SELECT FTS_DOC_ID  FROM t1
WHERE MATCH(title, text) AGAINST ('+for' IN BOOLEAN MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+for' in boolean mode))
SELECT FTS_DOC_ID  FROM t1
WHERE MATCH(title, text) AGAINST ('+for' IN BOOLEAN MODE);
FTS_DOC_ID
# No sorting by rank
EXPLAIN SELECT FTS_DOC_ID, TITLE FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY title;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`t1`.`title` AS `TITLE` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) order by `test`.`t1`.`title`
SELECT FTS_DOC_ID, TITLE FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY title;
FTS_DOC_ID	TITLE
9	MySQL databases are relational
8	MySQL is a database management system
12	MySQL Server works in client/server or embedded systems
1	MySQL Tutorial
5	MySQL vs. YourSQL database
11	The MySQL Database Server is very fast, reliable, scalable, and easy to use
EXPLAIN SELECT FTS_DOC_ID FROM t1
WHERE MATCH(title, text) AGAINST ('+fast +database' IN BOOLEAN MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+fast +database' in boolean mode))
SELECT FTS_DOC_ID  FROM t1
WHERE MATCH(title, text) AGAINST ('+fast +database' IN BOOLEAN MODE);
FTS_DOC_ID
11
EXPLAIN
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) ORDER BY title;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion)) order by `test`.`t1`.`title`
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) ORDER BY title;
FTS_DOC_ID	title
4	1001 MySQL Tricks
14	A large amount of contributed MySQL software is available
2	How To Use MySQL Well
13	MyISAM
9	MySQL databases are relational
8	MySQL is a database management system
6	MySQL Security
12	MySQL Server works in client/server or embedded systems
10	MySQL software is Open Source
1	MySQL Tutorial
5	MySQL vs. YourSQL database
3	Optimizing MySQL
11	The MySQL Database Server is very fast, reliable, scalable, and easy to use
EXPLAIN
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('"very fast"@3' IN BOOLEAN MODE) ORDER BY title;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('"very fast"@3' in boolean mode)) order by `test`.`t1`.`title`
SELECT FTS_DOC_ID, title FROM t1 WHERE MATCH(title, text) AGAINST ('"very fast"@3' IN BOOLEAN MODE) ORDER BY title;
FTS_DOC_ID	title
11	The MySQL Database Server is very fast, reliable, scalable, and easy to use
# LIMIT optimization
EXPLAIN SELECT FTS_DOC_ID, TITLE FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: sorted, limit = 3
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`t1`.`title` AS `TITLE` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) limit 3
SELECT FTS_DOC_ID, TITLE FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
LIMIT 3;
FTS_DOC_ID	TITLE
11	The MySQL Database Server is very fast, reliable, scalable, and easy to use
5	MySQL vs. YourSQL database
8	MySQL is a database management system
EXPLAIN SELECT FTS_DOC_ID FROM t1
WHERE MATCH(title, text) AGAINST ('+fast +database' IN BOOLEAN MODE)
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking, limit = 3; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+fast +database' in boolean mode)) limit 3
SELECT FTS_DOC_ID  FROM t1
WHERE MATCH(title, text) AGAINST ('+fast +database' IN BOOLEAN MODE)
LIMIT 3;
FTS_DOC_ID
11
EXPLAIN SELECT FTS_DOC_ID FROM t1
WHERE MATCH(title, text) AGAINST ('+fast +database' IN BOOLEAN MODE)
ORDER BY title
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+fast +database' in boolean mode)) order by `test`.`t1`.`title` limit 3
SELECT FTS_DOC_ID  FROM t1
WHERE MATCH(title, text) AGAINST ('+fast +database' IN BOOLEAN MODE)
ORDER BY title
LIMIT 3;
FTS_DOC_ID
11
EXPLAIN
SELECT FTS_DOC_ID FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) ORDER BY title LIMIT 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion)) order by `test`.`t1`.`title` limit 1
SELECT FTS_DOC_ID FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) ORDER BY title LIMIT 1;
FTS_DOC_ID
4
EXPLAIN
SELECT FTS_DOC_ID FROM t1 WHERE MATCH(title, text) AGAINST ('"very fast"@3' IN BOOLEAN MODE) ORDER BY title LIMIT 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('"very fast"@3' in boolean mode)) order by `test`.`t1`.`title` limit 1
SELECT FTS_DOC_ID FROM t1 WHERE MATCH(title, text) AGAINST ('"very fast"@3' IN BOOLEAN MODE) ORDER BY title LIMIT 1;
FTS_DOC_ID
11
EXPLAIN
SELECT FTS_DOC_ID, MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) as rank
FROM t1 WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY rank
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) AS `rank` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) order by `rank` limit 3
SELECT FTS_DOC_ID, MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) as rank
FROM t1 WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY rank
LIMIT 3;
FTS_DOC_ID	rank
1	0.15835624933242798
9	0.15835624933242798
12	0.15835624933242798
EXPLAIN
SELECT FTS_DOC_ID, MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) as rank
FROM t1 WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY rank DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: sorted, limit = 3; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) AS `rank` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) order by `rank` desc limit 3
SELECT FTS_DOC_ID, MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) as rank
FROM t1 WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY rank DESC
LIMIT 3;
FTS_DOC_ID	rank
11	1.5415468215942383
5	0.47506874799728394
8	0.31671249866485596
EXPLAIN SELECT FTS_DOC_ID,  MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) as rank
FROM t1
ORDER BY rank DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	NULL	ft_idx	262	NULL	15	100.00	Ft_hints: sorted, limit = 3; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+database' in boolean mode)) AS `rank` from `test`.`t1` order by `rank` desc limit 3
SELECT FTS_DOC_ID,  MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) as rank
FROM t1
ORDER BY rank DESC
LIMIT 3;
FTS_DOC_ID	rank
5	0.47506874799728394
8	0.31671249866485596
1	0.15835624933242798
EXPLAIN SELECT FTS_DOC_ID, MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) as rank
FROM t1
ORDER BY rank DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	NULL	ft_idx	262	NULL	15	100.00	Ft_hints: sorted, limit = 3; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) AS `rank` from `test`.`t1` order by `rank` desc limit 3
SELECT FTS_DOC_ID, MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) as rank
FROM t1
ORDER BY rank DESC
LIMIT 3;
FTS_DOC_ID	rank
11	1.5415468215942383
5	0.47506874799728394
8	0.31671249866485596
EXPLAIN SELECT FTS_DOC_ID,  MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE)
ORDER BY MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE)  DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: sorted, limit = 3; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+database' in boolean mode)) AS `rank` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+database' in boolean mode)) order by (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+database' in boolean mode)) desc limit 3
SELECT FTS_DOC_ID,  MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE)
ORDER BY MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE)  DESC
LIMIT 3;
FTS_DOC_ID	rank
5	0.47506874799728394
8	0.31671249866485596
1	0.15835624933242798
EXPLAIN SELECT FTS_DOC_ID,  MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) and FTS_DOC_ID > 1
ORDER BY MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE)  DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	PRIMARY,FTS_DOC_ID_INDEX,ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: sorted; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+database' in boolean mode)) AS `rank` from `test`.`t1` where ((match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+database' in boolean mode)) and (`test`.`t1`.`FTS_DOC_ID` > 1)) order by (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+database' in boolean mode)) desc limit 3
SELECT FTS_DOC_ID,  MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) and FTS_DOC_ID > 1
ORDER BY MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE)  DESC
LIMIT 3;
FTS_DOC_ID	rank
5	0.47506874799728394
8	0.31671249866485596
9	0.15835624933242798
EXPLAIN
SELECT FTS_DOC_ID,MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) 
ORDER BY rank
LIMIT 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion)) AS `rank` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion)) order by `rank` limit 1
SELECT FTS_DOC_ID,MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) 
ORDER BY rank
LIMIT 1;
FTS_DOC_ID	rank
3	0.009391550906002522
EXPLAIN
SELECT FTS_DOC_ID,MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) 
ORDER BY rank DESC
LIMIT 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: sorted, limit = 1; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion)) AS `rank` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion)) order by `rank` desc limit 1
SELECT FTS_DOC_ID,MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) 
ORDER BY rank DESC
LIMIT 1;
FTS_DOC_ID	rank
11	15.345823287963867
EXPLAIN
SELECT FTS_DOC_ID,MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) 
ORDER BY  MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) 
LIMIT 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion)) AS `rank` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion)) order by (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+very +fast' with query expansion)) limit 1
SELECT FTS_DOC_ID,MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) as rank
FROM t1 WHERE MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) 
ORDER BY  MATCH(title, text) AGAINST ('+very +fast' WITH QUERY EXPANSION) DESC
LIMIT 1;
FTS_DOC_ID	rank
11	15.345823287963867
# WHERE optimization on MATCH > 'some_rank'
EXPLAIN SELECT FTS_DOC_ID FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) > 0.1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: sorted, rank > 0.1; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where ((match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) > 0.1)
SELECT FTS_DOC_ID FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) > 0.1;
FTS_DOC_ID
11
5
8
1
9
12
# additional test for correct behaviour
EXPLAIN SELECT * FROM t1 ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC LIMIT 10;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`t1`.`title` AS `title`,`test`.`t1`.`text` AS `text` from `test`.`t1` order by (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) desc limit 10
SELECT FTS_DOC_ID FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) AND
MATCH (title, text) AGAINST ('mysql' IN NATURAL LANGUAGE MODE)
LIMIT 6;
FTS_DOC_ID
11
5
8
1
9
12
# test OR condition
SELECT FTS_DOC_ID
FROM t1
WHERE MATCH(title, text) AGAINST ('database')
OR MATCH(title, text) AGAINST ('mysql')
ORDER BY  MATCH(title, text) AGAINST ('database') DESC;
FTS_DOC_ID
5
8
1
9
11
12
2
3
4
6
10
14
EXPLAIN SELECT FTS_DOC_ID
FROM t1
WHERE MATCH(title, text) AGAINST ('database')
OR MATCH(title, text) AGAINST ('mysql')
ORDER BY  MATCH(title, text) AGAINST ('database') DESC;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	index	NULL	FTS_DOC_ID_INDEX	8	NULL	15	20.99	Using where; Using index; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where ((match `test`.`t1`.`title`,`test`.`t1`.`text` against ('database')) or (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('mysql'))) order by (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('database')) desc
# MATCH and GROUP BY, DISTINCT
EXPLAIN SELECT FTS_DOC_ID FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
GROUP BY FTS_DOC_ID
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	PRIMARY,FTS_DOC_ID_INDEX,ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: sorted, limit = 3; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) group by `test`.`t1`.`FTS_DOC_ID` order by (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) desc limit 3
SELECT FTS_DOC_ID FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
GROUP BY FTS_DOC_ID
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
FTS_DOC_ID
11
5
8
EXPLAIN SELECT FTS_DOC_ID FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
GROUP BY title
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Using temporary; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) group by `test`.`t1`.`title` order by (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) desc limit 3
SELECT FTS_DOC_ID FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
GROUP BY title
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
FTS_DOC_ID
11
5
8
EXPLAIN SELECT MAX(FTS_DOC_ID) FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Using index
Warnings:
Note	1003	/* select#1 */ select max(`test`.`t1`.`FTS_DOC_ID`) AS `MAX(FTS_DOC_ID)` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) limit 3
SELECT MAX(FTS_DOC_ID) FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
MAX(FTS_DOC_ID)
12
EXPLAIN SELECT DISTINCT(title) FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Using temporary; Using filesort
Warnings:
Note	1003	/* select#1 */ select distinct `test`.`t1`.`title` AS `title` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) order by (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) desc limit 3
SELECT DISTINCT(title) FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
title
The MySQL Database Server is very fast, reliable, scalable, and easy to use
MySQL vs. YourSQL database
MySQL is a database management system
EXPLAIN SELECT DISTINCT(FTS_DOC_ID) FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	PRIMARY,FTS_DOC_ID_INDEX,ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: sorted, limit = 3; Using index
Warnings:
Note	1003	/* select#1 */ select distinct `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) order by (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('fast database')) desc limit 3
SELECT DISTINCT(FTS_DOC_ID) FROM t1
WHERE MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE)
ORDER BY MATCH (title, text) AGAINST ('fast database' IN NATURAL LANGUAGE MODE) DESC
LIMIT 3;
FTS_DOC_ID
11
5
8
# FTS index access
SELECT FTS_DOC_ID, MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) as rank
FROM t1
ORDER BY rank DESC
LIMIT 3;
FTS_DOC_ID	rank
5	0.47506874799728394
8	0.31671249866485596
1	0.15835624933242798
EXPLAIN SELECT FTS_DOC_ID, MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) as rank
FROM t1
ORDER BY rank DESC
LIMIT 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	NULL	ft_idx	262	NULL	15	100.00	Ft_hints: sorted, limit = 3; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+database' in boolean mode)) AS `rank` from `test`.`t1` order by `rank` desc limit 3
SELECT a.FTS_DOC_ID, b.FTS_DOC_ID
FROM t1 a, t1 b
WHERE MATCH(a.title, a.text) AGAINST ('+database' IN BOOLEAN MODE) and
MATCH(b.title, b.text) AGAINST ('+mysql' IN BOOLEAN MODE) and
a.FTS_DOC_ID = b.FTS_DOC_ID;
FTS_DOC_ID	FTS_DOC_ID
5	5
8	8
1	1
9	9
11	11
12	12
EXPLAIN SELECT a.FTS_DOC_ID, b.FTS_DOC_ID
FROM t1 a, t1 b
WHERE MATCH(a.title, a.text) AGAINST ('+database' IN BOOLEAN MODE) and
MATCH(b.title, b.text) AGAINST ('+mysql' IN BOOLEAN MODE)  and
a.FTS_DOC_ID = b.FTS_DOC_ID;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	a	NULL	fulltext	PRIMARY,FTS_DOC_ID_INDEX,ft_idx	ft_idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using index
1	SIMPLE	b	NULL	eq_ref	PRIMARY,FTS_DOC_ID_INDEX,ft_idx	PRIMARY	8	test.a.FTS_DOC_ID	1	11.11	Using where; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`a`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`b`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` `a` join `test`.`t1` `b` where ((`test`.`b`.`FTS_DOC_ID` = `test`.`a`.`FTS_DOC_ID`) and (match `test`.`a`.`title`,`test`.`a`.`text` against ('+database' in boolean mode)) and (match `test`.`b`.`title`,`test`.`b`.`text` against ('+mysql' in boolean mode)))
SELECT a.FTS_DOC_ID, MATCH(a.title, a.text) AGAINST ('+database' IN BOOLEAN MODE),
b.FTS_DOC_ID, MATCH(b.title, b.text) AGAINST ('+database' IN BOOLEAN MODE)
FROM t1 a, t1 b
WHERE MATCH(a.title, a.text) AGAINST ('+database' IN BOOLEAN MODE) and
MATCH(b.title, b.text) AGAINST ('+database' IN BOOLEAN MODE);
FTS_DOC_ID	MATCH(a.title, a.text) AGAINST ('+database' IN BOOLEAN MODE)	FTS_DOC_ID	MATCH(b.title, b.text) AGAINST ('+database' IN BOOLEAN MODE)
5	0.47506874799728394	5	0.47506874799728394
5	0.47506874799728394	8	0.31671249866485596
5	0.47506874799728394	1	0.15835624933242798
5	0.47506874799728394	9	0.15835624933242798
5	0.47506874799728394	11	0.15835624933242798
5	0.47506874799728394	12	0.15835624933242798
8	0.31671249866485596	5	0.47506874799728394
8	0.31671249866485596	8	0.31671249866485596
8	0.31671249866485596	1	0.15835624933242798
8	0.31671249866485596	9	0.15835624933242798
8	0.31671249866485596	11	0.15835624933242798
8	0.31671249866485596	12	0.15835624933242798
1	0.15835624933242798	5	0.47506874799728394
1	0.15835624933242798	8	0.31671249866485596
1	0.15835624933242798	1	0.15835624933242798
1	0.15835624933242798	9	0.15835624933242798
1	0.15835624933242798	11	0.15835624933242798
1	0.15835624933242798	12	0.15835624933242798
9	0.15835624933242798	5	0.47506874799728394
9	0.15835624933242798	8	0.31671249866485596
9	0.15835624933242798	1	0.15835624933242798
9	0.15835624933242798	9	0.15835624933242798
9	0.15835624933242798	11	0.15835624933242798
9	0.15835624933242798	12	0.15835624933242798
11	0.15835624933242798	5	0.47506874799728394
11	0.15835624933242798	8	0.31671249866485596
11	0.15835624933242798	1	0.15835624933242798
11	0.15835624933242798	9	0.15835624933242798
11	0.15835624933242798	11	0.15835624933242798
11	0.15835624933242798	12	0.15835624933242798
12	0.15835624933242798	5	0.47506874799728394
12	0.15835624933242798	8	0.31671249866485596
12	0.15835624933242798	1	0.15835624933242798
12	0.15835624933242798	9	0.15835624933242798
12	0.15835624933242798	11	0.15835624933242798
12	0.15835624933242798	12	0.15835624933242798
EXPLAIN SELECT a.FTS_DOC_ID, MATCH(a.title, a.text) AGAINST ('+database' IN BOOLEAN MODE),
b.FTS_DOC_ID, MATCH(b.title, b.text) AGAINST ('+database' IN BOOLEAN MODE)
FROM t1 a, t1 b
WHERE MATCH(a.title, a.text) AGAINST ('+database' IN BOOLEAN MODE) and
MATCH(b.title, b.text) AGAINST ('+database' IN BOOLEAN MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	a	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Using index
1	SIMPLE	b	NULL	fulltext	ft_idx	ft_idx	0	const	1	100.00	Using where; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`a`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`a`.`title`,`test`.`a`.`text` against ('+database' in boolean mode)) AS `MATCH(a.title, a.text) AGAINST ('+database' IN BOOLEAN MODE)`,`test`.`b`.`FTS_DOC_ID` AS `FTS_DOC_ID`,(match `test`.`b`.`title`,`test`.`b`.`text` against ('+database' in boolean mode)) AS `MATCH(b.title, b.text) AGAINST ('+database' IN BOOLEAN MODE)` from `test`.`t1` `a` join `test`.`t1` `b` where ((match `test`.`a`.`title`,`test`.`a`.`text` against ('+database' in boolean mode)) and (match `test`.`b`.`title`,`test`.`b`.`text` against ('+database' in boolean mode)))
EXPLAIN SELECT FTS_DOC_ID FROM t1 WHERE MATCH(title, text) AGAINST ("data*" IN BOOLEAN MODE) * 100;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	index	NULL	FTS_DOC_ID_INDEX	8	NULL	15	100.00	Using where; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where ((match `test`.`t1`.`title`,`test`.`t1`.`text` against ('data*' in boolean mode)) * 100)
SELECT FTS_DOC_ID, MATCH(title, text) AGAINST ("data*" IN BOOLEAN MODE) * 100
FROM t1 WHERE MATCH(title, text) AGAINST ("data*" IN BOOLEAN MODE) * 100;
FTS_DOC_ID	MATCH(title, text) AGAINST ("data*" IN BOOLEAN MODE) * 100
1	4.92168664932251
5	14.76505994796753
8	9.84337329864502
9	4.92168664932251
11	4.92168664932251
12	4.92168664932251
SELECT * FROM t1 WHERE title IS NULL AND text IS NULL;
FTS_DOC_ID	title	text
15	NULL	NULL
CREATE TABLE t2 SELECT FTS_DOC_ID as doc_id, title, text FROM t1;
ALTER TABLE t2 ADD PRIMARY KEY (doc_id);
ALTER TABLE t2 ADD FULLTEXT KEY ft_idx (title,text);
Warnings:
Warning	124	InnoDB rebuilding table to add column FTS_DOC_ID
ANALYZE TABLE t2;
EXPLAIN SELECT DOC_ID FROM t2 WHERE MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) * 100;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	Using where
Warnings:
Note	1003	/* select#1 */ select `test`.`t2`.`doc_id` AS `DOC_ID` from `test`.`t2` where ((match `test`.`t2`.`title`,`test`.`t2`.`text` against ('+database' in boolean mode)) * 100)
SELECT DOC_ID FROM t2 WHERE MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) * 100;
DOC_ID
1
5
8
9
11
12
EXPLAIN SELECT FTS_DOC_ID FROM t1 WHERE MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) * 100;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	index	NULL	FTS_DOC_ID_INDEX	8	NULL	15	100.00	Using where; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where ((match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+database' in boolean mode)) * 100)
SELECT FTS_DOC_ID FROM t1 WHERE MATCH(title, text) AGAINST ('+database' IN BOOLEAN MODE) * 100;
FTS_DOC_ID
1
5
8
9
11
12
DROP TABLE t1, t2;
"Check hints with uft8 charset for 2 cases"
set names utf8;
CREATE TABLE t1 (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
text TEXT
) CHARACTER SET = utf8, ENGINE=InnoDB;
INSERT INTO t1 (title, text) VALUES
('Я могу есть стекло', 'оно мне не вредит'),
('Мога да ям стъкло', 'то не ми вреди'),
('Μπορῶ νὰ φάω σπασμένα' ,'γυαλιὰ χωρὶς νὰ πάθω τίποτα'),
('Příliš žluťoučký kůň', 'úpěl ďábelské kódy'),
('Sævör grét', 'áðan því úlpan var ónýt'),
('うゐのおくやま','けふこえて'),
('いろはにほへど ちりぬる','あさきゆめみじ ゑひもせず');
CREATE FULLTEXT INDEX idx on t1 (title, text);
# No ranking
EXPLAIN
SELECT count(*) FROM t1 WHERE MATCH (title, text) AGAINST ('вредит' IN NATURAL LANGUAGE MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select count(0) AS `count(*)` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('вредит'))
SELECT count(*) FROM t1 WHERE MATCH (title, text) AGAINST ('вредит' IN NATURAL LANGUAGE MODE);
count(*)
1
EXPLAIN
SELECT * FROM t1 WHERE MATCH(title, text) AGAINST ("оно" WITH QUERY EXPANSION);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	idx	idx	0	const	1	100.00	Using where; Ft_hints: sorted
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID`,`test`.`t1`.`title` AS `title`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('оно' with query expansion))
SELECT * FROM t1 WHERE MATCH(title, text) AGAINST ("оно" WITH QUERY EXPANSION);
FTS_DOC_ID	title	text
1	Я могу есть стекло	оно мне не вредит
# No sorting by rank
EXPLAIN SELECT FTS_DOC_ID FROM t1
WHERE MATCH(title, text) AGAINST ('+(Мога τίποτα)' IN BOOLEAN MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	idx	idx	0	const	1	100.00	Using where; Ft_hints: no_ranking; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`FTS_DOC_ID` AS `FTS_DOC_ID` from `test`.`t1` where (match `test`.`t1`.`title`,`test`.`t1`.`text` against ('+(Мога τίποτα)' in boolean mode))
SELECT FTS_DOC_ID  FROM t1
WHERE MATCH(title, text) AGAINST ('+(Мога τίποτα)' IN BOOLEAN MODE);
FTS_DOC_ID
2
3
DROP TABLE t1;
#
# Bug #18924341 CRASH IN TEST_IF_SKIP_SORT_ORDER, GROUP BY MATCH AGAINST DESC
#
CREATE TABLE t1 (f1 CHAR(1), FULLTEXT KEY (f1));
SELECT 1 FROM t1 NATURAL JOIN t1 a GROUP BY MATCH(t1.f1) AGAINST ("1") DESC;
1
Warnings:
Warning	1287	'GROUP BY with ASC/DESC' is deprecated and will be removed in a future release. Please use GROUP BY ... ORDER BY ... ASC/DESC instead
DROP TABLE t1;
#
# Bug#20261601 ASSERTION FAILED: !FIRST_QEP_TAB->TABLE()->NO_KEYREAD
#
CREATE TABLE t1(a INT PRIMARY KEY);
INSERT INTO t1 VALUES(1),(2);
SELECT (SELECT MATCH(`a`)AGAINST('1') FROM t1) FROM t1;
ERROR HY000: Can't find FULLTEXT index matching the column list
SELECT 1, a IN (SELECT a FROM t1) FROM t1;
1	a IN (SELECT a FROM t1)
1	1
1	1
DROP TABLE t1;
#
# Bug#20442572 ASSERTION `!FIRST_QEP_TAB->TABLE()->NO_KEYREAD' FAILED.
# Bug#75688 Assertion `!first_qep_tab->table()->no_keyread' failed.
#
CREATE TABLE t1(a INT,b POINT NOT NULL,KEY(a));
HANDLER t1 OPEN;
select * from t1 where MATCH a,b AGAINST('"Now sUPPort"' IN BOOLEAN MODE);
ERROR HY000: Can't find FULLTEXT index matching the column list
prepare stmt1 from "truncate t1";
SELECT a IN(SELECT a FROM t1)FROM t1;
a IN(SELECT a FROM t1)
deallocate prepare stmt1;
DROP TABLE t1;
#
# Bug #20685427 INVALID WRITE OF FREED MEMORY IN ITEM_FUNC_MATCH::CLEANUP
#
CREATE TABLE t1(a TEXT CHARSET LATIN1, FULLTEXT KEY(a)) ENGINE=INNODB;
SELECT MATCH(a) AGAINST ('') FROM (SELECT a FROM t1 LIMIT 1) q;
ERROR HY000: Can't find FULLTEXT index matching the column list
DROP TABLE t1;
#
# Bug#21140067 EXPLAIN .. MATCH AGAINST: ASSERTION FAILED: TO <= END
#
CREATE TABLE t1(f1 CHAR(1) CHARSET latin1, FULLTEXT(f1)) ENGINE=INNODB;
EXPLAIN SELECT 1 FROM t1 WHERE 1.238585e+308 <= MATCH(f1) AGAINST ('1' IN BOOLEAN MODE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	fulltext	f1	f1	0	const	1	100.00	Using where; Ft_hints: rank >= 1e308
Warnings:
Note	1003	/* select#1 */ select 1 AS `1` from `test`.`t1` where (1.238585e+308 <= (match `test`.`t1`.`f1` against ('1' in boolean mode)))
EXPLAIN FORMAT = JSON SELECT 1 FROM t1 WHERE 1.238585e+308 <= MATCH(f1) AGAINST ('1' IN BOOLEAN MODE);
EXPLAIN
{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "1.20"
    },
    "table": {
      "table_name": "t1",
      "access_type": "fulltext",
      "possible_keys": [
        "f1"
      ],
      "key": "f1",
      "used_key_parts": [
        "f1"
      ],
      "key_length": "0",
      "ref": [
        "const"
      ],
      "rows_examined_per_scan": 1,
      "rows_produced_per_join": 1,
      "filtered": "100.00",
      "ft_hints": "rank >= 1e308",
      "cost_info": {
        "read_cost": "1.00",
        "eval_cost": "0.20",
        "prefix_cost": "1.20",
        "data_read_per_join": "8"
      },
      "used_columns": [
        "f1"
      ],
      "attached_condition": "(1.238585e+308 <= (match `test`.`t1`.`f1` against ('1' in boolean mode)))"
    }
  }
}
Warnings:
Note	1003	/* select#1 */ select 1 AS `1` from `test`.`t1` where (1.238585e+308 <= (match `test`.`t1`.`f1` against ('1' in boolean mode)))
DROP TABLE t1;
#
# Bug#21140088 MATCH AGAINST: ASSERTION FAILED: !TABLE || (!TABLE->READ_SET || BITMAP_IS_SET
#
SET sql_mode='';
Warnings:
Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
CREATE TABLE t1(a INT) ENGINE=INNODB;
CREATE TABLE t2(b TEXT CHARSET LATIN1, FULLTEXT(b), PRIMARY KEY(b(10))) ENGINE=INNODB;
INSERT INTO t2 VALUES ('a'),('b');
SELECT NOT EXISTS (SELECT MATCH(b) AGAINST ('1') FROM t1) FROM t2 GROUP BY "a";
ERROR HY000: Incorrect arguments to MATCH
DROP TABLE t1, t2;
CREATE TABLE t1(a INT) ENGINE=MyISAM;
CREATE TABLE t2(b TEXT CHARSET LATIN1, FULLTEXT(b), PRIMARY KEY(b(10))) ENGINE=MyISAM;
INSERT INTO t2 VALUES ('a'),('b');
SELECT NOT EXISTS (SELECT MATCH(b) AGAINST ('1' in BOOLEAN MODE) FROM t1) FROM t2 GROUP BY "a";
ERROR HY000: Incorrect arguments to MATCH
DROP TABLE t1, t2;
SET sql_mode=default;
#
# Bug#21140039 ASSERTION FAILED: !FIRST_QEP_TAB->TABLE()->NO_KEYREAD MATCH AGAINST.....
#
CREATE TABLE t1
(
a INT,
b INT,
c CHAR(1) CHARSET latin1,
PRIMARY KEY (b,a),
FULLTEXT KEY (c)
) ENGINE=INNODB;
SELECT "a" NOT IN(SELECT b FROM t1 WHERE MATCH(c) AGAINST ('a' IN BOOLEAN MODE));
"a" NOT IN(SELECT b FROM t1 WHERE MATCH(c) AGAINST ('a' IN BOOLEAN MODE))
1
DROP TABLE t1;
#
# Bug#21300774 ASSERT `!INIT_FTFUNCS(THD, SELECT_LEX)` IN JOIN::RESET AT SQL/SQL_SELECT.CC:874
#
CREATE TABLE t1 (f1 INT);
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
CREATE TABLE t2 (ft TEXT, FULLTEXT KEY ft(ft));
INSERT INTO t2 VALUES ('abc');
INSERT INTO t2 VALUES ('def');
UPDATE t1 SET f1 =
(SELECT t1.f1 FROM t2 WHERE NOT TRUE AND
MATCH (ft) AGAINST ((SELECT 'xyz' FROM t2)));
ERROR 21000: Subquery returns more than 1 row
DROP TABLE t1, t2;
#
# Bug#22679209: FULL-TEXT QUERIES WITH ADDITIONAL SECONDARY INDEX
#               GIVES NULL OR ZERO ROWS
#
CREATE TABLE t1 (
f1 INTEGER,
title varchar(255),
body mediumtext,
KEY f1 (f1),
FULLTEXT KEY title (title),
FULLTEXT KEY body (body)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES
(1, 'Insert into table', 'insert into table select from'),
(1, 'Delete from table', 'insert into table select from'),
(1, 'Update',            'perform update'),
(2, 'Insert into table', 'insert into table select from'),
( 2, 'Delete from table', 'some body text here'),
( 2, 'Update',            'perform update'),
( 3, 'Insert into table', 'insert into table select from'),
( 3, 'Delete from table', 'some body text here');
SELECT f1 FROM t1 WHERE f1=1 AND
(MATCH (title) AGAINST ('table' IN BOOLEAN MODE) OR
MATCH (body) AGAINST ('table' IN BOOLEAN MODE));
f1
1
1
DROP TABLE t1;
# End of test for Bug#22679209

Man Man