Regular Expression Matching with a Trigram Index (2012)
swtch.com
swtch.com
https://codesearch.debian.net/
(If you want a lot more details, check out my thesis on it: https://codesearch.debian.net/research/bsc-thesis.pdf)
Everything old will be new again.
[1] for the curious - the header is basically uint64_t file_offsets_to_3gram_data[2**24].
Usually when I write regex someone describes me as a monster. I guess both could be accurate!
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX IF NOT EXISTS lowercase_title ON streams (lower(title));
CREATE INDEX IF NOT EXISTS title_trgm ON streams USING gin (lower(title) gin_trgm_ops);
And boom, super performant search via `LIKE %{}%`.
I also love taking advantage of `TABLESAMPLE system_rows()` which lets me do hyperfast random selection without needing to randomly sort the entire table. PG has so many hidden gems.
Past discussions: https://hn.algolia.com/?q=regexp4.html