Chapter 09 · Index Design, FULLTEXT, Spatial, Vector, and Specialized Access Paths
FULLTEXT Indexes, Tokenization, Boolean/Natural Language Search, and Limits
Build and evaluate MariaDB FULLTEXT search through tokenization, stopwords, natural/boolean modes, relevance, engine-specific settings, rebuild behavior, and explicit search-system boundaries.
Learning outcomes
ServiceHub operators search incident notes with phrases such as
“packet loss router” and expect relevant records rather than an
expensive LIKE '%packet loss%' scan. A FULLTEXT
index is designed for token-based text search, but it is not a
substring index and its results depend on storage engine,
parser/tokenization rules, stopwords, minimum token length,
collation and search mode. Treating it as a magical replacement
for every text-search system produces surprising omissions.
Identify MariaDB engines and column types that support FULLTEXT indexes.
Explain tokenization, stopwords and minimum-token settings as index-build semantics.
Distinguish natural-language, boolean and query-expansion modes and interpret relevance carefully.
Diagnose the classic mistake of expecting arbitrary substring or multilingual segmentation behavior.
Choose between built-in FULLTEXT and a dedicated search system from functional requirements rather than unsupported scale claims.
Current MariaDB documentation supports FULLTEXT indexes on MyISAM, Aria, InnoDB and Mroonga; FULLTEXT columns must be CHAR/VARCHAR/TEXT. Partitioned tables cannot contain FULLTEXT indexes. Mroonga is an optional engine/plugin with its own packaging/platform constraints and is not required for this lesson.
1. Build an InnoDB FULLTEXT index and make token search observable
USE servicehub_index_lab;CREATE TABLE knowledge_articles ( article_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(180) NOT NULL, body TEXT NOT NULL, FULLTEXT KEY ft_title_body(title,body)) ENGINE=InnoDB;INSERT INTO knowledge_articles(title,body) VALUES ('Diagnose packet loss','Measure loss, latency and interface errors before replacing the router.'), ('Router reboot loop','Inspect power, temperature and firmware logs before rebooting again.'), ('Fiber attenuation','Measure optical power and clean connectors before escalation.'), ('VPN authentication','Check certificate expiry and MFA synchronization for remote users.'), ('Packet capture workflow','Capture packets near the failing interface and record timestamps.');SHOW CREATE TABLE knowledge_articles\GSHOW INDEX FROM knowledge_articles;
SELECT article_id,title, MATCH(title,body) AGAINST ('packet router' IN NATURAL LANGUAGE MODE) AS relevanceFROM knowledge_articlesWHERE MATCH(title,body) AGAINST ('packet router' IN NATURAL LANGUAGE MODE)ORDER BY relevance DESC, article_id;EXPLAINSELECT article_id,titleFROM knowledge_articlesWHERE MATCH(title,body) AGAINST ('packet router' IN NATURAL LANGUAGE MODE);
Natural-language mode evaluates indexed terms and produces a relevance value. Relevance is an engine/search-mode score, not a universal semantic probability. Use it to order candidates in this search contract, and validate whether the ranking actually serves the application’s users.
2. Boolean mode exposes explicit term requirements
SELECT article_id,title, MATCH(title,body) AGAINST ('+packet +router -vpn' IN BOOLEAN MODE) AS scoreFROM knowledge_articlesWHERE MATCH(title,body) AGAINST ('+packet +router -vpn' IN BOOLEAN MODE)ORDER BY score DESC, article_id;
Boolean mode adds operators for required, excluded, weighted and wildcard-like token matching. Its syntax is useful for operator-facing search boxes, but exposing raw boolean syntax to end users can create usability and escaping concerns. If application input is converted into boolean syntax, treat it as its own parser/validation problem rather than concatenating arbitrary text into SQL.
3. Deliberately wrong: expect FULLTEXT to implement arbitrary substring matching
-- A user wants any body containing the character substring "atten".SELECT article_id,titleFROM knowledge_articlesWHERE MATCH(title,body) AGAINST ('atten' IN NATURAL LANGUAGE MODE);-- Compare the literal substring semantics (potentially scan-heavy):SELECT article_id,titleFROM knowledge_articlesWHERE body LIKE '%atten%';
FULLTEXT indexes work with parsed tokens, not arbitrary
character substrings. Searching for a fragment inside a longer
token can return nothing even though LIKE finds a
row. Boolean-mode wildcard behavior can extend token prefixes in
supported cases, but it still does not transform FULLTEXT into a
general n-gram substring engine. The repair is to define the
actual search requirement first: token search, prefix
completion, fuzzy matching, CJK segmentation, phrase ranking or
arbitrary substring search are different problems.
4. Stopwords and minimum token length belong to the index contract
SHOW VARIABLES LIKE 'ft_min_word_len';SHOW VARIABLES LIKE 'ft_stopword_file';SHOW VARIABLES LIKE 'innodb_ft_min_token_size';SHOW VARIABLES LIKE 'innodb_ft_enable_stopword';SHOW VARIABLES LIKE 'innodb_ft_server_stopword_table';
MariaDB distinguishes legacy MyISAM FULLTEXT variables such as
ft_min_word_len from InnoDB FULLTEXT variables such
as innodb_ft_min_token_size. Stopword configuration
is also engine-specific. If you change token-size or stopword
settings, existing FULLTEXT indexes do not magically reinterpret
their old token set; plan and test the required rebuild/reindex
procedure for the exact engine and version.
Defaults and built-in stopword sets are version/engine details. Record effective variables on the actual server and include them in migration/recovery tests. A restored or replicated environment with a different parser configuration can produce different search behavior even when table rows are identical.
5. Engine choice and multilingual search require explicit verification
InnoDB gives ServiceHub the transactional storage model used elsewhere in the course and includes built-in FULLTEXT. MyISAM and Aria also support FULLTEXT with different transaction/locking/recovery contracts. Mroonga is an optional Groonga-based storage engine designed for full-text use cases including CJK-ready search, but its plugin/package/platform prerequisites must be verified before it enters an architecture decision.
| Requirement | Built-in InnoDB FULLTEXT question | Possible reason to evaluate dedicated/optional search |
|---|---|---|
| Simple token search near transactional data | Often a good candidate | Only move if requirements exceed built-in behavior. |
| CJK or language-specific segmentation | Test parser behavior explicitly | Specialized analyzers/tokenizers may be required. |
| Fuzzy/typo tolerance | Not the same as standard FULLTEXT token matching | Search systems may offer richer fuzzy analyzers. |
| Complex facets/highlighting/synonyms | Validate exact MariaDB feature fit | A dedicated search engine may expose broader search features. |
| Transactional source of truth | InnoDB keeps search data in the same database transaction domain | External indexing introduces synchronization/lag/failure boundaries. |
This is a feature-and-correctness comparison, not a claim that one engine “scales better.” Benchmark your corpus, query mix, update rate and result-quality requirements. Search quality is as important as query latency.
6. Rebuild and migration discipline
CREATE TABLE bulk_articles ( article_id BIGINT UNSIGNED NOT NULL PRIMARY KEY, title VARCHAR(180) NOT NULL, body TEXT NOT NULL) ENGINE=InnoDB;INSERT INTO bulk_articles SELECT article_id,title,body FROM knowledge_articles;ALTER TABLE bulk_articles ADD FULLTEXT KEY ft_bulk(title,body);CHECK TABLE bulk_articles;
MariaDB documentation notes that for large data sets it can be faster to load data before creating the FULLTEXT index. That is a workload-dependent operational pattern, not a promise for every dataset. For production migrations, measure build duration, disk/temp-space needs, lock/DDL behavior, replica/Galera implications and recovery plan before applying the change to a busy table.
7. Verification checklist, production judgment, and bridge
- Verify the table engine and that indexed columns use a FULLTEXT-supported string type.
- Record effective token-size and stopword variables for the actual engine.
- Test natural-language and boolean queries against a labeled set of expected results.
- Include intentionally short, stopword-like, multilingual and substring cases to expose boundaries.
- Plan index rebuild behavior before changing parser/token settings.
- Decide whether search belongs inside MariaDB or in a separate search service by requirements and operational cost.
Check your understanding
- Why can LIKE %atten% find a row that MATCH ... AGAINST(atten) does not?
- Which built-in MariaDB storage engines support FULLTEXT according to current documentation?
- Why must InnoDB and MyISAM minimum-token settings not be conflated?
- What is the operational consequence of changing stopword/token settings?
- Why is relevance not a probability of semantic correctness?
Review the answers
FULLTEXT indexes parsed tokens rather than arbitrary character substrings. Current documentation lists MyISAM, Aria, InnoDB and Mroonga as FULLTEXT-capable engines, with Mroonga optional. MyISAM and InnoDB use different FULLTEXT configuration variables and internals. Changing parser/token settings generally requires rebuilding affected indexes for the new rules to apply. Relevance is a search-engine score under a particular index, corpus and mode; it must be evaluated against application expectations rather than interpreted as a calibrated probability.
Next, spatial access paths replace token matching with geometry relationships. The most important new distinction is between an R-tree bounding-box access path and the exact shape predicate used to confirm geometric truth.
8. Build a search-quality test set, not only a latency benchmark
Text search can be fast and still be wrong for users. Before accepting a FULLTEXT design, create a small labeled corpus with queries whose expected results are known: exact terminology, synonyms, short words, stopwords, prefixes, punctuation, multilingual text and deliberately ambiguous phrases. Store the expected top results outside the search index so an index rebuild or server upgrade cannot silently redefine your test oracle.
Run the same corpus in natural-language and boolean modes and record both result membership and order. A change in stopword tables, token-size variables, collation or parser behavior can alter which terms enter the index, so migration validation must compare search quality as well as DDL success. If a restore produces all rows but a different FULLTEXT configuration, ordinary row-count checks can pass while search behavior has changed materially.
Operationally, monitor search workload separately from ordinary point lookups. FULLTEXT index creation and maintenance consume I/O and storage, and large text updates can create a very different write pattern from updating narrow B-tree keys. When search traffic grows, measure query latency, index size, write throughput and user-relevance metrics together. Do not respond to one slow query by globally changing token settings without checking every application that shares the server.
If requirements include sophisticated language analyzers, typo tolerance, custom ranking pipelines, highlighting, synonym management or distributed search features that MariaDB does not provide in the needed form, keeping MariaDB as the transactional source of truth and publishing changes to a dedicated search system can be cleaner. That introduces synchronization and recovery complexity, so make the boundary explicit and test lag/failure behavior.