TL;DR
Searching massive database columns with regular expressions (regexes) is painfully slow when the pattern contains wildcards that bypass standard indexes—especially when you only want a quick preview of the first k matches. RIVET solves this by training a lightweight neural model to "translate" complex regexes into short, column-specific prefix keys that can use existing indexes. By jumping straight to high-yield buckets of data and letting the native database engine verify the final outputs, RIVET speeds up interactive queries by up to 36× over state-of-the-art regex indexes with zero loss in exactness.
What Problem Does This Paper Address?
Imagine it’s late, an outage is unfolding, and you’re querying millions of log lines with a regex, adding LIMIT 64 just to preview if your pattern works. Under the hood, regex engines are exact verifiers, not searchers; checking millions of rows one by one (a sequential scan) takes forever.
Databases usually accelerate this using a "key-then-verify" approach: extract literal substrings or trigrams directly from the regex surface, probe an index to grab candidate rows, and run the expensive regex check only on the survivors.
Here is the catch: reading keys off the regex surface is completely blind to the actual data distribution. Take the query ^T.*son$ on a column of names. A traditional index extractor might grab son, pulling in thousands of "Andersons" and "Aaronsons" that fail verification. Meanwhile, a prefix like Tho or Tim isn't explicitly in the regex, yet in this specific column, it points straight to "Thompson" and "Timson". For LIMIT-k queries, the bottleneck is finding a handful of indexable keys that point to match-rich candidate buckets first, so the engine can find k matches and clock out early.
Methods
RIVET reframes candidate selection as constrained neural translation, pairing a small learned model with standard, battle-tested database machinery.
- What’s New (Offline & Online Translation): Without needing historical query logs, RIVET samples "anchor" records directly from the target text column, synthesizes regexes that match them, and extracts each record's fixed-length prefix (e.g., first $\ell$ characters). A compact (30M-parameter), character-level Transformer seq2seq model is trained to translate a regex into these prefixes. Because the same synthesized regex naturally hits multiple records during sampling, the model learns to place probability mass across multiple valid prefixes. At query time, RIVET uses a mix of beam search (for high-probability hits) and temperature sampling (for diversity) to propose keys, filters them against the column's actual prefix dictionary, deduplicates them, and caps them at a strict budget ($t_{\text{max}}$).
- What’s Standard (Execution & Exactness): Databases don't trust neural nets with exact semantics—and RIVET doesn't ask them to. The generated prefixes simply become standard indexed queries (like
LIKE 'Tho%'on an existing B-tree). The native regex engine verifies every retrieved candidate, halting the moment k matches are found. If the key budget runs dry before hitting k—say, if you strictly require a full limit rather than a quick preview—a residual table scan cleanly finishes the job.
Datasets
RIVET is evaluated on four large text columns ranging from 2 million to 24 million rows:
- IMDB person names (5.0M rows)
- WIKI article titles (2.0M rows)
- TPC-H
lineitem.commentstrings (24.0M rows) - US-Acc traffic accident descriptions (7.72M rows)
Alongside four synthesized PostgreSQL regex workloads varying in wildcard complexity, the authors introduce an out-of-distribution (OOD) benchmark of 80 human-authored regexes mined from StackOverflow and arXiv—featuring denser character classes and tricky infix/suffix constraints—without retraining the models.
Key Insights and Ideas
- Useful keys live in the column, not the query: A literal fragment might be rare in names, ubiquitous in server logs, and absent from the surface of an alternation-heavy regex. Specializing a tiny translator to a single column captures local templates and formatting regularities that static extraction rules miss.
- General-purpose LLMs flop at this task: Can a massive LLM guess good prefix keys using world knowledge? Nope. Zero-shot giants (up to 671B parameters like DeepSeek-V3.2 and Qwen3.5) only hit valid column prefixes 26%–33% of the time (vs. 97%–99% for RIVET) while running up to 1,040× slower. Useful index keys are a property of your specific table, not natural language priors.
- Probability concentration + diversity = early stopping: You don't need every matching bucket—just enough to hit k rows. Combining greedy high-mass beams with stochastic temperature sampling dramatically outperforms either alone, pushing Recall@64 from ~0.45–0.69 (single greedy decode) to 0.986.
Key Results
Single-column LIMIT-64 latency and speedups across datasets
- Blazing Single-Column Speed: For
LIMIT 64queries, RIVET achieves 26.3–71.3 ms latency (35.8 ms median) with ~0.986 recall under its fixed key budget. It beats the fastest regex-indexing baseline (REI) by 3.4×–36.2× and sequential scans by up to 1,773×. - Interactive Previews & Plans: Under a strict 500 ms interactive budget, RIVET completes 99% of
LIMIT 64preview queries (REI manages 74%). Dropped into full multi-table TPC-H query plans, it trims end-to-end execution latency by 1.23×–1.77×. - OOD & Deployment Practicality: On the 80 wild human regexes, fixed-budget RIVET hits 0.622–0.878 recall in 48–92 ms (and adding a residual scan for 100% recall is still 3.6×–33.9× faster than scanning from scratch). Training takes ~39 minutes per column, yields a ~60 MB model, and breaks even on compute investment in under 2 days at 5,000 queries/day.
Limitations and Future Work
- Dispersed and non-prefix patterns: Because RIVET instantiates keys as prefixes, regexes constrained purely by suffixes, infixes, or matches thinly scattered across hundreds of tiny prefix buckets can exhaust its key budget, forcing a fallback to slower residual scans.
- Per-column upkeep and hardware: Every indexed column needs its own trained specialist (pooling columns degrades recall) and lightweight periodic fine-tuning if data drifts (~2 minutes per partition). Additionally, sub-75ms latencies rely on colocated GPU inference; CPU-only inference bumps median translator time to ~154 ms, and sequential scans still win on tiny tables (<5,000 rows).
- Future Directions: The authors note that on hard OOD queries, the fastest path to 100% completion varies by dataset—motivating future cost-based query planners that dynamically route between RIVET, traditional n-gram filters, or scans.
Summary updated