Algorithm Search⌘K

Problemadvanced

Consistent query answering

Also called CQA, consistent answers over repairs.

Return the answers to a query that hold in every repair of an inconsistent database, without choosing one repair.

Consistent query answering asks which answers of a query are true in every repair of a database that violates its constraints. It differs from database repair: that problem builds one consistent database and runs queries on it, while consistent query answering keeps the data as it is and returns only what no choice of repair can change. The definition follows Arenas, Bertossi and Chomicki. Most of the theory is for primary keys, where a repair keeps exactly one fact of each group of facts with the same key.

In plain words

Two sources disagree about the department of Ann. One says sales and the other says HR, and the database cannot tell which is right. You can still answer questions. "Is Bob in HR?" gets yes if all sources agree on Bob. "Does Ann work somewhere?" gets yes, because she does in every reading. "Is Ann in HR?" gets no clear answer, so it is left out.

The answers you return are the safe ones: true whatever way the conflicts are settled. The hard part is that the number of ways to settle the conflicts grows very fast, so you cannot try them one by one. For some questions a clever rewrite of the question gives the safe answers directly. For others, no fast method is known.

Definition

Repairs. Let DD be a finite database and Σ\Sigma a set of constraints, for example primary keys, functional dependencies or denial constraints. Set semantics holds. A subset repair of DD is a subset D′⊆DD' \subseteq D that satisfies Σ\Sigma and is maximal under inclusion among such subsets. Denial constraints, and so primary keys and functional dependencies, are kept when facts are deleted, so at least one subset repair exists.

