InnoDB
Fulltext Search
Database Management
MySQL
SQL Optimization

Fulltext Search with InnoDB

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

InnoDB supports full-text indexing so MySQL can search large text columns more intelligently than simple LIKE scans. The feature is useful for natural-language style queries, but it works best when you understand its indexing rules, search modes, and limitations around stopwords and token size.

Creating a Full-Text Index

You can create a full-text index on CHAR, VARCHAR, or TEXT columns.

sql
1CREATE TABLE articles (
2    id BIGINT PRIMARY KEY AUTO_INCREMENT,
3    title VARCHAR(255) NOT NULL,
4    body TEXT NOT NULL,
5    FULLTEXT KEY ft_title_body (title, body)
6) ENGINE=InnoDB;

Once the index exists, MySQL can evaluate MATCH ... AGAINST queries efficiently.

The default search mode is natural language mode:

sql
1SELECT id, title,
2       MATCH(title, body) AGAINST ('database tuning') AS score
3FROM articles
4WHERE MATCH(title, body) AGAINST ('database tuning')
5ORDER BY score DESC;

This returns rows ranked by relevance. Unlike LIKE '%database%', the full-text engine tokenizes and scores results instead of scanning blindly for a substring.

Boolean Mode

Boolean mode gives you more control over required terms, excluded terms, and optional weighting.

sql
SELECT id, title
FROM articles
WHERE MATCH(title, body) AGAINST ('+mysql -oracle +index' IN BOOLEAN MODE);

In this example:

  • '+mysql means the term must appear'
  • '-oracle means the term must not appear'
  • '+index also must appear'

Boolean mode is useful when you want search syntax closer to query operators than to pure relevance ranking.

Loading Sample Data

sql
1INSERT INTO articles (title, body) VALUES
2('MySQL indexing basics', 'This article covers index design and database tuning.'),
3('InnoDB fulltext guide', 'Learn how InnoDB fulltext search works in natural language mode.'),
4('Query optimization tips', 'Use the right index strategy for heavy search workloads.');

Now you can run:

sql
SELECT id, title
FROM articles
WHERE MATCH(title, body) AGAINST ('fulltext search');

This is the simplest end-to-end example: create the index, load rows, and query with MATCH ... AGAINST.

Stopwords and Minimum Token Length

Two settings affect what gets indexed:

  • stopwords
  • minimum token size

Common words may be ignored entirely, and very short terms may not be indexed depending on server settings. With InnoDB, token-size configuration affects whether short terms such as abbreviations or two-letter words can be searched meaningfully.

This explains many "why did my term return nothing?" questions. The row may exist, but the term was never indexed in the first place.

When Full-Text Search Is a Good Fit

InnoDB full-text search is useful when:

  • search lives inside MySQL already
  • the corpus is moderate in size
  • you want relevance ranking without introducing a separate search engine

It is less suitable when you need sophisticated linguistic analysis, typo tolerance, synonyms, highlighting, or large-scale search features. At that point, dedicated search systems may be a better fit.

Common Pitfalls

The most common mistake is expecting MATCH ... AGAINST to behave exactly like LIKE. Full-text search works on indexed tokens and relevance, not arbitrary substrings.

Another issue is forgetting to create a full-text index before benchmarking. Without the index, you do not get the intended search behavior or performance.

A third pitfall is ignoring stopwords and token-size rules. If short words or common words are important to your application, default indexing rules may not match your expectations.

Finally, do not assume relevance ordering is business ordering. Full-text score is useful, but many applications still combine it with publish date, category filters, or custom ranking logic.

Summary

  • InnoDB full-text search uses FULLTEXT indexes and MATCH ... AGAINST queries.
  • Natural language mode ranks results by relevance.
  • Boolean mode gives explicit control over required and excluded terms.
  • Stopwords and token-size settings affect what can be searched.
  • Full-text search is powerful inside MySQL, but it is not a full replacement for a dedicated search engine in every case.

Course illustration
Course illustration

All Rights Reserved.