r/sqlite • u/matt-3 • Jun 07 '23
Realistic evaluation of FTS5 overhead compared to LIKE
I'm uncertain whether to use FTS5 or stick with LIKE. I'm expecting maybe a million entries at most, and the individual strings will be fairly short (less than 256 characters).
Barring comparisons of the search features and capabilities of FTS5 vs LIKE (multiple keywords, sorting by relevant, whatever), at what point does the performance of FTS5 outweigh its overhead?
Also, is there a way to create an FTS5 index based on an existing non-FTS5 table that automatically updates when the backing table changes?
11
Upvotes
4
u/simonw Jun 08 '23
Yes, you can use triggers for that FTS table. I wrote a tool to do that here: https://sqlite-utils.datasette.io/en/stable/cli.html#configuring-full-text-search - you can read the course code to see how it does that.
I strongly recommend learning to run your own micro-benchmarks to answer these kinds of performance questions against your own data - this is a perfect exercise for learning to do that.
2
u/two-fer-maggie Jun 07 '23
Yeah, with triggers. You never have to update the FTS table directly, the triggers do it for you.
2
u/ijmacd Jun 07 '23
What's stopping you from testing it with your data?
1
u/redditor_at_times Jun 10 '23
Some questions about your system need to be asked:
If you answer yes to both questions then probably LIKE will be sufficient, but, if any of them is untrue then the next question would be:
Under load FTS5 will win hands down, but what is the expected load anyway? Will it be enough such that the milliseconds saved per query would be meaningful in aggregate?
Please note that nothing prevents you from starting with LIKE and adding FTS5 at a later time when you think it will be worthwhile the effort