ngram Fulltext Parser — SQL Technical Interview Questions & Answers

ngram Fulltext Parser

ngram Fulltext Parser

  • FULLTEXT index lets MATCH (title, body) AGAINST ('exam prep') search words, not LIKE '%exam%'. Needs a FULLTEXT index on those columns (InnoDB in 5.6+).
  • Natural language mode is default. BOOLEAN MODE uses +must -mustnot. Query expansion is a follow-up search — mention only if asked.
  • Trap: FULLTEXT on InnoDB with tiny tables (minimum token length, stopwords). Trap: MATCH on columns that are not in the index together.
  • On the example next to this theory: ngram Fulltext Parser: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Technical Interview Tip: MATCH (col) AGAINST ('words') needs a FULLTEXT index.

Code Examples for ngram Fulltext Parser

ngram Fulltext Parser — sample query

-- ngram Fulltext Parser
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

ngram Fulltext Parser: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

How to Explain ngram Fulltext Parser to an Interviewer

How do you search words in MySQL?

FULLTEXT index MATCH … AGAINST