The Importance of Parameters in Database Queries

Amir Gilad, Martin Grohe, Benny Kimelfeld, Peter Lindner, Christoph Standke

TL;DR

This paper introduces a formal framework to quantify the "responsibility" of specific parameter values (like constants in a WHERE clause) for a database query's result. By adapting the SHAP score from machine learning, the authors provide a principled way to measure parameter importance, offering both exact polynomial-time algorithms for acyclic queries and a robust approximation scheme for more complex, correlated scenarios.

What Problem Does This Paper Address?

When we run a database query, the results are often dictated by specific choices of constants—parameters like a maximum price, a specific date, or a category. But how much does each choice actually matter? If a search for "flights under $500 on Friday" returns no results, is the price limit or the date more "to blame"?

Standard sensitivity analysis often fails here because parameters interact: changing one might have no effect unless another is also changed. This is a classic problem of contribution attribution in cooperative game theory. While the machine learning community has embraced SHAP (Shapley Additive Explanations) to explain model features, the database community lacked a rigorous equivalent for query parameters. This paper fills that gap, focusing on the computational complexity of calculating these scores across different query types and similarity measures.

Methods

The authors define the importance of a parameter as its SHAP score. To calculate this, the framework requires:

  1. A Parameterized Query ($Q$): A query where some constants are treated as variables that can change.
  2. A Probability Distribution ($\Gamma$): A model of how those parameters might realistically vary.
  3. A Utility Function ($s$): A way to measure the similarity between the original query result and the result obtained with randomized parameters (e.g., Jaccard index or intersection size).

The core of the method involves evaluating the expected change in query results as parameter sets are toggled. The authors prove a significant theoretical result: two different intuitive approaches to defining importance—measuring the effect of fixing a parameter vs. changing it—actually converge on the same SHAP score.

Figure 1. On a given database D, we evaluate a parameterized query Q with respect to a reference parameter p∗. The result is compared (using a similarity function s) against different parameterizations of Q, according to a probabilistic model Γ.

Datasets

The paper is primarily theoretical and does not utilize large-scale empirical datasets for training or benchmarking. Instead, it uses illustrative examples, such as a flight database schema (Flight, Airline) and synthetic relational structures, to demonstrate the complexity of the algorithms and the behavior of the SHAP scores.

Key Insights and Ideas

  • The "Parameter-Acyclic" Requirement: The authors show that standard query acyclicity isn't enough for tractability. They introduce p-acyclicity, which requires the query to remain acyclic even when parameters are treated as variables. If the parameter structure itself is complex (e.g., forming a clique), the problem becomes #P-hard.
  • Projection is a Bottleneck: Similar to results in query counting, the presence of existential quantifiers (projection) often pushes the complexity of exact SHAP computation from polynomial time to #P-hardness, even for simple "star-shaped" queries.
  • Why-Not Explanations: The framework elegantly extends to "why-not" questions (explaining why a specific tuple is missing from a result). By treating query filters as "players" in a game, SHAP scores can rank which part of the query is most responsible for excluding the expected data.
  • Sampling for Correlation: While exact computation is often hard, the authors demonstrate that if you can efficiently sample from the parameter distribution (even if parameters are correlated, like in a Bayesian network), you can achieve an FPRAS (Fully Polynomial Randomized Approximation Scheme) for the SHAP score.

Key Results

  • Tractability for Full pACQs: The paper provides polynomial-time algorithms for computing exact SHAP scores for "full" (no projection) acyclic conjunctive queries using natural similarity functions like Intersection and Negative Difference.
  • Hardness Proofs: They establish that computing SHAP is #P-hard for queries with projection and for queries involving certain inequality filters, even with independent parameters.
  • Approximation Guarantees: They prove that an additive approximation of the SHAP score can be computed efficiently for any tractable query class, provided the similarity function is bounded.

Limitations and Future Work

  • Aggregate Queries: The current framework focuses on set-based results (relational algebra). The authors note that extending this to aggregate queries (e.g., SUM, AVG) where similarity is measured numerically is a vital next step.
  • Continuous Parameters: While the paper touches on discretization, a native treatment for continuous probability distributions (like Gaussian models for price or time) remains an open area for refinement.
  • Real-world Applications: The authors suggest applying this framework to fact-checking, specifically to detect "cherry-picked" claims that rely too heavily on arbitrary parameter choices to remain true.

Summary updated

Abstract

We propose and study a framework for quantifying the importance of the choices of parameter values to the result of a query over a database. These parameters occur as constants in logical queries, such as conjunctive queries. In our framework, the importance of a parameter is its SHAP score - a popular instantiation of the game-theoretic Shapley value to measure the importance of feature values in machine learning models. We make the case for the rationale of using this score by explaining the intuition behind SHAP, and by showing that we arrive at this score in two different, apparently opposing, approaches to quantifying the contribution of a parameter. The application SHAP requires two components in addition to the query and the database: (a) a probability distribution over the combinations of parameter values, and (b) a utility function that measures the similarity between the result for the original parameters and the result for hypothetical parameters. The main question addressed in the paper is the complexity of calculating the SHAP score for different distributions and similarity measures. In particular, we devise polynomial-time algorithms for the case of full acyclic conjunctive queries for certain (natural) similarity functions. We extend our results to conjunctive queries with parameterized filters (e.g., inequalities between variables and parameters). We also illustrate the application of our results to "why-not" explanations (aiming to explain the absence of a query answer), where we consider the task of quantifying the contribution of query components to the elimination of a non-answer in consideration. Finally, we discuss a simple approximation technique for the case of correlated parameters.
BibTeX
@inproceedings{gilad2024importance,
  author = {Amir Gilad and Martin Grohe and Benny Kimelfeld and Peter Lindner and Christoph Standke},
  title = {{The Importance of Parameters in Database Queries}},
  booktitle = {ICDT},
  year = {2024},
  url = {https://openreview.net/forum?id=rcvQy0sbiA},
}
Figure