Check a filtered FULLTEXT query and its plan¶
This recipe uses the older FULLTEXT index, separate from FULLTEXT2. Search for a phrase, add a category filter, and inspect EXPLAIN. The existing Boolean search tutorial covers search syntax.
SET fulltext_bloom_filter_pushdown=1;
CREATE DATABASE cookbook_fulltext_plan;
CREATE TABLE cookbook_fulltext_plan.articles(
id BIGINT PRIMARY KEY, title TEXT, body TEXT, category VARCHAR(20));
INSERT INTO cookbook_fulltext_plan.articles VALUES
(1,'Machine learning','A practical machine learning guide','tech'),
(2,'Machine learning','A general introduction','news'),
(3,'Gardening','Growing tomatoes','home');
CREATE FULLTEXT INDEX ft_article ON cookbook_fulltext_plan.articles(title,body);
EXPLAIN SELECT id FROM cookbook_fulltext_plan.articles
WHERE MATCH(title,body) AGAINST('machine learning') AND category='tech';
SELECT id FROM cookbook_fulltext_plan.articles
WHERE MATCH(title,body) AGAINST('machine learning') AND category='tech'
ORDER BY id;
DROP DATABASE cookbook_fulltext_plan;
The filtered query should return the tech article 1 only. Inspect EXPLAIN for the chosen access path on your version and dataset; a tiny table does not prove a performance gain from pushdown. See the v4.2.4 source test.