A full-text index in SQL
LIKE scans every row. A full-text index knows which rows hold the word.
CREATE VIRTUAL TABLE doc_search USING fts5(
title,
body,
slug UNINDEXED,
tokenize = 'porter unicode61'
);
INSERT INTO doc_search (title, body, slug)
VALUES ('Indexing text', 'Full-text search finds words, not substrings.',
'indexing-text'),
('Query plans', 'Read the plan before optimizing the query.',
'query-plans');
How it works
CREATE VIRTUAL TABLE ... USING fts5lists the columns to index.UNINDEXEDkeeps a column retrievable without adding it to the index.- Inserting into the virtual table is what builds the index.
Keywords and builtins used here
CREATEINSERTINTOTABLEUSINGVALUES
The run, in numbers
- Lines
- 12
- Characters to type
- 319
- Tokens
- 46
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 29 seconds.
Step 1 of 4 in Full-text search, step 9 of 14 in JSON & search.