Database / SQLite Interview questions
Why might full-text search (FTS5) be needed instead of a LIKE query?
A LIKE '%word%' query has to scan every row and check the pattern against each one, since a
leading wildcard prevents SQLite from using a normal B-tree index at all — on a large table, this means
a full table scan for every search, which gets slower as the table grows and offers none of the
relevance-ranking or linguistic features (stemming, tokenization) a real search feature typically needs.
-- slow: full table scan, no relevance ranking SELECT * FROM articles WHERE body LIKE '%database%'; -- FTS5: indexed, ranked full-text search CREATE VIRTUAL TABLE articles_fts USING fts5(title, body); SELECT * FROM articles_fts WHERE articles_fts MATCH 'database';
FTS5 is SQLite's built-in full-text search extension: it builds a specialized inverted index over
the text (mapping words to the rows containing them), supporting fast MATCH queries, relevance
ranking, phrase search, and prefix matching — capabilities a plain LIKE scan simply can't
provide efficiently or at all, regardless of table size.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