Consistent answers. For a query QQ, a tuple aˉ\bar a is a consistent answer if aˉ∈Q(D′)\bar a \in Q(D') for every subset repair D′D' of DD. For a Boolean query qq, the decision problem CERTAINTY(q)\text{CERTAINTY}(q) asks, given DD, whether qq is true in every repair. The query and the constraints are fixed, so the complexity is data complexity unless stated.

Primary keys. A schema with primary keys is written R(x‾;y)R(\underline{x}; y), with the key before the semicolon. A block is a maximal set of facts of one relation that agree on the key. Under primary keys, the subset repairs are exactly the sets that keep one fact from each block, so a database with blocks of sizes b1,…,bsb_1, \ldots, b_s has b1⋯bsb_1 \cdots b_s repairs. Queries are conjunctive queries in AHV notation q() :- R1(uˉ1),…,Rm(uˉm)q() \text{ :- } R_1(\bar u_1), \ldots, R_m(\bar u_m). The query is self-join-free if no relation name occurs twice.

Variants

  • Constraints. Primary keys, functional dependencies, denial constraints, or constraints with insertions such as inclusion dependencies. With inclusion dependencies a repair may also add facts, and repairs are defined by a minimal symmetric difference.
  • Repair semantics. Subset repairs, repairs with the largest number of facts, repairs by updates of values, or repairs with priorities among facts. Each gives a different set of consistent answers.
  • Queries. Self-join-free conjunctive queries, queries with self-joins, unions, aggregates, or first-order queries. For an aggregate, the usual answer is the range of values over all repairs.
  • Counting. Count the repairs in which the query is true, instead of asking if it is true in all of them.

Examples

Let Emp(name‾;dept)\text{Emp}(\underline{name}; dept) hold (ann, sales), (ann, hr) and (bob, hr). The block of ann has two facts, so there are two repairs: {(ann, sales), (bob, hr)} and {(ann, hr), (bob, hr)}.

query answers in repair 1 answers in repair 2 consistent answers
Q(x) :- Emp(x,hr)Q(x) \text{ :- } \text{Emp}(x, \text{hr}) bob ann, bob bob
Q(x) :- Emp(x,y)Q(x) \text{ :- } \text{Emp}(x, y) ann, bob ann, bob ann, bob
Q(y) :- Emp(ann,y)Q(y) \text{ :- } \text{Emp}(\text{ann}, y) sales hr none

Three Boolean queries over R(x‾;y)R(\underline{x}; y) and S(y‾;z)S(\underline{y}; z) or S(z‾;y)S(\underline{z}; y) show the three cases of the theory.

  • First-order. q0() :- R(x,y),S(y,z)q_0() \text{ :- } R(x, y), S(y, z) with SS keyed on yy. It is true in every repair if and only if ∃x [∃y R(x,y)∧∀y (R(x,y)→∃z S(y,z))]\exists x\, [\exists y\, R(x, y) \wedge \forall y\, (R(x, y) \to \exists z\, S(y, z))] holds in DD. Each repair keeps one fact of the block of such an xx, and the block of SS for its yy is not empty, so the repair keeps an SS fact that joins. If no such xx exists, a repair that picks a bad yy in every block of RR makes q0q_0 false. So CERTAINTY(q0)\text{CERTAINTY}(q_0) is a first-order query, and SQL can compute it.
  • Polynomial but not first-order. q1() :- R(x,y),S(y,x)q_1() \text{ :- } R(x, y), S(y, x) with SS keyed on yy. Wijsen proved that CERTAINTY(q1)\text{CERTAINTY}(q_1) is in polynomial time but has no first-order rewriting.
  • coNP-complete. q2() :- R(x,y),S(z,y)q_2() \text{ :- } R(x, y), S(z, y) with SS keyed on zz, so the join is on two attributes outside the keys. CERTAINTY(q2)\text{CERTAINTY}(q_2) is coNP-complete (Fuxman and Miller). The reduction is below.

Known algorithms

  • Brute force. Enumerate the repairs and evaluate the query in each one. Correct for every query, but the number of repairs can be exponential in ∣D∣|D|.
  • First-order rewriting. For the queries where it exists, compute a first-order query φ\varphi with φ(D)\varphi(D) equal to the consistent answers, and run it as SQL. Arenas, Bertossi and Chomicki gave a rewriting by residues for some classes of constraints and queries. Fuxman and Miller gave a rewriting for a class of self-join-free conjunctive queries under primary keys, which contains q0q_0.
  • The attack graph. Koutris and Wijsen define, for a self-join-free conjunctive query, a graph on its atoms. It decides which case holds and, in the polynomial cases, guides the algorithm.
  • The conflict hypergraph. Under denial constraints, the facts are the vertices and each minimal set of facts that violates a constraint is a hyperedge. The repairs are the maximal independent sets. Chomicki and Marcinkowski use it to answer queries without quantifiers in polynomial time.
  • Solvers. For the coNP-complete cases, encode "some repair makes the query false" as a SAT instance, an integer program or an answer set program, and give it to a solver.

Bounds

All bounds are theorems in data complexity unless stated.

  • Upper bound. Under denial constraints, CERTAINTY(q)\text{CERTAINTY}(q) is in coNP for every first-order qq. A certificate for "no" is a repair D′D' with qq false. Checking that D′D' is consistent takes polynomial time for fixed constraints. Checking that it is maximal needs only single facts: D′D' is maximal if and only if D′∪{f}D' \cup \{f\} violates Σ\Sigma for each f∈D∖D′f \in D \setminus D', since a consistent D′∪SD' \cup S would make D′∪{f}D' \cup \{f\} consistent for each f∈Sf \in S.
  • Hardness. CERTAINTY(q2)\text{CERTAINTY}(q_2) is coNP-complete (Fuxman and Miller).
  • Trichotomy for primary keys. For each self-join-free conjunctive query qq under primary keys, CERTAINTY(q)\text{CERTAINTY}(q) is in FO if the attack graph of qq is acyclic, coNP-complete if it has a strong cycle, and in P but not in FO otherwise (Koutris and Wijsen, TODS 2017). The case can be decided from qq.
  • Logspace. The polynomial cases of the trichotomy can be expressed in symmetric stratified Datalog and so are in logspace (Koutris and Wijsen, 2021).
  • Queries without quantifiers. Under denial constraints, the consistent answers to quantifier-free queries can be found in polynomial time (Chomicki and Marcinkowski).
  • Combined complexity. If the query is part of the input, the problem is at least as hard as evaluating a Boolean conjunctive query, which is NP-complete: with Σ\Sigma empty the database is its own only repair.

Reductions

  • From SAT to the complement of CERTAINTY(q2)\text{CERTAINTY}(q_2). Take a formula in conjunctive normal form. For each clause CC, put R(C,ℓ)R(C, \ell) for each literal ℓ\ell of CC, so the block of CC holds its literals. For each variable vv, put S(v,v)S(v, v) and S(v,¬v)S(v, \neg v), a block of two facts. A repair picks one literal per clause from RR and one literal per variable from SS, and q2q_2 is false in it if and only if no literal is picked by both. Read the SS pick vv as "vv is false" and ¬v\neg v as "vv is true". Then the SS picks are the false literals of an assignment, and q2q_2 fails if and only if each clause picks a true literal. So the formula is satisfiable if and only if some repair makes q2q_2 false. This gives the coNP-hardness.
  • To SAT. In the other direction, "some repair makes qq false" is in NP and so reduces to SAT, which is how solvers are used.
  • From certain answers. The consistent answers are the certain answers over the set of possible worlds given by the repairs. Data exchange and answering queries using views use the same idea with other sets of worlds.

Applications

  • Data integration. Sources that agree on the schema can disagree on the values for one key. Consistent answers report only what holds whatever source is right.
  • Querying dirty data without cleaning it. When no repair can be chosen with confidence, consistent answers give a safe subset of the answers. A probabilistic method such as HoloClean chooses values instead.
  • Data quality checks. The difference between the plain answers and the consistent answers shows which answers depend on the conflicts.

References

  1. Marcelo Arenas, Leopoldo Bertossi and Jan Chomicki, Consistent query answers in inconsistent databases, PODS 1999, pages 68-79, the definition of repairs and consistent answers, and the rewriting by residues
  2. Ariel Fuxman and Renée J. Miller, First-order query rewriting for inconsistent databases, Journal of Computer and System Sciences 73(4), 2007, pages 610-635, the class of queries with a first-order rewriting under primary keys, and a coNP-complete query
  3. Jef Wijsen, A remark on the complexity of consistent conjunctive query answering under primary key violations, Information Processing Letters 110(21), 2010, pages 950-955, a query in polynomial time without a first-order rewriting
  4. Paraschos Koutris and Jef Wijsen, Consistent query answering for self-join-free conjunctive queries under primary key constraints, ACM TODS 42(2), 2017, the attack graph and the dichotomy between polynomial time and coNP-completeness
  5. Paraschos Koutris and Jef Wijsen, Consistent query answering for primary keys in Datalog, Theory of Computing Systems 65(1), 2021, the polynomial cases expressed in symmetric stratified Datalog and placed in logspace
  6. Jan Chomicki and Jerzy Marcinkowski, Minimal-change integrity maintenance using tuple deletions, Information and Computation 197(1-2), 2005, pages 90-121, the conflict hypergraph and the complexity of consistent answers under denial constraints
  7. Leopoldo Bertossi, Database Repairing and Consistent Query Answering, Morgan and Claypool, 2011, the chapters on consistent query answering and its complexity

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a known algorithm
  • a contract.yaml