# Run, SQL Run!

DevFeed: [Run, SQL Run!](<https://devfeed.tech/articles/run-sql-run-91138.md>)

Original publisher: [Read original article](<https://proandroiddev.com/run-sql-run-58b1045dce4a?source=rss----c72404660798---4>)

Author: Burak Karaduman

Published: 2026-10-20T16:28:24Z

Content type: tutorial

Language: en

Sources: [ProAndroidDev](<https://devfeed.tech/sources/proandroiddev-medium.md>)

Topics: [rdbms](<https://devfeed.tech/topics/rdbms.md>), [email](<https://devfeed.tech/topics/email.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [full-text-search](<https://devfeed.tech/tags/full-text-search.md>), [indexing](<https://devfeed.tech/tags/indexing.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [offline-first](<https://devfeed.tech/tags/offline-first.md>), [performance](<https://devfeed.tech/tags/performance.md>), [room](<https://devfeed.tech/tags/room.md>), [room-database](<https://devfeed.tech/tags/room-database.md>), [sql](<https://devfeed.tech/tags/sql.md>)

## AI overview

The excerpt describes using SQLite FTS4 with Room to speed up local email search in an offline-capable app. FTS indexes text as searchable tokens linked to source rows, then uses that index to find matching keywords. In the demo, `LIKE` with a prefix pattern checks only the beginnings of fields, while FTS can match terms elsewhere, so FTS returns more results. On a database of 20,776 items, the author reports that FTS found more matches faster for the tested queries, but gives no numerical timings here. The five consecutive trials used to average query duration may benefit from caching; no cache-control improvement was implemented.

## Source excerpt

Searching data like products, messages or emails is one of the most common features in modern applications. There are couple of ways to implement this. In many cases, the client works together with backend services for searching. But, for fully client based or offline first app without network connection, we must execute search operations locally. When the number of tables and rows grows, local queries can become slow. To handle this performance issue, a widely used technique is full text search. Our goal is to achieve the same search functionality that exists in current Gmail application. Image generated with ChatGPTAbout The Demo It is demonstrated in a sample email application, which displays only emails with sender, subject, and body. After performing a search, it is possible to see the number of results, the average time taken, and the times from all five trials. Also note that while FTS searches every content in every field, a query using LIKE only searches the beginnings of tields, so the results are not exactly the same. FTS generally finds more matches. How Does FTS Work Generally? There are two phases in full text search: indexing and searching. Full text search uses a virtual table to index text columns for faster search. While indexing, the text is split into searchable tokens, and each token is linked with its source row through a special column called docid, which points to the original document in the normal table. After the index is generated, users can search, and the system processes the query and uses index to locate documents that contain the matching keywords. FTS4 Usage With Room Room library was used in this demo, which provides built in support, and the setup is easy to do. Firstly, we must have a normal table. https://medium.com/media/84455741835c2f3883228f41aee4585f/href Then we can add the FTS version of it by providing FTS4 annotation with required properties in FTS table. For our case I added all of these. https://medium.com/media/1b3f03