Abstract
Regular expression (regex) queries are essential for complex data retrieval but often suffer from poor performance in database systems, typically requiring exhaustive full table scans. This paper presents a novel framework for indexing regular expressions by transforming the selection of indexable substrings, or multigrams, into a combinatorial optimization problem. By utilizing Linear Programming (LP) with randomized rounding and enforcing a prefix-free property, the proposed Linear Programming Multigram Selection (LPMS) system achieves high precision and recall while maintaining a compact index size. Experimental results on synthetic and biological datasets demonstrate that LPMS significantly outperforms existing static multigram approaches in both filtering efficiency and scalability.
Introduction
Regular expressions have been a standard feature in SQL for decades, yet they remain a significant performance bottleneck. Most database engines lack specialized indexing for these queries, leading to inefficient full table scans for patterns that cannot be simplified to prefix matches. Existing indexing methods, such as suffix trees, often exceed the size of the database itself, leading to memory thrashing. Conversely, static n-gram approaches fail to adapt to specific data distributions or query workloads. This research introduces a "Goldilocks" index: a compact, memory-efficient structure that provides high precision to minimize the workload on the regex engine.
Methods
The core of the proposed system is the Linear Programming Multigram Selection (LPMS) framework. The process begins by identifying a set of candidate multigrams (substrings of varying lengths) from a representative query workload. The selection of the optimal subset of these multigrams is modeled as an Integer Programming (IP) problem, aimed at minimizing the total support—the number of records an index key points to—while maximizing query coverage.
To handle the NP-hard nature of the IP formulation, the authors employ LP relaxation followed by rounding techniques. Two variants were developed: LPMS-D (Deterministic rounding) and LPMS-R (Randomized rounding). A critical innovation is the enforcement of a "prefix-free" constraint, ensuring no index key is a prefix of another. This mathematical guarantee keeps the index size bounded relative to the database size, making the constraint endogenous to the optimization model.
Experimental Evaluation
The researchers evaluated LPMS using synthetic English datasets with varying support distributions and the PROSITE protein database, which contains 100,000 sequences. The PROSITE dataset served as a "stress test" due to the high complexity of protein signatures, which are represented as intricate regular expressions used for biological classification.
Results and Discussion
A key finding was the superiority of randomized rounding (LPMS-R) in balancing precision and recall. While deterministic methods (LPMS-D) achieved 100% recall in complex biological datasets, LPMS-R consistently provided better precision across varying data distributions.
As shown in the comparative analysis above, LPMS-R maintains a significantly smaller posting list size compared to baseline "BEST" algorithms (represented by B-series indices) while achieving higher precision. For instance, LPMS-R reduced the posting size to approximately 2,773 entries, whereas comparable baseline methods required nearly four times as much space for lower precision. Furthermore, the system demonstrated linear scalability with database size, making it suitable for large-scale applications.
Conclusion
The LPMS framework successfully addresses the long-standing challenge of indexing regular expression queries. By treating index selection as an optimization problem and leveraging workload-aware multigrams, the system provides a scalable and precise filtering mechanism. Future work will focus on optimizing the LP solver for even larger workloads using primal-dual approaches and adapting the index for dynamic datasets with frequent updates.
Summary updated