[Paper Review] Improved Cardinality Estimation by Learning Queries Containment Rates
This paper proposes a novel deep learning-based method, CRN, to estimate containment rates between SQL queries on a specific database, using learned vector representations of query components. By leveraging these containment rates, the approach significantly improves cardinality estimation—achieving up to 1,650× better accuracy than MSCN on 5-join queries—offering a robust, plug-in solution for enhancing existing query optimizers without model retraining.
The containment rate of query Q1 in query Q2 over database D is the percentage of Q1's result tuples over D that are also in Q2's result over D. We directly estimate containment rates between pairs of queries over a specific database. For this, we use a specialized deep learning scheme, CRN, which is tailored to representing pairs of SQL queries. Result-cardinality estimation is a core component of query optimization. We describe a novel approach for estimating queries result-cardinalities using estimated containment rates among queries. This containment rate estimation may rely on CRN or embed, unchanged, known cardinality estimation methods. Experimentally, our novel approach for estimating cardinalities, using containment rates between queries, on a challenging real-world database, realizes significant improvements to state of the art cardinality estimation methods.
Motivation & Objective
- To address the critical challenge of inaccurate cardinality estimation in query optimization, especially for complex queries with multiple joins.
- To introduce a new metric—containment rate—defined as the percentage of one query’s result tuples contained in another’s on a specific database.
- To develop a deep learning model, CRN, that learns query representations from tables, joins, and predicates to estimate containment rates accurately.
- To demonstrate that containment rate estimation can significantly enhance existing cardinality estimation methods without modifying them.
- To provide a practical, low-overhead framework for improving query optimizer performance in real-world databases like IMDb.
Proposed method
- CRN encodes each query into three sets: tables (T), joins (J), and column predicates (P), each represented by learnable vectors.
- The model generates a single query representation vector by combining the embeddings of T, J, and P using attention mechanisms.
- Containment rate between two queries is estimated by measuring the distance between their learned representation vectors using a specialized neural network layer.
- The method uses a three-step framework: (1) estimate containment rates via CRN, (2) use these rates to refine cardinality estimates, and (3) integrate with existing estimators without modification.
- The approach supports extensions to complex predicates, string equality (via hashing), EXCEPT, UNION, and OR operators through recursive decomposition and set-based reasoning.
- For dynamic databases, the method allows incremental retraining or full retraining with updated schema and data, with placeholders for future schema changes.
Experimental results
Research questions
- RQ1Can learning containment rates between queries on a specific database improve cardinality estimation accuracy?
- RQ2How does the proposed CRN model compare to state-of-the-art methods in estimating containment rates and cardinalities?
- RQ3To what extent can containment rate estimation reduce cardinality estimation errors in multi-join queries?
- RQ4Can existing cardinality estimation models be enhanced by embedding them within a containment rate-based framework?
- RQ5How can the CRN model be extended to support complex SQL constructs like string predicates, IN, BETWEEN, and set operators?
Key findings
- The proposed method improves cardinality estimation by up to 150× and 175× on 4-join queries compared to PostgreSQL and MSCN, respectively.
- On 5-join queries, the method achieves a 1,650× improvement over MSCN and a 120× improvement over PostgreSQL in cardinality estimation accuracy.
- The containment rate estimation via CRN is highly effective, even when queries are not analytically contained, due to data-specific correlations.
- The method can enhance any existing cardinality estimator by embedding it in a three-step process that uses containment rates to refine estimates.
- The CRN model generalizes well to complex queries, including those with UNION, EXCEPT, and OR conditions, through recursive decomposition and set operations.
- The approach is practical for dynamic databases, with support for incremental retraining and schema evolution via placeholder mechanisms.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.