Conceptio › Archive › arXiv CS
arXiv CS open access

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

2026 · arxiv_cs
arXiv CS · Papers · 2026
Open Source ↗Direct PDF ↓
data-managementdatabasessqlstorage
Conceptio Open Archive

Analyze & explore related research in Conceptio

Connect this record directly into your research workflow or AI agent. Explore citations across open repositories, query full text, and export structured proof bundles.

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering Miika Hannula University of Tartu, Estonia

arXiv:2608.03477v1 [cs.DB] 4 Aug 2026

Abstract The data complexity of consistent query answering has been extensively studied over the past two decades. In this paper, we study its combined complexity, which has gained less attention. The input is a triple consisting of a set of integrity constraints, a (potentially inconsistent) database, and a query, and the question is to determine whether all repairs of the database with respect to the constraints satisfy the query. Our aim is to isolate query-specific structural features that make this problem computationally tractable. We focus on Boolean self-join-free conjunctive queries over primary-key constraints, as in this context the corresponding data complexity problem has been completely classified. Moreover, we restrict attention to queries with an acyclic attack graph, which are precisely those queries that admit a first-order rewriting. As an additional simplifying assumption, we focus on unary primary keys. Each conjunctive query with unary primary keys naturally gives rise to a directed graph, which we call the key-nonkey graph, where each atom contributes an edge from its key variable to each of its non-key variables. Our main result is that, under the stated assumptions, the combined complexity of consistent query answering is in polynomial time whenever the number of source strongly connected components (SCCs) in the key-nonkey graph is bounded by a constant. To prove this result, we develop novel concepts, such as variable guarding and attack-propagation graphs, and techniques, such as database and query saturation and query normalization. In addition, without the boundedness restriction, the combined complexity of this problem is shown to be ΠP2 -complete.

Contents 1 Introduction

2

2 Preliminaries 2.1 Databases and Repairs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Attack Graphs, Gaifman Graphs, and Key-Nonkey Graphs . . . . . . . . . . .

5 5 6

3 Main Theorem 3.1 Roadmap to the Proof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2 Connection to CQ Evaluation under Primary Keys . . . . . . . . . . . . . . .

8 8 9

4 Saturated Databases

10

5 Saturated and Normal Queries 5.1 Query Saturation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Basic Properties of Saturated Queries . . . . . . . . . . . . . . . . . . . . . . 5.3 Query Normality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Attack-Propagation Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12 12 14 15 17

6 Query Pruning via Guarded Reductions

17

2

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

7 Variable Substitution via Substitution-Guarded Reductions

19

8 Proof of Main Theorem

20

9 Conclusion

22

A Auxiliary Concepts and Lemmas

24

B Lemmas for Section 4

24

C Lemmas for Section 5.1 C.1 Controlled and Size-Monotone Reductions . . . . . . . . . . . . . . . . . . . . C.2 Saturation Lemma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C.3 Saturation Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

25 25 26 28

D Lemmas for Section 5.3 D.1 First Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.2 Second Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.3 Third Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.4 Fourth Condition and Substitutable Sets . . . . . . . . . . . . . . . . . . . . . D.5 Normalization Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.6 Basic Properties of Saturated and Normal Queries . . . . . . . . . . . . . . .

29 30 31 32 37 41 42

E Definitions and Lemmas for Section 6 E.1 Properties of Guards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E.2 Guarded Reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E.3 Leaf Pruning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E.4 Leaf Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E.5 Consistent Edge Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . E.6 Inconsistent Edge Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . E.7 Pruning Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

47 48 49 50 54 58 67 77

F Definitions and Lemmas for Section 7 80 F.1 Substitution Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 G Proof of Main Lemma

83

H Hardness without Source SCC Bound

88

1

Introduction

Consistent query answering (CQA), introduced in [3], provides a principled semantics for queries over inconsistent databases. This semantics is often presented via the notions of repairs and consistent answers. A repair of a database db is any consistent database r that is as close to db as possible. Under the usual formal definition, r is a repair whenever r is a consistent database with a ⊆-minimal symmetric difference r ⊕ db. In the context of primary-key constraints, or functional dependencies more generally, such a repair r is always a subset of db. Given a query q(⃗x), an answer ⃗a is called a consistent answer if it belongs to the output q(r) of the query q on each repair r of db. In particular, when q is Boolean, the consistent answer is “yes” if the query answer is “yes” on every repair.

M. Hannula

3

Since the number of repairs can be exponential in the size of the database, CQA is generally computationally intractable, even for conjunctive queries (CQs). In contrast to ordinary CQ evaluation, this intractability arises already in the data complexity setting, where the query and the constraint set are fixed and only the database is part of the input. Indeed, there exist Boolean conjunctive queries consisting of only two atoms (over distinct relation symbols) whose CQA problem is coNP-hard. At this point, several complexity classifications exist for data complexity, typically along structural properties that depend on the query and the constraint set. Most pertinent for our study is the trichotomy result by Wijsen and Koutris [19, 20], which partitions all self-join-free Boolean conjunctive queries (sjfBCQs) into three classes: those whose CQA problem is in FO, L-complete, or coNP-complete. This classification is based on the notion of an attack graph, to which we return below in the technical treatment. Other similar data complexity classifications, fully or partially complete, concern path queries [17], rooted tree queries [18], aggregate queries [13, 14, 15], two-atom queries with self-joins [23], queries under primary and foreign keys [12], queries under semiring semantics [16], and counting complexity [5, 22]. Taken together, these works paint a remarkably comprehensive picture of the data complexity of CQA. In this paper we shift attention from data complexity to combined complexity. In the CQA context, this point of view was given attention already in earlier papers such as [2, 6]. Later, Arming et al. [4] classified the CQA problem in various input configurations, including combined complexity (where all the three input components are allowed to vary). As summarized therein, the combined complexity of CQA is ΠP2 -complete over Boolean CQs and key constraints, and remains ΠP2 -complete even when more general EGDs are considered instead of keys. In addition, the same problem is NP-complete over inclusion dependencies and undecidable over TGDs. Recently, [11] investigated parameterized complexity of CQA for data and combined complexity. These works notwithstanding—and there may be others that we fail to list here—it is safe to say that combined complexity for CQA has not yet received a similarly extensive structural analysis as data complexity. In particular, while we know that the combined complexity of CQA is in general intractable, it is not well understood what explains this intractability, and when it can be avoided. Attack graphs provide such explanations for data complexity, but no analogous theory exists for combined complexity. The following example illustrates the gap. ▶ Example 1. Consider Boolean CQs qk := ∃x1 . . . ∃xk+1 (R1 (x1 , x2 ) ∧ R2 (x2 , x3 ) ∧ · · · ∧ Rk (xk , xk+1 )),

(1)

where the (underlined) first position in each atom is the primary-key position. From the theory of attack graphs, we obtain a first-order rewriting to capture the CQA semantics of the queries qk : ∃x1 x2 (R1 (x1 , x2 )∧∀x2 (R1 (x1 , x2 ) → ∃x3 (R2 (x2 , x3 )∧ ∀x3 (R2 (x2 , x3 ) → ∃x4 (R3 (x3 , x4 ) ∧ · · · ∧ ∀xk (Rk−1 (xk−1 , xk ) → ∃xk+1 Rk (xk , xk+1 )) . . . ))))). These alternating formulas can be evaluated naïvely in O(nk ), where n is the size of the database. This, however, is needlessly expensive. Given a database db, an alternative process repeats the following steps, for each i = k − 1, . . . , 1: Remove from db every Ri -block (i.e., a maximal set of Ri -facts with the same primary-key value) containing a fact Ri (a, b) such that no fact of the form Ri+1 (b, c) exists in db.

4

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Remove each fact Ri+1 (b, c) from db. In the end, return true if db is non-empty, and otherwise return false. The procedure returns true precisely when each repair of db satisfies q. Since, assuming constant-time access to blocks by relation name and primary-key value, every block is examined at most once, the procedure runs in O(n). The above example provides a simple combined complexity fragment that is tractable. In this paper, our aim is to understand when and how such fragments arise. To illustrate our contribution, the queries qk above give rise to what we call a key-nonkey graph, consisting of directed edges from xi to xi+1 . The elimination procedure exemplifies one part of what we call database saturation. Moreover, each xi forms a singleton SCC, with x1 being their only source. The number of source SCCs is therefore bounded by 1, and hence, as per our main result, the combined complexity of CQA over {qk | k ≥ 1} is in polynomial time. Note that in this example the key-nonkey graph is a tree. The general case is considerably more involved, as one must also handle multiple incoming edges and cycles. Contributions. A source SCC is an SCC with no incoming edge from another SCC. We prove that the combined complexity of CQA over Boolean self-join-free conjunctive queries with unary primary keys and acyclic attack graphs is in polynomial time whenever the number of source SCCs in the key-nonkey graph is bounded. In order to construct a proof, we develop a number of concepts and techniques: attack-propagation graphs, variable guarding and guarded reductions, database saturation, query saturation, and query normalization. Additionally, we show that the problem becomes ΠP2 -complete as soon as the restriction of having a bound on the number of source SCCs is dropped. The assumptions for our result are motivated as follows. Self-join-free Boolean conjunctive queries form a extensive class for which the data complexity of CQA has been completely classified. In particular, this classification relies on the notion of the attack graph, which also plays a central role in the present work. Restricting to acyclic attack graphs isolates exactly the class of queries for which CQA admits first-order rewritings. Extending our techniques to the remaining queries, whose data complexity is L-complete, is left for future work. We assume unary primary keys in order to simplify the technical development. We expect that many of our techniques can be generalized to composite primary keys. Related work. Perhaps closest in spirit to our approach is [7], which identifies a class of sjfBCQs for which CQA can be solved via FO-rewriting in linear time. The class they introduce (queries admitting a pair-pruning join tree) is orthogonal to ours: it allows composite primary keys but requires the query to be (α-)acyclic. Consequently, this class is a strict subclass of the sjfBCQs with an acyclic attack graph. For example, the query q = ∃xyz(R(x, y) ∧ S(y, z) ∧ T (z, x) ∧ T ′ (z, x) ∧ U (y, x) ∧ U ′ (y, x))

(2)

has unary primary keys, an acyclic attack graph, but is not acyclic. This illustrates also that tractability in our framework does not rely on hypergraph acyclicity. Another work that studies the algorithmic aspects of CQA is [8], which presents a remarkably simple generic algorithm for all sjfBCQs (and path queries) whose CQA problem has polynomial-time data complexity. The algorithm runs in O(nk ), where n is the database size and k is the number of atoms in the query.

M. Hannula

There is also a long line of work on the combined complexity of ordinary CQ evaluation. In particular, tractability has been analyzed and characterized via structural measures such as treewidth, hypertree width, generalized hypertree width, and submodular width [10, 9, 21]. These works study CQ evaluation often without integrity constraints; when constraints are present, the input database is assumed to satisfy them, and hence no repair semantics arises. At first sight, this setting therefore appears orthogonal to ours. Interestingly, however, ordinary Boolean CQ evaluation under primary-key constraints can be viewed as a special case of CQA over sjfBCQs with acyclic attack graphs; we return to this observation in Section 3.

2

Preliminaries

We use the convention of dropping the set parentheses for singleton sets in notation. That is, if our term involves a set argument U , we write u instead of {u} when U = {u}. For two natural numbers k ≤ n, we define [k, n] := {k, k + 1, . . . , n} and [n] := [1, n]. We assume disjoint countably infinite sets of variables Var, constants Const, and relation names Rel. A term is a variable or a constant. We assume a fixed total order ≺ over Var ∪ Const ∪ Rel, and extend it lexicographically to all composite expressions defined below. Each relation name R is associated with primary-key arity k and relation arity n, denoted ar(R) = (k, n), where k ≤ n. An R-atom (or simply an atom) is an expression of the form F := R(t1 , . . . , tk , tk+1 , . . . , tn ), where t1 , . . . , tn are terms and ar(R) = (k, n). If t1 , . . . , tn are constants, then this expression is an R-fact (or a fact). We assume an order ≺ on relation names, variables, and constants, and extend it lexicographically to atoms and facts. Two ⃗ are called key-equal if ⃗a = ⃗b. Throughout the proofs, we tacitly facts R(⃗a, ⃗c) and R(⃗b, d) identify atoms that differ only by a permutation of their non-key terms whenever their order is irrelevant. Accordingly, we may denote atoms by writing R(t, ⃗u, −) where ⃗u is a distinguished sequence of non-key terms, and “−” stands for the non-distinguished non-key terms. A Boolean conjunctive query (with primary-key constraints) is q is defined as a finite set of atoms {F1 , . . . , Fn }. The query is self-join-free if Fi and Fj are associated with different relation names whenever i = ̸ j. We write Rel(q) for the set of relation names appearing in q. The classes of Boolean conjunctive queries and self-join-free Boolean conjunctive queries are denoted BCQ and sjfBCQ, respectively. In this paper, we focus on queries of sjfBCQ with unary primary keys. We let BCQU and sjfBCQU denote the classes of queries in BCQ and sjfBCQ, respectively, such that ar(R) = (1, n) for each relation name R appearing in q. Additionally, we also assume that each query q ∈ sjfBCQU is variable-repetition-free, i.e., it contains only atoms R(t1 , t2 , . . . , tn ) such that the sequence t1 , . . . , tn does not repeat any variables. This assumption is without loss of generality; a formal justification will be given later. For a query q from BCQ, we write Vars(q) for the set of variables appearing in it. For a set V ⊆ Vars(q) and a function f : Y → Const ∪ Var, the query qf is obtained from q by replacing each variable x ∈ V with f (x). For an atom F , we define Ff analogously.

2.1

Databases and Repairs

Let V be a set of variables. A valuation (over V ) is a function θ from V to the constants. A valuation is extended to be the identity over constants, and it extends to atoms and queries q from BCQ naturally. If q ∈ sjfBCQ and R ∈ Rel(q), by slight abuse of notation we sometimes

5

6

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

write R for the unique R-atom in q. A database db is a finite set of facts, and the set of all databases is denoted by DB. The active domain of db, denoted by adom(db), is the set of all constants appearing in db. Given a query q from BCQ, we say that db satisfies q if there exists a valuation over Vars(q) such that θ(q) ⊆ db. A block of db is any ⊆-maximal set of key-equal facts from db. Let R(x, ⃗y ) ∈ q. We write block(R, a, db) for the set of facts in db of the form R(a, −). The expression R(a, ⃗b, −) ∈ db means that there exists a tuple of constants ⃗c such that R(a, ⃗b, ⃗c) ∈ db. A database db is consistent if for all R(⃗a, ⃗b), R(⃗a, ⃗c) ∈ db it holds that ⃗b = ⃗c. A repair of db is any ⊆-maximal consistent subset of db. Let R be a set of relation names. We write db↾R for the restriction of db to R. If q is a query from BCQ, then we may write db↾q instead of db↾Rel(q) . If R is a relation name, we may write Rdb (or, by slight abuse of notation, simply R when db is understood) instead of db↾{R} to the denote the set of all R-facts in db.

2.2

Attack Graphs, Gaifman Graphs, and Key-Nonkey Graphs

Next, we define the basic graph notions used in the paper. The definition of attack graphs is slightly modified for queries in sjfBCQU , although it is equivalent to the standard one. Let G = (V, E) be a directed graph. Let U ⊆ V be a vertex set. The set of vertices reachable from U in G is denoted by ReachG (U ). We also write OutG (U ) for the set of vertices having an incoming edge from a vertex in U . Let P = x1 , . . . , xn be a path in G. For two vertices xi and xj with 1 ≤ i < j ≤ n, we write P [xi , xj ] for its subpath that originates in xi and ends in xj . We say that P is separated by U if xi ∈ U , for some i ∈ [n]. Two sets U0 , U1 ⊆ V are separated by U if every non-empty path with one endpoint in U0 and another in U1 is separated by U . In particular, if U0 and U1 are not separated by U , then (U0 ∩ U1 ) ∩ U = ∅. For a path U = x1 , . . . , xn and A strongly connected component (SCC) of G is a maximal strongly connected subgraph of G. An SCC C ⊆ V is a source SCC if there is no edge (u, v) ∈ E with u ∈ / C and v ∈ C. We write #srcSCC(G) for the number of source SCCs of G. Let q be a query from BCQ. The Gaifman graph of q, denoted Gaifman(q), is an undirected simple graph whose vertex set is Vars(q). There is an edge between x and y if x = ̸ y and some atom of q contains both x and y. Next, we define attack graphs for queries in sjfBCQU . Our definition is slightly different from, but equivalent to, the standard one. Fix a special symbol ⊥ that does not belong to Var. Given F = R(t1 , t2 , . . . , tn ), we write ( Key(F ) :=

t1

if t1 ∈ Var,

⊥

if t1 ∈ Const.

In particular, Key(F ) is either a variable or the ⊥. Define also NonKeyVars(F ) := {ti | i ∈ [k + 1, n], ti ∈ Var} and Vars(F ) := (Key(F ) ∪ NonKeyVars(F )) \ {⊥}. Let q ∈ BCQU . Then, we define K(q) := {Key(F ) → y | F ∈ q, y ∈ NonKeyVars(F )}.

(3)

M. Hannula

7

When we write x → y, then x is understood to be a variable or ⊥, and y is understood to be a variable. Then, if F is a single atom and x → y ∈ K(F ), we say that x → y is generated by F. Now, we can view K(q) as a directed graph, called the key-nonkey graph. ▶ Definition 2 (Key-Nonkey Graph). Let q be a query from BCQU . The key-nonkey graph of q is a directed graph defined as follows: The vertex set is Vars(q) ∪ {⊥}. There is an edge from x to y if x → y ∈ K(q). We write K(q) for both the non-key-graph of q and its edge set; the intended meaning will be clear from the context. Note that for an edge x → y it holds that y ∈ Vars(q) and x ∈ Vars(q) ∪ {⊥}. Thus, ⊥ is a source vertex for each query q. If q is variable-repetition-free, then K(q) lacks self-loops. Let us then write K∗ (q) := {x → y | x ∈ Vars(q) ∪ {⊥}, y ∈ ReachK(q) (x) ∪ ReachK(q) (⊥)}. Note that K∗ (F ) consists of the (not necessarily distinct) edges x → y and ⊥ → y, for x = Key(F ) and y ∈ NonKeyVars(F ). Define also, for each F ∈ q, F +,q := {y ∈ Vars(q) | Key(F ) → y ∈ K∗ (q \ {F })}.

(4)

Let q be a query from sjfBCQU . An atom F of q is said to attack a variable x (in q), denoted q F ⇝ x, if NonKeyVars(F ) and {x} are not separated by F +,q in Gaifman(q). A variable x is said to be unattacked (in q) if no atom attacks x. The attack graph of q is a directed simple graph whose vertices are the atoms of q. Given two q distinct atoms F, G ∈ q, there is a directed edge from F to G, denoted F ⇝ G, if F attacks q+ some variable of Vars(G). We write F ⇝ G if there is a non-empty sequence of attacks q

q+

+

leading from F to G. When q is understood, we may abbreviate ⇝ and ⇝ by ⇝ and ⇝, respectively. Fix a query q from sjfBCQ. We define CERTAINTY(q) as the following problem, given a database db, determine whether every repair of db satisfies q. The following dichotomy result is due to Koutris and Wijsen [19, 20]. Note that in this paper we defined attack graphs only in the presence of unary primary keys and omitted the definition of a strong cycle. ▶ Theorem 3 ([19, 20]). Let q be a query from sjfBCQ. If the attack graph of q is acyclic, then CERTAINTY(q) is in FO. If the attack graph of q contains a cycle but no strong cycle, then CERTAINTY(q) is L-complete. If the attack graph of q contains a strong cycle, then CERTAINTY(q) is coNP-complete. From now on we will focus on queries with acyclic attack graphs. By the above theorem, these queries are precisely those that admit a first-order rewriting. We write sjfBCQA for

8

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

the subclass of sjfBCQ consisting of queries whose attack graph is acyclic. Furthermore, let sjfBCQU,A := sjfBCQU ∩ sjfBCQA . That is, sjfBCQU,A consists of Boolean self-join free conjunctive queries with unary primary keys and acyclic attack graphs.

3

Main Theorem

We now move from data complexity to combined complexity. Fix a subclass Q of sjfBCQ. We define CERTAINTY(Q) as the following problem: given a database db and a query from Q, determine whether every repair of db satisfies q. The main result of this paper states that the combined complexity of consistent query answering over queries in sjfBCQU,A is in polynomial time whenever we assume a fixed bound for the number of source SCCs in the underlying key-nonkey graph. ▶ Theorem 4. Let c ∈ N. Let Q be a class of queries q ∈ sjfBCQU,A such that #srcSCC(K(q)) ≤ c. Then CERTAINTY(Q) is in polynomial time. A crucial construct in the proof is a partitioning of the edges of K(q) into the set of consistent edges Kc (q) and the set of inconsistent edges Ki (q). Additionally, we enrich Kc (q) with dummy edges. Let q ∈ BCQU , and let x, y be two variables. Then Kc (q) consists of the edges x → y where x = y or there exists F ∈ q and G ∈ q \ {F } such that x → y ∈ K(F ) and x → y ∈ K∗ (G); Ki (q) consists of the edges x → y that belong to K(q) \ Kc (q). In particular, every edge from K(q) belongs either to Ki (q) or Kc (q), but not both. If q is variable-repetition-free, then K(q) and Ki (q) do not contain any dummy edges x → x. Likewise, q is partitioned into two subqueries: q i and q c : F ∈ q c if for all x → y ∈ K(F ) it holds that x → y ∈ Kc (q). F ∈ q i if there exists x → y ∈ K(F ) such that x → y ∈ Ki (q). Next, we briefly sketch our proof strategy for Theorem 4.

3.1

Roadmap to the Proof

The key concepts introduced for the proof are the following: Database saturation employs a collection of local relevancy checks to remove irrelevant blocks from the database. Query saturation extends the query with a maximal amount of doubles S(x, y), S ′ (x, y) between two distinct variables x and y. Additionally, the database is extended with consistent relations for the associated fresh relation names S, S ′ . Query normalization prepares the query for the subsequent reduction steps. The main purpose is to separate consistent and inconsistent edges so that one atom can only generate edges of one type. Attack-propagation graph is a subgraph that selects those edges of K(q) that convey an attack. It is a directed acyclic graph that gives an order for the reduction steps.

M. Hannula

Variable guarding means that a variable y is associated with two atoms of the form S(x, y, −), S ′ (x, y, −), where x is a variable that is both a member of an source SCC of the key-nonkey graph and a root of the attack-propagation graph. We then say y is guarded by x. Query pruning transforms the subtree of the attack-propagation graph that is rooted at ⊥ into one of depth 1 via variable-level reduction steps. At the same time, it removes all unguarded variables from the subtree. The polynomial-time algorithm consists of several components. First, a preprocessing step is applied, consisting of the query saturation and the subsequent query normalization. Then, the following alternating process is applied, with database saturation employed frequently inbetween steps. 1. Unless ⊥ is already the root of a non-trivial subtree of the attack-propagation graph, existentially replace a suitable non-attacked primary-key variable with a constant c to obtain such a subtree. 2. Apply query pruning to flatten the subtree rooted at ⊥ 3. Universally replace the guarded non-primary-key variables in atoms with c in the primarykey position. During this process either database saturation removes one relation entirely, in which case false is returned, or the process reaches the end replacing all variables with constants, in which case true is returned. Moreover, guarding ensures that the size of the intermediate instances as well as the number of computation branches are polynomially bounded, with each branch running in polynomial time. This concludes the roadmap to the proof. Before proceeding to the proof, let us return to the remark made in the end of the introduction, namely, that CQ evaluation under primary-key constraints can be viewed as CQA over selfjoin-free CQs with acyclic attack graphs.

3.2

Connection to CQ Evaluation under Primary Keys

By Boolean CQ evaluation under primary-key constraints, denoted BCQ-PK-EVAL, we refer to the following problem: given a query q from BCQ and a database db that satisfies the primary-key constraints of q, determine whether db satisfies q. If C ⊆ BCQ, then BCQ-PK-EVAL(Q) denotes BCQ-PK-EVAL restricted to Q. ▶ Proposition 5. BCQ-PK-EVAL is logspace-reducible to CERTAINTY(sjfBCQA ). Moreover, for every c ∈ N, if C ⊆ BCQU and #srcSCC(K(q)) ≤ c for each q ∈ C, then BCQ-PK-EVAL(C) is logspace-reducible to CERTAINTY(C ′ ), where C ′ ⊆ sjfBCQU,A and #srcSCC(K(q)) ≤ c for every q ∈ C ′ . Proof. For a BCQ with primary-key constraints q = {R1 (⃗t1 , ⃗s1 ), . . . , Rk (⃗tk , ⃗sk )}, construct a self-join-free query q ′ := {R1a,1 (⃗t1 , ⃗s1 ), R1b,1 (⃗t1 , ⃗s1 ), . . . , Rka,1 (⃗tk , ⃗sk ), Rkb,1 (⃗tk , ⃗sk )}. In particular, each relation name in q ′ is fresh and not repeated. We obtain that q ′ is associated with the empty attack graph since each atom is copied by another atom having the

9

10

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

same argument. (We did not define attack graphs generally for queries in sjfBCQ; for this, the reader can refer e.g. to [19].) Given a consistent database db over the schema of q, let db′ be a database obtained by letting (Ric,i )db be a copy of Ridb , for c ∈ {a, b} and i ∈ [k]. We obtain that db satisfies q if and only db′ satisfies q ′ , where db′ is the unique repair of itself. The reduction from (db, q) to (db′ , q ′ ) is computable in logarithmic space. Moreover, q ′ has only unary primary keys if q has. In addition, it holds that #srcSCC(K(q ′ )) = #srcSCC(K(q)). This proves the second claim. ◀ As an immediate corollary of Theorem 4 and Proposition 5, we obtain the following result. ▶ Corollary 6. Let c ∈ N, and let Q ⊆ BCQU be such that #srcSCC(K(q)) ≤ c for each q ∈ Q. Then BCQ-PK-EVAL(Q) is solvable in polynomial time. The corollary can also be proved directly by a straightforward argument. It also follows from a tractability result for CQs with unary functional dependencies. Indeed, #srcSCC(K(q)) ≤ c entails that the so-called closure treewidth of q (i.e., a width measure tailored to CQs under unary functional dependencies) is at most c, and bounded closure treewidth guarantees polynomial-time model checking by [1, Corollary 5.8]. In our case, the trivial one-bag tree decomposition yields closure treewidth at most c since every variable is functionally determined by a set of at most c variables, namely one representative from each source SCC of K(q). (Before applying this argument, we apply Proposition 5 to enforce self-join-freeness and then normalize away atoms whose primary-key position contains a constant; hence, the key-nonkey graph considered here has only query variables as vertices.) It is conceivable that the assumptions in Theorem 4 can be relaxed by combining the techniques in this paper with dynamic programming over suitable width measures. This question is left for future work. We now proceed to the proof of our main result. The following sections contain a more detailed exposition of the proof, with proof details located in the appendix.

4

Saturated Databases

We begin with database saturation. Assuming an underlying query q ∈ sjfBCQ, consider the following local consistency criteria for a database db. Non-triviality. A database db is non-trivial (over q) if for every atom F ∈ q and every fact A ∈ db↾Rel(F ) , there exists a valuation θ such that θ(F ) = A. Functional consistency. A database db is functionally consistent (over q) if for all R(x, y, −) ∈ q such that x → y ∈ Kc (q) and all a, b, c ∈ adom(db), if R(a, b, −), R(a, c, −) ∈ db, then b = c. Pairwise consistency. A database db is pairwise consistent (over q) if for any (not necessarily distinct) atoms R, S ∈ q and any R-atom A, there is a valuation θ over Vars(R) ∪ Vars(S) such that θ(R) = A ∈ db and θ(S) ∈ db. Collision consistency. A database db is collision consistent (over q) if for any R(x1 , x2 , . . . , xℓ ), xi → z, xj → z ∈ Kc (q), and T (xj , z, −), where i, j ∈ [ℓ], if xi = z and R(a1 , a2 , . . . , aℓ ) ∈ db, then T (aj , ai , −) ∈ db; if S(xi , z, −) ∈ q and R(a1 , a2 , . . . , aℓ ), S(ai , b, −) ∈ db, then T (aj , b, −) ∈ db.

M. Hannula

11

Guardedness. A database db is guarded (over q) if for any R(x1 , x2 , . . . , xℓ ) ∈ q and S1 (z, xi1 , −), . . . , Sn (z, xin , −) ∈ q such that z → xi1 , . . . , z → xin ∈ Kc (q), where ij ∈ [ℓ] for j ∈ [n], if R(a1 , a2 , . . . , aℓ ) ∈ db, then there is b ∈ adom(db) such that S1 (b, ai1 , −), . . . , Sn (b, ain , −) ∈ db. A database db that is non-trivial, functionally consistent, pairwise consistent, collision consistent, and guarded over q is called q-saturated (or simply saturated when q is understood). ▶ Example 7. Consider the following query from sjfBCQU : q := {R(c, x, y), S(z, x), S ′ (z, x), T (z, y), T ′ (z, y), U (x, v), U ′ (x, v), V (y, v), V ′ (y, v)}. Then, K(q) = {⊥ → x, ⊥ → y, z → x, z → y, x → v, y → v} and Kc (q) = {z → x, z → y, x → v, y → v}. Consider then a database db given as follows: R

c a c

x y 1 20 2 20

S

z x d 1 d 2 e 2

S′

z x d 1 e 2

T

z y d 10 e 20

U

x 1 2

v 100 200

U′

x 1 2

V

y 10 20

V′

y v 10 100 20 200

v 100 200

v 100 200

T′

z y d 10 e 20

The database violates q-saturation in several ways. R(a, 1, 20) witnesses that db is non-trivial, since there is no valuation θ mapping R to this fact. S(d, 1), S(d, 2) witness that db is not functionally consistent. T (d, 10) witnesses that db is not pairwise consistent, since is no valuation θ maps T to this fact while simultaneously mapping R to some fact in db. R(a, 1, 20), U (1, 100) witness that db is not collision consistent, since V (20, 100) does not belong to db. R(a, 1, 20) witnesses that db is not guarded, since there exists no constant b such that S(b, 1) and T (b, 20) are in db. Consider the database db′ obtained from db by recursively removing every block that witnesses a violation of q-saturation. This process simply drops the top block from each relation in db. One can verify that (db, q) ∈ CERTAINTY if and only if (db′ , q) ∈ CERTAINTY. Note that the same process over db∗ := db \ {V (10, 100)} would remove the V -relation entirely (in fact, it would remove the entire database), in which case we could derive that (db∗ , q) ∈ / CERTAINTY. The previous example can be expanded to a general algorithm, called DBSaturate (see Algorithm 1 in the appendix), that turns a database into a saturated one via repetitive removal of blocks. To understand how this can help in finding the consistent answer, consider the following example with expands (1) with the kind of cyclicity exhibited in (2).

12

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

▶ Example 8. Consider queries qk′ := qk ∪ {Si (xi , x1 ), Si′ (xi , x1 ) | i ∈ [2, k + 1]}, where qk is the query defined in (1). It can be verified that the attack graph of qk′ is acyclic. Suppose db is a qk′ -saturated database. Then, using functional consistency and collision consistency, we obtain that every repair of db satisfies qk′ if and only if every repair of db ′ satisfies qk′ \ {Sk+1 (xk+1 , x1 ), Sk+1 (xk+1 , x1 )}. By induction, it follows that every repair of ′ db satisfies qk if and only if every repair of db satisfies qk . Hence, for saturated databases, the queries qk′ are equally hard to the queries qk , which were dealt in Example 1. We say that a many-one reduction f : DB × sjfBCQU → DB ∪ {true, false} is equivalencepreserving if for every (db, q), (db, q) ∈ CERTAINTY whenever f (db, q) = true, (db, q) ∈ / CERTAINTY whenever f (db, q) = false, and otherwise (db, q) ∈ CERTAINTY if and only if (f (db, q), q) ∈ CERTAINTY. The proof of the following lemma is deferred to Section B. ▶ Lemma 9 (Database Saturation Lemma). DBSaturate : DB×sjfBCQU → DB∪{true, false} is an equivalence-preserving polynomial-time reduction such that for every pair (db, q), assuming db′ = DBSaturate(db, q) ∈ / {true, false}, we have that 1. db′ is q-saturated, 2. db′ ⊆ db.

5

Saturated and Normal Queries

Next, we consider the query preprocessing stage that consists of query saturation and normalization. First, an arbitrary query in sjfBCQU is transformed into a saturated query, and subsequently this query is made both saturated and normal.

5.1

Query Saturation

Informally, a query is saturated if it maximizes the number of consistent edges between two variables. ▶ Definition 10 (Saturatedness). Let q ∈ sjfBCQU . We say that q is saturated if for every atom F ∈ q, if 1. x → y ∈ K(F ), 2. y → z ∈ Kc (q), and 3. x → z ∈ K∗ (q \ {F }), then x → z ∈ Kc (q). We illustrate the concept of query saturation via the following example. After the initial database saturation step, we have a problem instance (db, q) where q is a query from sjfBCQU and db is a q-saturated database. ▶ Example 11. Consider a query q := {R(x, y), S(y, z), S ′ (y, z), U (x, v), V (v, z)}. It holds that K(q) = {x → y, y → z, x → v, v → z} and Kc (q) = {y → z}. We also observe that q is not saturated, since x → y ∈ K(R), y → z ∈ Kc (q), x → z ∈ K∗ (q \ {R}), while x→z∈ / Kc (q).

M. Hannula

13

Consider a database db given as follows: R

x a a b b

y 0 1 1 2

S

y 0 1 2

z d e e

S′

y 0 1 2

z d e e

U

x v a f a g b g b h

V

v f g h

z d e e

We note that db is q-saturated. Specifically, the relations S and S ′ are consistent, following the fact that y → z ∈ Kc (q). Now, (db, q) ∈ CERTAINTY if and only if (db′ , q) ∈ CERTAINTY, where db′ := db \ {R(a, 0), R(a, 1)}. To see why, consider a repair r of db′ falsifying q. Then, r picks either U (a, f ) or U (a, g). If r picks U (a, f ), let r′ be obtained from r by adding R(a, 1). Then, r′ contains R(a, 1), S(1, e), U (a, f ), V (f , d). In particular, the conflicting values for z entail that no satisfying assignment can map R(x, y) to R(a, 1). The case where r picks U (a, g) is treated symmetrically. Therefore, the repair r′ of db obtained this way falsifies q. We conclude that the block {R(a, 0), R(a, 1)} can be safely removed from db, resulting in db′ . A consequent application of database saturation yields db0 := DBSaturate(db′ , q), depicted below: R

x y b 1 b 2

S

y 1 2

z e e

S′

y 1 2

z e e

U

x v b g b h

V

v z g e h e

By Lemma 9, we have that (db′ , q) ∈ CERTAINTY if and only if (db0 , q) ∈ CERTAINTY. Now, we observe that any selection from the R-block is associated with a unique value of variable z. Hence, letting q ∗ := q ∪ {T (x, z), T ′ (x, z)}, db∗ := db0 ∪ {T (b, e), T ′ (b, e)}, we obtain that (db0 , q) ∈ CERTAINTY if and only if (db∗ , q ∗ ) ∈ CERTAINTY, where q ∗ is a saturated query and db∗ is a q ∗ -saturated database. This concludes the example. The next lemma extends the example to a general procedure. In particular, the lemma shows how to transform a problem instance into one where both the database and the query are saturated. An important feature of this procedure is that the size of the problem instance grows only polynomially, as the number of consistent relations added is at most quadratic. Consider a many-one reduction f : DB × sjfBCQU,A → DB × sjfBCQU,A ∪ {true, false}. We say that f is SCC-monotone if for every (db, q) such that f (db, q) ∈ / {true, false}, letting (db′ , q ′ ) = f (db, q), we have #srcSCC(K(q ′ )) ≤ #srcSCC(K(q)); and equivalence-preserving if for every (db, q), (db, q) ∈ CERTAINTY whenever f (db, q) = true, (db, q) ∈ / CERTAINTY whenever f (db, q) = false, and otherwise (db, q) ∈ CERTAINTY if and only if f (db, q) ∈ CERTAINTY. Let us also define a auxiliary technical condition: a query q ∈ sjfBCQU,A is binary-saturated if x → y ∈ Kc (q) implies that q contains two atoms F, G, where ar(F ) = ar(G) = (1, 2), such that x → y ∈ K(F ) ∩ K(G). The proof of the following lemma is given in Section C.

14

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

v

v

z

z′

y

y′

saturation

z

z′

y

y′

x

“pruning”

x

z

z′

y

y′

x

Figure 1 The key-nonkey-graphs K(q) before and after query saturation and “query pruning”. Double arrows represent consistent edges and single arrows inconsistent edges.

▶ Lemma 12 (Query Saturation Lemma). Let C be the set of pairs (db, q), where q is a query from sjfBCQU,A and db is a q-saturated database. Then Saturate is an equivalencepreserving, SCC-monotone, polynomial-time reduction from C to C∪{true, false}. Additionally, for each (db, q), assuming (db′ , q ′ ) = Saturate(db, q) ∈ / {true, false}, we have that q ′ is saturated and binary-saturated. We illustrate the process of query saturation via an example, illustrated in Figure 1. ▶ Example 13. Consider an arbitrary database db and a query q = { R0 (x, y), R1 (y, z), R2 (z, v), R0′ (x, y ′ ), R1′ (y ′ , z ′ ), R2′ (z ′ , v), S0 (y, x), S1 (z, x), S0′ (y ′ , x), S1′ (z ′ , x), T0 (y, x), T1 (z, x), T0′ (y ′ , x), T1′ (z ′ , x) }. It can be observed that q is a query from sjfBCQU,A . However, it is not saturated. For instance, z → v ∈ K(R2 ), v → v ∈ Kc (q), and z → v ∈ K∗ (q \ {R2 }), while z → v ∈ / Kc (q). Thus, c query saturation adds z → v to K (q) via an introduction of fresh atoms U (z, v), U ′ (z, v). Analogously, it adds y → v to Kc (q) via V (y, v), V ′ (y, v), and so on. After q has been saturated, the database db is likewise saturated. Then, using functional consistency and collision consistency as in Example 8, one can “prune” the query in order to remove all the consistent edges from the key-nonkey graph in a top-down manner, leaving only the atoms R0 , R1 , R0′ , R1′ in the query.

5.2

Basic Properties of Saturated Queries

To further illustrate the notion of query saturation, let us briefly consider some of its simple but fundamental properties. Namely, consistent edges are transitively closed, inconsistent edges convey attacks, and two inconsistent edges do not collide. While all of these properties rely on query saturation, only the last property requires the query to have an acyclic attack graph. ▶ Lemma 14. Let q ∈ sjfBCQU be saturated. If x → y, y → z ∈ Kc (q), then x → z ∈ Kc (q)

M. Hannula

Proof. Now, x → y ∈ Kc (q) entails we find F ∈ q and G ∈ q \ {F } such that x → y ∈ K(F ) and x → y ∈ K∗ (G). Clearly, also y → z ∈ K(q \ {F }), and thus x → z ∈ K∗ (q \ {F }). Hence x → z ∈ Kc (q) follows due to saturation. ◀ ▶ Lemma 15. Let q ∈ sjfBCQU be saturated. Suppose x → y ∈ Ki (q). If F ∈ q generates x → y, then F ⇝ y. Proof. Toward contradiction, assume F does not attack y. Since the empty path connects NonKeyVars(F ) and y in Gaifman(q), we obtain y ∈ F +,q . This means x → y ∈ K∗ (q \ {F }). Since x → y ∈ K(F ) and, by definition, y → y ∈ Kc (q), we obtain by saturation that x → y ∈ Kc (q), a contradiction. ◀ ▶ Lemma 16. Let q ∈ sjfBCQU,A be saturated. If x → z, y → z ∈ Ki (q), then x = y. ̸ y. Then we find Proof. Toward contradiction, suppose x → z, y → z ∈ Ki (q) and and x = two distinct atoms F, G ∈ q such that x → y ∈ K(F ), u → y ∈ K(G). By Lemma 15, this leads to a cycle in the attack graph of q, a contradiction. Hence the statement of the lemma holds. ◀

5.3

Query Normality

As the next preprocessing step, we transform the query into a normal form. Informally, normalization ensures that whenever an atom generates more than one edge, all of them are inconsistent. Consequently, an atom generates either only consistent edges or only inconsistent edges, but never both. Furthermore, normalization guarantees that consistent edges are never reversed, never occur inside the non-primary-key part of an atom, and that the source of a consistent edge is never ⊥. These properties will be used in the later pruning stage. ▶ Definition 17 (Normality). Let q ∈ sjfBCQU,A . We say that q is normal if the following statements hold, for every F ∈ q with x = Key(F ). 1. If |NonKeyVars(F )| > 1, then x → y ∈ Ki (q), for each y ∈ NonKeyVars(F ). 2. y → z ∈ / Kc (q), for distinct y, z ∈ NonKeyVars(F ). 3. y → z ∈ Kc (q) implies z → y ∈ / Kc (q), for distinct y, z ∈ Vars(q). 4. ⊥ → z ∈ / Kc (q), for each z ∈ Vars(q). We illustrate the normalization process via an example. At this stage of the reduction, we may assume a problem instance (db, q) where q is a saturated query from sjfBCQU,A and db is a q-saturated database. ▶ Example 18. Consider a query q := {R(x, y, z, v), R′ (x′ )} ∪ {Si (x, v), Ti (y, z), Ui (x, x′ ), Vi (x′ , x), Wi (c, w) | i ∈ {0, 1}}. We have that Kc (q) = {x → v, y → z, x → x′ , x′ → x, ⊥ → w} and Ki (q) = {x → y, x → z}. The query is saturated but not normal. In particular, all items of query normality are

15

16

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

violated. Consider a q-saturated database db given as follows: R

x y a b a c

Si

x a

z v d f e f

v f

R′

x′ p

Ti

y b c

z d e

Wi

c w c 1

Ui

x x′ a p

Vi

x′ p

x a

The problem instance (db, q) can be transformed into one where the query is additionally normal in few steps. Each numbered item addresses a violation of the condition with the same number in the definition of query normality. 1. Let q1 := (q \ {R(x, y, z, v)}) ∪ {R1 (x, y, z)} and db1 := (db \ {R}) ∪ {R1 }, where R1 is obtained from R by dropping the column that corresponds to v. 2. Let q2 := (q \ {R1 (x, y, z)}) ∪ {R2 (x, y)} and db2 := (db1 \ {R1 }) ∪ {R2 }, where R2 is obtained from R1 by dropping the column that corresponds to z. 3. Let q3 := (q2 )x′ 7→x . Let db3 be obtained from db2 by replacing values b in columns corresponding to x′ with f (b), where f is the function determined by the consistent relations Vi . Since q3 is not variable-repetition-free, we further remove all repeated variable occurrences from atoms of q3 , keeping only the leftmost occurrence of each variable, and deleting the corresponding columns from the relations of db3 . 4. Let q ′ := (q3 \ {Wi (c, w) | i ∈ {0, 1}}) ∪ {Wi (c, 1) | i ∈ {0, 1}}, and let db′ := db3 . The final query takes the form q ′ := {R(x, y), R′ (x)} ∪ {Si (x, v), Ti (y, z), Ui (x), Vi (x), Wi (c, 1) | i ∈ {0, 1}}, and the final database db′ can be depicted as R

x y a b a c

R′

x a

Si

x a

Ti

y b c

v f

z d e

Wi

c 1 c 1

Ui

x a

Vi

x a

The query q ′ is now saturated and normal, and the database db′ is q ′ -saturated. The following normalization lemma is proven in Section D. It relies on a reduction called Normalize (Algorithm 4), which processes the normalization items one by one, analogously to the example above. ▶ Lemma 19 (Normalization Lemma). Let C be the set of pairs (db, q), where q is a saturated query from sjfBCQU,A and db is a q-saturated database. Then Normalize is an equivalencepreserving, SCC-monotone, polynomial-time reduction from C to C∪{true, false}. Additionally, for each (db, q), assuming (db′ , q ′ ) = Normalize(db, q) ∈ / {true, false}, we have that q ′ is normal.

M. Hannula

This completes the preprocessing stage of the polynomial-time algorithm. Note that the query obtained in Example 13 after saturation is already normal. However, in general a query may require normalization inbetween the saturation and the pruning steps. Next, we consider this pruning step.

5.4

Attack-Propagation Graphs

For the pruning step, we introduce an important notion called the attack-propagation graph. This graph is a subgraph of the key-nonkey graph. In particular, it does not include the dummy edges x → x that were introduced for Kc (q). ▶ Definition 20 (Attack-Propagation Graph). Let q be a saturated and normal query from sjfBCQU,A . We define the attack-propagation graph of q, denoted K⇝ (q), as follows the vertices consist of ⊥ and all variables in Vars(q); and an edge x → y ∈ K(q) is also an edge of K⇝ (q) if x → y ∈ Ki (q), or x → y ∈ Kc (q) and there exists an edge z → x ∈ Ki (q) such that z → y ∈ / Kc (q). We denote by LeafVars⇝ (q) the set of all variables in Vars(q) that have an incoming edge, but no outgoing edge, in K⇝ (q). Moreover, we denote by RootVars⇝ (q) the set of all variables in Vars(q) that have no incoming edge in K⇝ (q). Note that K⇝ (q) has no self-loops because q is variable-repetition-free and ⊥ has no incoming edge. Moreover, by Lemma 16, each variable x has at most one incoming edge in Ki (q). If such an edge exists, it is generated by a unique atom. By normality, if x → y ∈ K⇝ (q)∩Kc (q), then x is a variable (and not ⊥). The attack-propagation graph K⇝ (q) is a DAG in which every vertex has a unique root (see Lemma 71 in the appendix). Now, with slight abuse of terminology, the induced subgraph on a ⊆-maximal set of vertices sharing a root is called a tree of K⇝ (q). We have already seen in Lemma 15 that every edge of Ki (q) propagates an attack. By definition, all such edges belong to K⇝ (q). The remaining edges of K⇝ (q), namely those in K⇝ (q) ∩ Kc (q), propagate attacks similarly. The following lemma makes this precise. ▶ Lemma 21. Let q ∈ sjfBCQU,A be saturated and normal. Suppose x → y ∈ Ki (q) and y → z ∈ K⇝ (q) ∩ Kc (q). Let F ∈ q be the (unique) atom generating x → y. Then F ⇝ z. Proof. Toward contradiction, suppose F ̸⇝ z. Since F ⇝ y by Lemma 15, and {y, z} is an edge in the Gaifman graph of q, it follows that z ∈ K∗ (q \ {F }). But then, by the saturation of q we obtain x → z ∈ Kc (q), contradicting the assumption that y → z ∈ K⇝ (q)∩Kc (q). ◀

6

Query Pruning via Guarded Reductions

Then, we proceed to query pruning. The function Prune, described in Algorithm 5 (appendix), flattens the tree (of the attack-propagation graph) rooted at ⊥ into a tree of depth 1. During this process, it also removes all unguarded variables from this tree. We show that Prune is what we call a guarded reduction: it does not introduce new domain elements, preserves guarding relations, and maintains the structural properties of the query needed in subsequent reductions, including the necessary size-bounds needed to avoid an exponential

17

18

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

z1

y1

z2

z1

y2

x1

y1

x2

z2

y2

y1

x1

(LP)

⊥

z2

x2

y2

x1

⊥

x2

(LE)

⊥

x1

x2

(CEE)

⊥

z2

y2

y1

x1

(IEE)

y1

y1

x2

⊥

y2

x2

(LE)

y2

⊥

z2

x1

x2

(IEE)

⊥

y1

y2

(LE)

⊥

z2

y1

y2

z2

z2

Figure 2 The key-nonkey-graphs K(q) in query pruning (the edges corresponding to guarding relations are omitted). Every edge belongs to the attack-propagation graph K⇝ (q), except for the edge represented by the red arrow. The red vertices represent unguarded variables and blue vertices guarded variables. The dashed rectangles enclose the non-primary-key variables of a single atom. The pruning reduction is composed of leaf pruning (LP), leaf elimination (LE), consistent edge elimination (CEE), and inconsistent edge elimination (IEE).

blow-up incurred by repetitive reductions. We here only provide some crucial definitions and intuition; the reader is referred to Section E for full details. Define SrcVars→ (q) := {x ∈ Vars(q) | x belongs to a source SCC in K(q)}. A variable x ∈ Vars(q) is called a guard variable if x ∈ RootVars⇝ (q) ∩ SrcVars→ (q). The set of guard variables is denoted GuardVars(q). We say that y ∈ Vars(q) is guarded if there exists x ∈ GuardVars(q) such that x → y ∈ Kc (q). The set of all guarded variables is denoted GuardedVars(q) and the set of non-guarded variables is then NotGuardedVars(q) := Vars(q) \ GuardedVars(q). The sets NotGuardedVars(q) and GuardedVars(q) form a partition of Vars(q). Intuitively, if the number of source SCCs is bounded by a constant, then the number of values for guarded variables is polynomially bounded in a saturated database. Let us write KeyVars(q) := {x ∈ Vars(q) | ∃F ∈ q : x = Key(F )} and NotKeyVars(q) := Vars(q) \ KeyVars(q).

M. Hannula

19

▶ Lemma 22. Let c ∈ N. Let C be a class of pairs (db, q) such that db is a q-saturated database, q is a saturated and normal query from sjfBCQU,A , and |GuardVars(q)| ≤ c. Then, Prune is a guarded, equivalence-preserving, and polynomial-time reduction from C to C ∪ {true, false}. Additionally, assuming (db′ , q ′ ) = Prune(db, q) ∈ / {true, false}, it holds that OutK⇝ (q) (⊥) ⊆ GuardedVars(q) ∩ LeafVars⇝ (q) ∩ NotKeyVars(q).

(5)

We illustrate query pruning with the following example. ▶ Example 23. Consider a query q :={R(c, x1 , x2 ), S(x1 , y1 ), T (y1 , z1 , z2 )} ∪ {Ui (x1 , y2 ), Vi (x2 , y2 ), Wi (y1 , y2 ) | i ∈ {0, 1}} ∪ {Ai (u, y1 ), Bi (u, y2 ), Ci (u, z1 ) | i ∈ {0, 1}}, where c is a constant and all the remaining terms are variables. In particular, the variable u is a guard variable, and the variables y1 , y2 , z1 are guarded, while all the remaining variables are unguarded. The key-nonkey graph of q is illustrated in the top left corner of Figure 2. The attack-propagation graph of q consists of a single ⊥-rooted tree. Unless Prune(db, q) produces false, it outputs a pair (db′ , q ′ ), where the query takes the form q ′ ={R′ (c, y1 , y2 , z2 )} ∪ {Ai (u, y1 ), Bi (u, y2 ), Ci (u, z1 ) | i ∈ {0, 1}}. This concludes the example. As the example demonstrates, unguarded variables are dropped in leaves, and consequently a relation can only be extended by guarded variables. This order of reduction is important to prevent the database size from exploding at intermediate stages. To illustrate how guarding helps in this, consider the following example. ▶ Example 24. Consider a query q = {R1 (c, x1 ), R2 (x1 , x2 ), . . . , Rn (xn−1 , xn )} ∪ {Si,j (u, xi ) | i ∈ [n], j ∈ {0, 1}}, where c is a constant and all the remaining terms are variables. In particular, the variables x1 , . . . , xn are guarded. Let db be an arbitrary database over the schema of q. Suppose (db′ , q ′ ) = Prune(db, q) ∈ / {true, false}. Then, the query q ′ is obtained by flattening q: q ′ = {R′ (c, x1 , . . . , xn )} ∪ {Si,j (u, xi ) | i ∈ [n], j ∈ {0, 1}}. Furthermore, the database db′ is essentially obtained by introducing a fact R′ (c, d1 , . . . , dn ) for each sequence of facts R1 (c, d1 ), R2 (d1 , d2 ), . . . , Rn (dn−1 , dn ) from db. Since the database ′ db is assumed to be q-saturated, the size of (R′ )db is bounded by the size of the active domain of db, in particular, by the number of values the variable u takes in db. Without ′ guarding, the size of (R′ )db could be 2n for a database whose size is linear in n.

7

Variable Substitution via Substitution-Guarded Reductions

Query pruning is used as a subroutine in our main algorithm that otherwise follows the known first-order rewriting strategy. Namely, at each step we replace quantified variables with constants, resulting in what is essentially an alternating algorithm. This substitution step is what we call substitution-guarded, that is, it preserves similar desirable properties as guarded reductions. It is also strict, meaning that it decreases the query size (defined appropriately). For the details, see Section F. We note here that the effect of Substitutef on a query is to replace variables with constants according to f .

20

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

▶ Lemma 25 (Substitution Lemma). Let C consist of all (db, q) ∈ DB × sjfBCQU,A , where q is a saturated and normal query and db is a q-saturated database. Then, for each (db, q) ∈ C, substitutable Y ⊆ Vars(q), and function f : Y → Const, (db, q) 7→ Substitutef (db, q) is a strict, substitution-guarded, and polynomial-time reduction from C to C ∪ {true, false}. We shortly illustrate substitution-guarded reductions via the previous example. ▶ Example 26. Consider the query q given in Example 23. Let f be a function mapping a variable v to a constant c, and let q0 be obtained from q by replacing the constant c with a variable v (in particular, q = (q0 )v7→c ). Then Y = {v} is substitutable in q (see Definition 52 in the appendix), and unless Substitutef (db0 , q0 ) is false, we have Substitutef (db0 , q0 ) = (db, q), where db, db0 are some databases. Consider then the query q ′ in Example 23. Let g be a function mapping the variables y1 , y2 , z2 respectively to constants d, e, f . Let q0′ be obtained from q ′ by replacing the variables y1 , y2 , z2 with a constants d, e, f (formally, q0′ := qy′ 1 ,y2 ,z2 7→d,e,f ). Then, Y ′ = {y1 , y2 , z2 } is substitutable in q ′ , and unless Substitutef (db′ , q ′ ) is false, we have Substitutef (db′ , q ′ ) = (db′0 , q0′ ), where db′ , db′0 are some databases. Note that the substitution step is not equivalence-preserving, as it essentially corresponds to the existential and universal quantification in the first-order rewriting. Consider the two substitutions in the above example. First, since v is unattacked in q0 , there exists a constant c (see Lemma 127 in the appendix) such that every repair of db satisfies q0 if and only if every repair of db satisfies (q0 )v7→c . Second, it is clear that every repair of db′ satisfies q ′ if and only if for each fact of the form R′ (c, d, e, f ) from db′ , every repair of db′ satisfies qy′ 1 ,y2 ,z2 7→d,e,f . The substitution steps together with the pruning step constitute the building blocks of our main lemma, to which we turn next.

8

Proof of Main Theorem

The main theorem is proven using the following lemma. The reader is referred to Section G for details. ▶ Lemma 27 (Main Lemma). Let c ∈ N. Let C be a class of pairs (db, q) such that db is a q-saturated database, q is a saturated and normal query from sjfBCQU,A , and #srcSCC(K(q)) ≤ c. Then Solve is an equivalence-preserving, polynomial-time reduction from C to {true, false}. A schematic outline of the reduction performed by Solve (see Algorithm 6) is shown in Figure 3. Let q be a saturated and normal query. Unless ⊥ already has outgoing edges in the attack-propagation graph K⇝ (q), the algorithm first selects a suitable non-attacked root variable x1 and existentially substitutes it with a constant. It then flattens the tree rooted at ⊥ by pruning it, thereby removing all non-guarded variables from the tree. Finally, the guarded variables that remain in the tree are universally substituted by a constant. This removes one tree from K⇝ (q), after which the process repeats on the remaining graph. At any stage, a computation branch may terminate with false; if it reaches the end, it returns true. Guarding guarantees that the number of branches is polynomially bounded, with each branch running in polynomial time. With the help of this lemma, we can now prove the main theorem.

M. Hannula

21

··· x1

x2

xn (existential) substitution

··· ⊥

x2

xn pruning

··· ⊥

x2

xn (universal) substitution

··· x2

xn

Figure 3 Schematic outline for the main lemma. The triangles represent the trees of the attackpropagation graph K⇝ (q), with the red area representing unguarded and the blue area guarded variables.

Proof of Theorem 4. Let c ∈ N, and let Q be a class of queries q from sjfBCQU,A such that #srcSCC(K(q)) ≤ c. By Lemmas 9 and 49, we may assume without loss of generality that every query in sjfBCQU,A is variable-repetition-free; informally, we initially saturate the database and then remove variable repetitions. Consider an input (db, q) for CERTAINTY(Q). By Lemma 9, it is possible in polynomial time to either determine whether or not (db, q) ∈ CERTAINTY, or obtain a q-saturated database db0 such that (db, q) ∈ CERTAINTY ⇐⇒ (db0 , q) ∈ CERTAINTY. Then, by Lemma 12, it is possible in polynomial time to either determine whether or not (db0 , q) ∈ CERTAINTY, or obtain a pair (db1 , q0 ), where db1 is a q0 -saturated database, q0 is a saturated query from sjfBCQU,A , #srcSCC(K(q0 )) ≤ #srcSCC(K(q)), and (db0 , q) ∈ CERTAINTY ⇐⇒ (db1 , q0 ) ∈ CERTAINTY. Then, by Lemma 19, it is possible in polynomial time to either determine whether or not (db1 , q0 ) ∈ CERTAINTY, or obtain a pair (db2 , q1 ), where db2 is a q1 -saturated database, q1 is a saturated and normal query from sjfBCQU,A , #srcSCC(K(q1 )) ≤ #srcSCC(K(q0 )), and (db1 , q0 ) ∈ CERTAINTY ⇐⇒ (db2 , q1 ) ∈ CERTAINTY. Observe that #srcSCC(K(q1 )) ≤ c. Finally, by Lemma 27, one can decide in polynomial time whether or not (db2 , q1 ) ∈ CERTAINTY. By composition, we conclude that CERTAINTY(Q) is solvable in polynomial time.

◀

22

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

9

Conclusion

The aim of this paper was to understand the structural properties that govern the combined complexity of consistent query answering. The class of self-join-free conjunctive queries with acyclic attack graphs and unary primary keys was isolated for case study. The main message of our investigation is that, moving from data complexity to combined complexity, it may be necessary to shift from atom-level granularity to variable-level granularity. To this end, we coupled attack graphs with new notions such as key-nonkey graphs and attack-propagation graphs, both taking the query variables as vertices. We also introduced novel preprocessing techniques such as query and database saturation, and query normalization. Additionally, we introduced the notion of variable guarding to control the size of the search space. Using these concepts and techniques, we proved that the combined complexity of consistent query answering is in polynomial time for any class of queries (from the aforementioned class), where the number of source SCCs in the query’s key-nonkey graph is bounded. The following result (see Section H) shows that without this boundedness restriction, the problem is as hard as the combined complexity of CQA for Boolean CQs and EGDs. ▶ Theorem 28. CERTAINTY(sjfBCQU,A ) is ΠP2 -complete. The present paper gives rise to a number of follow-up questions. First, observing that Theorems 4 and 28 do not provide a full dichotomy, one may ask whether this gap can be closed or tightened. Second, as the techniques introduced in this paper rely on the unary primary-key restriction, it is left open whether they can be extended to composite primary keys. Third, as our case study covers only the first-order rewritable part of data complexity (see Theorem 3), one may ask whether our techniques extend to arbitrary self-join-free queries with tractable data complexity.

References 1

Isolde Adler. Tree-width and functional dependencies in databases. In PODS, pages 311–320. ACM, 2008.

2

Marcelo Arenas and Leopoldo E. Bertossi. On the decidability of consistent query answering. In AMW, volume 619 of CEUR Workshop Proceedings. CEUR-WS.org, 2010.

3

Marcelo Arenas, Leopoldo E. Bertossi, and Jan Chomicki. Consistent query answers in inconsistent databases. In PODS, pages 68–79. ACM Press, 1999.

4

Sebastian Arming, Reinhard Pichler, and Emanuel Sallinger. Complexity of repair checking and consistent query answering. In ICDT, volume 48 of LIPIcs, pages 21:1–21:18. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2016.

5

Marco Calautti, Ester Livshits, Andreas Pieris, and Markus Schneider. Counting database repairs entailing a query: The case of functional dependencies. In PODS, pages 403–412. ACM, 2022.

6

Andrea Calì, Domenico Lembo, and Riccardo Rosati. On the decidability and complexity of query answering over inconsistent and incomplete databases. In PODS, pages 260–271. ACM, 2003.

7

Zhiwei Fan, Paraschos Koutris, Xiating Ouyang, and Jef Wijsen. Lincqa: Faster consistent query answering with linear time guarantees. Proc. ACM Manag. Data, 1(1):38:1–38:25, 2023.

M. Hannula

8

Diego Figueira, Anantha Padmanabha, Luc Segoufin, and Cristina Sirangelo. A simple algorithm for consistent query answering under primary keys. Log. Methods Comput. Sci., 21(1), 2025.

9

Georg Gottlob, Nicola Leone, and Francesco Scarcello. Hypertree decompositions and tractable queries. J. Comput. Syst. Sci., 64(3):579–627, 2002.

10

Martin Grohe, Thomas Schwentick, and Luc Segoufin. When is the evaluation of conjunctive queries tractable? In Jeffrey Scott Vitter, Paul G. Spirakis, and Mihalis Yannakakis, editors, Proceedings on 33rd Annual ACM Symposium on Theory of Computing, July 6-8, 2001, Heraklion, Crete, Greece, pages 657–666. ACM, 2001. doi:10.1145/380752.380867.

11

Teemu Hankala, Miika Hannula, Yasir Mahmood, and Arne Meier. Parameterised complexity of consistent query answering via graph representations. CoRR, abs/2412.08324, 2024.

12

Miika Hannula and Jef Wijsen. A dichotomy in consistent query answering for primary keys and unary foreign keys. In PODS, pages 437–449. ACM, 2022.

13

Aziz Amezian El Khalfioui and Jef Wijsen. Consistent query answering for primary keys and conjunctive queries with counting. In ICDT, volume 255 of LIPIcs, pages 23:1–23:19. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2023.

14

Aziz Amezian El Khalfioui and Jef Wijsen. Computing range consistent answers to aggregation queries via rewriting. Proc. ACM Manag. Data, 2(5):218:1–218:19, 2024.

15

Aziz Amezian El Khalfioui and Jef Wijsen. Computing consistent least upper bounds in aggregate logic. In ICDT, volume 365 of LIPIcs, pages 4:1–4:21. Schloss Dagstuhl - LeibnizZentrum für Informatik, 2026.

16

Phokion G. Kolaitis, Nina Pardal, Jonni Virtema, and Jef Wijsen. Rewriting consistent answers on annotated data. Proc. ACM Manag. Data, 3(2):110:1–110:26, 2025.

17

Paraschos Koutris, Xiating Ouyang, and Jef Wijsen. Consistent query answering for primary keys on path queries. In PODS, pages 215–232. ACM, 2021.

18

Paraschos Koutris, Xiating Ouyang, and Jef Wijsen. Consistent query answering for primary keys on rooted tree queries. Proc. ACM Manag. Data, 2(2):76, 2024.

19

Paraschos Koutris and Jef Wijsen. Consistent query answering for self-join-free conjunctive queries under primary key constraints. ACM Trans. Database Syst., 42(2):9:1–9:45, 2017.

20

Paraschos Koutris and Jef Wijsen. Consistent query answering for primary keys in datalog. Theory Comput. Syst., 65(1):122–178, 2021.

21

Dániel Marx. Tractable hypergraph properties for constraint satisfaction and conjunctive queries. J. ACM, 60(6):42:1–42:51, 2013.

22

Dany Maslowski and Jef Wijsen. A dichotomy in the complexity of counting database repairs. J. Comput. Syst. Sci., 79(6):958–983, 2013.

23

Anantha Padmanabha, Luc Segoufin, and Cristina Sirangelo. A dichotomy in the complexity of consistent query answering for two atom queries with self-join. Proc. ACM Manag. Data, 2(2):74, 2024.

23

24

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

A

Auxiliary Concepts and Lemmas

For a finite set of atoms q, we define: #rel(q) := the number of occurrences of relation symbols in q, #var(q) := the number of occurrences of variables in q, #distvar(q) := the number of variables in q, #const(q) := the number of occurrences of constant symbols in q. We define the size of q as ||q|| := #rel(q) + 2#var(q) + #distvar(q) + #const(q). Thus, replacing a variable by a constant strictly decreases ||q||, and so does replacing two variables with one variable. Observe that ||q|| remains linearly bounded by a more standard way of defining the size of q, such as #rel(q) + #var(q) + #const(q). The following lemma will be used in later reductions. ▶ Lemma 29. Let G = (V, E) be a directed graph. 1. If u, v ∈ V are two vertices such that u is connected to v in G, and G′ := (V, E ∪ {(u, v)}), then #srcSCC(G′ ) = #srcSCC(G). 2. If x, y, z ∈ V are three vertices such that (x, y), (y, z), (x, z) ∈ E, and G′ := (V, E \ {(x, z)}), then #srcSCC(G′ ) = #srcSCC(G). Proof. We claim that in both cases, a vertex w0 is connected to another vertex w1 in G if and only if this holds in G′ . The statements of the items then follow by a straightforward argument. In Item 1, the claim holds clearly. In Item 2, the claim holds because the edge (x, z) in a path of G can be replaced by two edges (x, y), (y, z) in G′ . ◀

B

Lemmas for Section 4

Consider the function DBSaturate given in Algorithm 1. ▶ Lemma 9 (Database Saturation Lemma). DBSaturate : DB×sjfBCQU → DB∪{true, false} is an equivalence-preserving polynomial-time reduction such that for every pair (db, q), assuming db′ = DBSaturate(db, q) ∈ / {true, false}, we have that 1. db′ is q-saturated, 2. db′ ⊆ db. Proof. It is straightforward to verify that each individual step db 7→ db′ in the algorithm is such that (db, q) ∈ CERTAINTY if and only if (db′ , q) ∈ CERTAINTY. Specifically, a repair of db′ that falsifies q can be extended to one of db falsifying q by picking the violating fact from the block of facts of the form R(a, −). The only exception is the case of functional consistency having two witnesses; since R(x, y, −) ∈ q and x → y ∈ Kc (q) implies the existence of another atom of the form S(x, y, −) ∈ q, one here picks from R(a, b, −) if S(a, b, −) does not belong to r′ , and R(a, c, −) if S(a, c, −) does not belong to r′ . If in the end db↾R = ∅ for some R ∈ q, then clearly (db, q) ∈ / CERTAINTY. It is straightforward to verify that the procedure gives rise to a an equivalence-preserving polynomial-time reduction (db, q) 7→ db ∪ {true, false}. ◀

M. Hannula

Algorithm 1 DBSaturate(db, q)

Input : A query q and a database db Output : A q-saturated database 1 repeat 2 while there exists a violation of non-triviality, pairwise consistency, or guardedness witnessed by R(a, −) ∈ db do 3 remove from db all facts of the form R(a, −); while there exists a violation of functional consistency witnessed by R(a, b, −), R(a, c, −) ∈ db do remove from db all facts of the form R(a, −);

4

5

while there exists a violation of collision consistency witnessed by R(a, −) ∈ db, possibly together with S(a′ , b, −) ∈ db do remove from db all facts of the form R(a, −);

6

7

until no while-loop is entered; if db↾R = ∅ for some R ∈ q then 10 return false; 8 9

11

return db;

C

Lemmas for Section 5.1

▶ Lemma 30. Let q ∈ sjfBCQU , and let x → y ∈ K∗ (q). Let r be a repair of a database db. Let θ and θ′ be two valuations such that θ(q) ⊆ r, θ′ (q) ⊆ r. If x is a variable and θ(x) = θ(x), then θ(y) = θ′ (y). If x = ⊥, then θ(y) = θ′ (y). Proof. Suppose x is a variable. From x → y ∈ K∗ (q) we obtain a path x1 , x2 , . . . , xn where x1 = x and xn = y. Since r is consistent and θ(x1 ) = θ′ (x1 ) it follows by a simple induction that θ(y) = θ′ (y). Suppose x = ⊥. From x → y ∈ K∗ (q) we obtain a path x1 , x2 , . . . , xn where x1 = ⊥ and xn = y. Since r is consistent and θ(q) ⊆ r and θ′ (q) ⊆ r, we obtain θ(x2 ) = θ′ (x2 ). Informally, the edge ⊥ → x2 arises from an atom of the form R(a, x2 , −), where a is a constant, and both θ and θ′ must pick the unique fact from the R-block of r whose primary-key value is a. Again, by simple induction we obtain that θ(y) = θ′ (y). ◀

C.1

Controlled and Size-Monotone Reductions

Throughout the paper, a reduction f : DB × sjfBCQU,A → (DB × sjfBCQU,A ) ∪ {true, false} is called strict if it strictly decreases the query size, i.e., if ||q ′ || < ||q|| whenever (db′ , q ′ ) = f (db, q) ∈ / {true, false}. ▶ Definition 31 (c-Controlled and Size-Monotone Reduction). Let c ∈ N. A reduction f : DB × sjfBCQU,A → (DB × sjfBCQU,A ) ∪ {true, false} is c-controlled if for each (db, q) ∈ DB×sjfBCQU,A , having (db′ , q ′ ) := f (db, q) ∈ / {true, false}, the following hold:

25

26

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

(i) ||q ′ || ≤ ||q|| + c; (ii) ||db′ || ≤ ||db|| + c|adom(db)|; (iii) adom(db′ ) ⊆ adom(db); (iv) Vars(q ′ ) ⊆ Vars(q). The reduction is size-monotone if it is 0-controlled. It follows immediately that, given a fixed constant c, any polynomial-length composition of polynomial-time c-controlled reductions remains computable in polynomial time. ▶ Lemma 32. Let c ∈ N. Any polynomial-length sequence of c-controlled polynomial-time reductions can be evaluated in polynomial time.

C.2

Saturation Lemma

Next, we describe an individual saturation step and prove its correctness. At this stage of the overall reduction, the database db is q-saturated. Saturation Step. Let q ∈ sjfBCQU,A . A pair (x, z) ∈ (Vars(q) ∪ {⊥}) × Vars(q) \ {(x, x) | x ∈ Vars(q)}

(6)

is called possible joinable (over q), and it is joinable (over q) if there exists F ∈ q and y ∈ Vars(q) such that F, x, y, z satisfy Items 1–3 of Definition 10. Note that F is an atom of the form T (t, y, −), where t = x (if x is a variable) or t = a ∈ Const (if x = ⊥). Given such F, x, y, z, we define q ′ := q ∪ {R(x, z), S(x, z)}, if x is a variable, and q ′ := q ∪ {R(a, z), S(a, z)}, if x = ⊥. Furthermore, R and S are fresh relation names, i.e., R, S ∈ / Rel(q). Since y → z ∈ Kc (q), it holds that either (i) y = z or (ii) there exists an atom of the form U (y, z, −) in q. Let db be a database. We let db0 be a database obtained from db by applying the following case-specific rule until no longer possible: (i) Case y = z. If T (a, b, −), T (a, b′ , −) ∈ db, where b = ̸ b′ , then remove block(T, a, db) from db. ̸ c′ , (ii) Case U (y, z) ∈ q. If T (a, b, −), T (a, b′ , −), U (b, c, −), U (b′ , c′ , −) ∈ db, where c = then remove block(T, a, db) from db. Furthermore, we let db1 be obtained from db0 by applying the following case-specific rule until no longer possible: (i) Case y = z. If T (a, b, −) ∈ db0 , then add R(a, b), S(a, b) to db0 . (ii) Case U (y, z) ∈ q. If T (a, b, −), U (b, c, −) ∈ db0 , then add R(a, c), S(a, c) to db0 . Finally, we define db′ := DBSaturate(db1 , q ′ ). Given a joinable pair (x, z), we let SaturateStepx,z (db, q) = false if db′ ∈ {true, false}, and otherwise (when db′ is a database), SaturateStepx,z (db, q) = (db′ , q ′ ). The following saturation lemma is the key lemma in this work.

M. Hannula

27

▶ Lemma 33 (Saturation Lemma). Let C be a set of pairs (db, q) ∈ DB × sjfBCQU,A such that db is q-saturated. There exists c ∈ N such that for each q ∈ sjfBCQU,A and each joinable pair (x, z), (db, q) 7→ SaturateStepx,z (db, q) is an equivalence-preserving, SCC-monotone, c-controlled, polynomial-time reduction from C to C ∪ {true, false}. Proof. Clearly, we can select c ∈ N such that SaturateStepx,z is c-controlled and in polynomial time. Furthermore, by Lemma 29, the reduction is SCC-monotone, and by Lemma 9 it is into C ∪ {true, false}; in particular, db′ is q ′ -saturated if a pair (db′ , q ′ ) is returned. We consider the lemma statement in the case that x is a variable. The case where x is ⊥ is analogous. Note that z is also a variable. By the lemma hypothesis, there exists F ∈ q and a variable y such that F, x, y, z satisfy Items 1–3 of Definition 10. (Proof of SaturateStepx,z (db, q) ∈ C ∪ {true, false}.) Assume (db′ , q ′ ) = SaturateStepx,z (db, q) ∈ / {true, false}. By Lemma 9, we have that db′ is q ′ -saturated. By definition, q ′ remains variable-repetitionfree. To show that q ′ ∈ sjfBCQU,A , it suffices to prove that q ′ has an acyclic attack graph. It is q′

clear that R(x, z) and S(x, z) do not attack any atoms in q ′ . It thus suffices to show G ⇝ H q

q′

entails G ⇝ H for all G, H ∈ q. Now, G ⇝ H means that Gaifman(q ′ ) has a path U between ′ ′ NonKeyVars(G) and Vars(H) containing no variables from G+,q . Since G+,q ⊆ G+,q , no variable from U belongs to G+,q either. q

If U is also a path in Gaifman(q), we obtain G ⇝ H, as required. (The case where x = ⊥ stops here, as atoms of the form R(a, z), S(a, z), where a is a constant, do not generate edges to the Gaifman graph.) Thus, suppose U is not a path in Gaifman(q), in which case it contains an edge that does not belong to Gaifman(q). The only possibility is that this edge is {x, z}; that is, it is an edge introduced by the atom R(x, z) (or S(x, z)). Note that x and z are not in G+,q . Therefore, we have F ̸= G, because otherwise Items 1 and 3 would entail z ∈ G+,q , a contradiction; specifically, we would have Key(G) = x and x → z ∈ K∗ (q \ {G}). Now, let U ′ be obtained from U by replacing the edge {x, z} with two edges {x, y} and {y, z}. Clearly, U ′ is a path in Gaifman(q) between NonKeyVars(G) and Vars(H). We claim that no variable from U ′ belongs to G+,q . Toward contradiction, suppose this is not the case. As U is not separated by G+,q , it follows that y ∈ G+,q . But then, Item 2 entails z ∈ G+,q , again a contradiction. We conclude by contradiction that NonKeyVars(G) and Vars(H) are q not separated by G+,q . This establishes G ⇝ H. Hence the attack graph of q ′ is acyclic. (Proof of equivalence-preservation.) We consider the case where y = ̸ z; the case where y = z is analogous. In this case, q contains an atom of the form G := U (y, z, −). Furthermore, we write F = T (x, y, −). We prove two claims, reflecting the two stages in the construction of db′ . First we show that the block removal preserves equivalence. ▷ Claim 34. If T (a, b, −), T (a, b′ , −), U (b, c, −), U (b′ , c′ , −) ∈ db, where c ̸= c′ , then (db, q) ∈ CERTAINTY if and only if (db \ block(T, a, db), q) ∈ CERTAINTY.

28

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Proof. It suffices to show that (db \ block(T, a, db), q) ∈ / CERTAINTY implies (db, q) ∈ / CERTAINTY. Let r be a repair of db \ block(T, a, db) falsifying q. Thus, r ∪ {T (a, b, −)} and r ∪ {T (a, b′ , −)} are two distinct repairs of db. Assume toward contradiction that they both satisfy q. Let θ and θ′ be valuations such that θ(q) ⊆ r ∪ {T (a, b, −)} and θ′ (q) ⊆ r ∪ {T (a, b′ , −)}. Clearly, θ(F ) = T (a, b, −) and θ′ (F ) = T (a, b′ , −), whence θ(x) = θ′ (x). Furthermore, θ(q \ {F }) ⊆ r, θ′ (q \ {F }) ⊆ r and x → z ∈ K∗ (q \ {F }), and thus Lemma 30 implies θ(z) = θ′ (z). Since db is q-saturated, Item 1 implies that U db is consistent. In particular, both U (b, c, −) and U (b′ , c′ , −) belong to r, hence θ(G) = U (b, c, −) and θ′ (G) = U (b′ , c′ , −). But then c ̸= c′ entails θ(z) ̸= θ(z ′ ), which leads to a contradiction. We conclude by contradiction that db has a repair that falsifies q. ◁ Then, we show that the database can be extended, reflecting the second stage. ▷ Claim 35. Suppose T (a, b, −), T (a, b′ , −), U (b, c, −), U (b′ , c′ , −) ∈ db implies c = c. Let db′ := {R(a, c), S(a, c) | ∃b : T (a, b, −), U (b, c, −) ∈ db} ∪ db Then, (db, q) ∈ CERTAINTY if and only if (db′ , q ′ ) ∈ CERTAINTY. Proof. It suffices to show that (db′ , q ′ ) ∈ / CERTAINTY implies (db, q) ∈ / CERTAINTY. Let r′ be a repair of db′ falsifying q ′ . Let r be obtained from r′ by dropping all the R-facts and S-facts. Clearly r is a repair of db. Assume toward contradiction that r satisfies q. Let θ be a valuation such that θ(q) ⊆ r. Suppose θ(F ) = T (a, b, −) and θ(G) = U (b, c, −). By the claim assumption, {R(a, c)} and {S(a, c)} are singleton blocks of db′ . Thus θ(q ′ ) ⊆ r′ , contradicting the assumption. We conclude by contradiction that r falsifies q. ◁ Now, by the definition of the reduction, equivalence-presevation follows by Claims 34 and 35 and Lemma 9. This concludes the proof of the lemma. ◀

C.3

Saturation Step

We begin by stating the following conventions, which will be used from hereafter. ▶ Remark 36. For a function f , an assignment of the form (db, q) ← Try(f (db, q, ⃗x)) means the following: the current procedure immediately returns f (db, q, ⃗x) if f (db, q, ⃗x) ∈ {true, false}. If f (db, q, ⃗x) = (db′ , q ′ ) ∈ / {true, false}, then (db, q) ← (db′ , q ′ ). Furthermore, whenever an expression of the form (g(db, q), q ′ ) occurs and g(db, q) ∈ {true, false}, the expression is understood to evaluate to this Boolean value rather than to a pair. Throughout the paper, reductions from C to C ∪ {true, false} are extended to be the identity on true and false. In this way, we can also describe their composition properties. To start with, the following property is immediate. ▶ Proposition 37. SCC-monotone and equivalence-preserving reductions are both closed under composition. The algorithm for Saturate, given in Algorithm 2, applies Lemma 33 exhaustively to construct a saturated query. Since Lemma 33 describes an equivalence-preserving and SCC-monotone reduction, it gives rise to the following result.

M. Hannula

▶ Lemma 12 (Query Saturation Lemma). Let C be the set of pairs (db, q), where q is a query from sjfBCQU,A and db is a q-saturated database. Then Saturate is an equivalencepreserving, SCC-monotone, polynomial-time reduction from C to C∪{true, false}. Additionally, for each (db, q), assuming (db′ , q ′ ) = Saturate(db, q) ∈ / {true, false}, we have that q ′ is saturated and binary-saturated. Proof. The algorithm applies Lemma 33 exhaustively. Then, by Proposition 37, we obtain that Saturate is an equivalence-preserving and SCC-monotone reduction from C to C ∪ {true, false}. In particular, this reduction does not introduces cycles into the attack graph. Furthermore, q ′ is saturated and binary-saturated by construction. It remains to show that Saturate runs in polynomial time. Suppose (db′ , q ′ ) is some intermediate pair considered during computation, and suppose (db, q) is the initial input. Now, there exists a constant c such that each individual step SaturateStepx,z (db′ , q ′ ) is c-controlled. Since (x, z) becomes non-joinable after SaturateStepx,z , the number of iterations is bounded by (|Vars(q)| + 1)2 by Item (iv) of Definition 31. Consequently, as the final output is a polynomial-length composition of c-controlled reductions, by Lemma 32 it can be computed in polynomial time. To conclude, we need to verify that the condition of the while-loop is polynomial-time checkable. This condition consists of scans over q ′ and, for each F ∈ q ′ , reachability checks over K(q ′ \ {F }). Since q ′ is polynomially bounded in q, this can be done in polynomial time in the initial input. We may thus conclude that Saturate runs in polynomial time. ◀ Algorithm 2 Saturate(db, q)

Input : A database db and a query q ∈ sjfBCQU,A . Output : false or (db′ , q ′ ) where db′ is a q ′ -saturated database and q ′ a saturated and binary-saturated query from sjfBCQU,A . 1 while a possibly joinable (x, z) witnesses that q is not saturated and binary-saturated do 2 (db, q) ← Try(SaturateStepx,z (db, q)); 3

return (db, q)

D

Lemmas for Section 5.3

In this section we prove the lemmas that are the building blocks the normalization process. We begin by setting up some notational conventions, assuming an underlying query q from sjfBCQU,A . Atoms. Let F ∈ q, and let y ∈ NonKeyVars(F ). Without loss of generality F is of the form R(x, y, ⃗z) ∈ q. Then, we define F −y as the atom R′ (x, ⃗z), where R′ is a fresh relation symbol not occurring in q. If y ∈ / NonKeyVars(F ), then F −y := F . Moreover, then, q −y := {F −y | F ∈ q}. Facts. Let A be a fact. Assume that F is the unique underlying atom in q with the same relation name. Suppose y ∈ NonKeyVars(F ), and suppose without loss of generality that F is of the form R(x, y, ⃗z). Assuming A is of the form R(a, b, ⃗c), define A−y as the fact R′ (a, ⃗c), where R′ is the relation name of F −y . If y ∈ / NonKeyVars(F ), then A−y := A. Moreover, −y given a database db, we write db := {A−y | A ∈ db}.

29

30

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

D.1

First Condition

Given q ∈ sjfBCQU,A , F ∈ q, and y ∈ NonKeyVars(F ), define q ′ := (q \{F })∪{F −y }. Suppose F is of the form T (x, y, ⃗z), in which case F −y is of the form T ′ (x, ⃗z). Then, considering a database db, define db0 := {T ′ (a, ⃗c) | ∃b : T (a, b, ⃗c) ∈ db} ∪ (db \ db↾T ).

(7)

We then let RemoveF,y (db, q) := (db′ , q ′ ), where db′ := DBSaturate(db0 , q ′ ). ▶ Lemma 38 (Normality, Item 1). Let C be the set of pairs (db, q), where q is a saturated and binary-saturated query from sjfBCQU,A and db is a q-saturated database. Then for each F ∈ q such that NonKeyVars(F ) > 1 and x → y ∈ Kc (q) ∩ K(F ), (db, q) 7→ RemoveF,y (db, q) is a strict, size-monotone, SCC-monotone, equivalence-preserving, polynomial-time reduction from C to C ∪ {true, false}. Proof. Let us assume that F is of the form T (x, y, ⃗z), in which case F −y is of the form T ′ (x, ⃗z), and db0 is as in (7). Given an atom I ∈ q, let us write I ′ for its corresponding atom in q ′ ; that is, I ′ = I when I ∈ q \ {F }, while F ′ = F −y . Since q is binary-saturated and NonKeyVars(F ) > 1, it follows that q \ {F } contains two atoms of the form R(x, y), S(x, y). Assume (db′ , q ′ ) = RemoveF,y (db, q) ∈ / {true, false}. Now, RemoveF,y is SCC-monotone due to K(q) = K(q ′ ). Moreover, that it is size-monotone and strict is clear by construction. Using Lemma 9, the reduction is in polynomial time. It remains to prove that it is equivalencepreserving and that (db′ , q ′ ) ∈ C. Membership of (db′ , q ′ ) in C. Now, db′ is q ′ -saturated by Lemma 9. The saturation of q ′ is straightforward to verify by the construction and the fact that q is binary-saturated. For the binary-saturation of q ′ , given u → v ∈ Kc (q ′ ), we need to prove that q ′ contains two atoms of the form U (u, v), V (u, v). It is straightforward to verify that Kc (q ′ ) ⊆ Kc (q). Thus, by binary-saturation q we obtain that q contains two atoms of the form U (u, v), V (u, v). Since F is neither of these atoms, q ′ contains these atoms too. Therefore, q ′ is binary-saturated. To conclude that (db′ , q ′ ) ∈ C, it remains to prove the following claim. ▷ Claim 39. q ′ ∈ sjfBCQU,A . Proof. Clearly, q ′ remains variable-repetition-free. q′

q

To prove that q ′ has an acyclic attack graph, it suffices to show that G′ ⇝ H ′ entails G ⇝ H, q

′

for all G′ , H ′ ∈ q ′ . Now, G ⇝ H means that Gaifman(q ′ ) has a path between some variables +,q ′ x ∈ NonKeyVars(G′ ) and y ∈ Vars(H ′ ) such that no variable on the path belongs to (G′ ) . Since every edge in Gaifman(q ′ ) belongs also to Gaifman(q), the same path exists in Gaifman(q) +,q ′ (between x ∈ NonKeyVars(G) and y ∈ Vars(H)). Note that G+,q ⊆ (G′ ) due to having both R(x, y) and S(x, y) in q. Thus no variable on the path belongs to G+,q either. This q yields G ⇝ H as required. ◁

M. Hannula

31

(Equivalence-preservation) It suffices to show that (db, q) ∈ CERTAINTY if and only if (db0 , q ′ ) ∈ CERTAINTY. Suppose each repair of db0 satisfies q ′ . Let r be a repair of db. Let r′ be obtained from r by replacing each T (a, b, ⃗c) with T ′ (a, ⃗c). Clearly r′ is a repair of db0 . By assumption r′ satisfies q ′ . Let θ be a valuation such that θ(q ′ ) ⊆ r′ . In particular, T (θ(x), θ(⃗z)) ∈ r′ , which means that there exists a constant b such that T (θ(x), b, θ(⃗z) ∈ r. Since x → y ∈ Kc (q \ {T }), there exists an atom of the form R(x, y, −) ∈ q \ {T }. In particular, we have R(θ(x), θ(y), −) ∈ r′ , and hence R(θ(x), θ(y), −) ∈ r. Since db is saturated, we obtain b = θ(y). This shows θ(q) ⊆ r. We conclude that each repair of db satisfies q. Suppose each repair of db satisfies q. Let r′ be a repair of db0 . Let r be obtained from r′ by replacing each T ′ (a, ⃗c) with an arbitrary fact of the form T (a, b, ⃗c) ∈ db. It is clear that r is a repair, and hence there exists a valuation θ such that θ(q) ⊆ r. Then θ(q ′ ) ⊆ r′ , and we may conclude that each repair of db0 satisfies q ′ . ◀

D.2

Second Condition

▶ Lemma 40 (Normality, Item 2). Let C be the set of pairs (db, q), where q is a saturated query from sjfBCQU,A such that it satisfies Item 1 of Definition 17, and db is a q-saturated database. Then for each F ∈ q such that y → z ∈ Kc (q), for some distinct variables y, z ∈ NonKeyVars(F ), (db, q) 7→ RemoveF,z (db, q) is a strict, size-monotone, SCC-monotone, equivalence-preserving, polynomial-time reduction from C to C ∪ {true, false}. Proof. Let us assume that F is of the form T (x, y, z, ⃗v ) ∈ q, in which case F −z takes the form T (x, y, ⃗v ). Let db0 be the database obtained by dropping the column of T db corresponding to z, in the style of (7). Given an atom I ∈ q, let us write I ′ for its corresponding atom in q ′ ; that is, I ′ = I when I ∈ q \ {F }, while F ′ = F −z . Assume (db′ , q ′ ) = RemoveF,z (db, q) ∈ / {true, false}. Now, RemoveF,z is SCC-monotone due to Lemma 29. Moreover, that it is size-monotone and strict is clear by construction. Using Lemma 9, the reduction is in polynomial time. It remains to prove that it is equivalencepreserving and that (db′ , q ′ ) ∈ C. Membership of (db′ , q ′ ) in C. Now, db′ is q ′ -saturated by Lemma 9. It is also straighforward to verify that q ′ satisfies Item 1 of normality. Consider then the following claim. ▷ Claim 41. q ′ ∈ sjfBCQU,A . Proof. Clearly, q ′ remains variable-repetition-free. q′

q

For acyclicity of the attack graph over q ′ , it suffices to show that G′ ⇝ H ′ entails G ⇝ H for q′

all G′ , H ′ ∈ q ′ . Now, G′ ⇝ H ′ means that Gaifman(q ′ ) has a path U between some variables +,q ′ u ∈ NonKeyVars(G′ ) and v ∈ Vars(H ′ ) that is not separated by (G′ ) . Since every edge ′ in Gaifman(q ) belongs also to Gaifman(q), the same path exists in Gaifman(q) (between +,q ′ u ∈ NonKeyVars(G) and v ∈ Vars(H)). Moreover, it is easy to verify that G+,q ⊆ (G′ ) . q Thus no variable on U belongs to G+,q either. This yields G ⇝ H as required. ◁

32

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

To conclude that (db′ , q ′ ) ∈ C, it remains to prove the following claim. ▷ Claim 42. q ′ is saturated. Proof. Let F ∈ q be such that u → v ∈ K(F ′ ), v → w ∈ Kc (q ′ ), and u → w ∈ K∗ (q ′ \ {F ′ }). We need to show that u → w ∈ Kc (q ′ ). Clearly, we have u → v ∈ K(F ), v → w ∈ Kc (q), and u → w ∈ K∗ (q \ {F }), hence saturation of q yields u → w ∈ Kc (q). If follows by construction that u → w ∈ Kc (q ′ ) whenever u → w is different from y → z. The case where u → w equals y → z is not possible because by |NonKeyVars(F )| > 1 and Item 1 of normality for q we obtain y → z ∈ / Kc (q). ◁ (Equivalence-preservation) It suffices to prove that (db, q) ∈ CERTAINTY if and only if (db0 , q ′ ) ∈ CERTAINTY. First, suppose every repair of db0 satisfies q ′ . Let r be a repair of db. Let r′ be obtained from ⃗ with T ′ (a, b, d). ⃗ Clearly r′ is a repair of db0 . By assumption r by replacing each T (a, b, c, d) ′ ′ r satisfies q . Let θ be a valuation such that θ(q ′ ) ⊆ r′ . Then T ′ (θ(x), θ(y), θ(⃗v )) ∈ r′ . Note that z ∈ Vars(q ′ ). We claim that T (θ(x), θ(y), θ(z), θ(⃗v )) ∈ r. Since y → z ∈ Kc (q \ {F }), there exists an atom of the form R(y, z, −) ∈ q \ {F }. By definition, there exists a fact of the form T (θ(x), θ(y), c, θ(⃗v )) in r. As db is q-saturated (in particular, it satisfies pairwise consistency), there exists a constant c∗ such that R(θ(y), c∗ , −) ∈ db. By functional consistency, this constant is unique, meaning that R(θ(y), c∗ , −) ∈ r′ , hence θ(z) = c∗ . Since db is q-saturated (collision consistency), it follows that c = c∗ . It can now be seen that θ(q) ⊆ r, and hence r satisfies q. Then, suppose every repair of db satisfies q. Let r′ be a repair of db0 . Let r be obtained ⃗ with an arbitrary fact of the form T (a, b, c, d) ⃗ ∈ db. It from r′ by replacing each T ′ (a, b, d) is clear that r is a repair of db. By assumption there is a valuation θ such that θ(q) ⊆ r. Clearly, also θ(q ′ ) ⊆ r′ . We conclude that r′ satisfies q ′ . ◀

D.3

Third Condition

To enforce the third condition of normality for a query q, we will identify variables x and y such that x → y, y → x ∈ Kc (q). This is done two steps. First, we simply replace x with y in q. Since such a process may include variable repetition, we then remove such repetitions. We describe these two steps in this section. Before doing so, we introduce some auxiliary lemmas.

D.3.1

Auxiliary Lemmas

▶ Lemma 43. Let q ∈ sjfBCQU , let x, y ∈ Vars(q), and let c be an arbitrary constant. Then the following statements hold: 1. #srcSCC(K(qx7→c )) ≤ #srcSCC(K(q)); 2. If x → y, y → x ∈ K(q), then #srcSCC(K(qx7→y )) = #srcSCC(K(q)). Proof. Let us denote by q ′ the query qx7→c in Item 1 and the query qx7→y in Item 2.

M. Hannula

(Item 1) Suppose #srcSCC(K(q ′ )) = n. Then we find vertices x1 , . . . , xn from source SCCs C1 , . . . , Cn of K(q ′ ). In particular, xi and xj are not mutually reachable in K(q ′ ), for i ̸= j. Moreover, x is not listed among of x1 , . . . , xn . We first show that the vertices x1 , . . . , xn are not mutually reachable in K(q). Toward contradiction, suppose K(q) has a simple path D = u, . . . , v, where u and v are two vertices listed in x1 , . . . , xn . Since v ∈ / ReachK(q′ ) (u), it is the case that x appears on D. This means we find a path from ⊥ to v in K(q ′ ). Since ⊥ has no incoming edges, and v appears on a source SCC, it follows that v = ⊥. But then K(q) has a non-empty path from u to ⊥, which contradicts the fact that ⊥ has no incoming edges in K(q). We conclude by contradiction that the vertices x1 , . . . , xn are not mutually reachable in K(q). Then we show that the vertices x1 , . . . , xn belong to source SCCs in K(q). Toward contradiction suppose this is not the case. Then for some vertex v listed in x1 , . . . , xn , there exists an edge u → v ∈ K(q) such that u ∈ / ReachK(q) (v). We claim first that u ∈ / ReachK(q′ ) (v). Toward contradiction, suppose D = v, . . . , u is a path in K(q ′ ). If D contains variables only, then it is also a path in K(q), a contradiction. Otherwise, D contains ⊥, in which case it follows that v = ⊥. But then the edge u → v contradicts the fact that ⊥ has no incoming edges in K(q). We conclude by contradiction that the claim holds. Since x = ̸ v, we obtain either u → v ∈ K(q ′ ) or ⊥ → v ∈ K(q ′ ). The latter case contradicts the fact that v belongs to a source SCC of K(q ′ ). Hence, the former case holds. It follows that u does not belong to a source SCC in K(q ′ ) either, a contradiction. We conclude by contradiction that x1 , . . . , xn belong to source SCCs in K(q). It follows that the vertices x1 , . . . , xn belong to distinct source SCCs in K(q) Hence #srcSCC(G) ≥ n, proving the claim. (Item 2) The graph K(qx7→y ) is obtained from K(q) by identifying x with y. Since x and y belong to the same SCC, the statement follows. ◀ ▶ Lemma 44. Let q be a saturated query from sjfBCQU , and let x, y ∈ Vars(q) be such that x → y, y → x ∈ Kc (q). Let q ′ := qx7→y . Write x′ = y, and u′ = u for u ∈ (Vars(q)\{x})∪{⊥}. Then, for u ∈ Vars(q) ∪ {⊥} and v ∈ Vars(q) it holds that u → v ∈ Kc (q) ⇐⇒ u′ → v ′ ∈ Kc (q ′ ). Proof. Since “⇒” is straightforward, we focus on “⇐”. For this, assume that u′ → v ′ ∈ Kc (q ′ ). Let us write F ′ to denote Fx7→y , for F ∈ q. Case 1: u = v = x. It holds by definition that x → x ∈ Kc (q). Case 2: u = x and v = ̸ x. Then u′ = y and v ′ = v, and the assumption is that y → v ∈ Kc (q ′ ). ′ ′ Let F ∈ q and G ∈ q ′ \ {F ′ } be such that y → v ∈ K(F ′ ) and y → v ∈ K∗ (G′ ). Note that also F ̸= G. Suppose first that x → v ∈ K(F ). If x → v ∈ K∗ (G), then x → v ∈ Kc (q). Otherwise, we have x → v ∈ / K∗ (G) which entails y → v ∈ K(G). Then, by x → y ∈ Kc (q) and G ̸= F we obtain that x → v ∈ K∗ (q \ {F }). Since v → v ∈ Kc (q) by definition, by the saturation of q we obtain x → v ∈ Kc (q).

33

34

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Suppose then that x → v ∈ / K(F ). Then we obtain y → v ∈ K(F ). If y → v ∈ K∗ (G), then we obtain that y → v ∈ Kc (q), and furthermore by saturation and x → y ∈ Kc (q) that x → v ∈ Kc (q). Otherwise, if y → v ∈ / K∗ (G), we obtain x → v ∈ K(G). In this case, we c obtain, by composing x → y ∈ K (q) and y → v ∈ K(q \ {G}) to obtain x → v ∈ K(q \ {G}), and using saturation with v → v ∈ Kc (q), that x → v ∈ Kc (q). Hence we conclude that u → v ∈ Kc (q). Case 3: u = ̸ x and v = x. Then u′ = u and v ′ = y, and the assumption is that u → y ∈ Kc (q ′ ). ′ Let F ∈ q and G ∈ q ′ \ {F ′ } be such that u → y ∈ K(F ′ ) and u → y ∈ K∗ (G′ ). Suppose first that u → x ∈ K(F ). If u → x ∈ K∗ (G), then u → x ∈ Kc (q). Otherwise, we have u → y ∈ K∗ (G) which entails that u → y ∈ K(G) or ⊥ → y ∈ K(G). In both cases, using saturation, G ̸= F , and y → x ∈ Kc (q) we obtain u → x ∈ Kc (q). Suppose then that u → x ∈ / K(F ). Then we have u → y ∈ K(F ). If u → y ∈ K∗ (G), then u → y ∈ Kc (q), in which case saturation and y → x ∈ Kc (q) leads to u → x ∈ Kc (q). Otherwise, if u → y ∈ / K∗ (G), we obtain u → x ∈ K∗ (G). Then, by saturation, G = ̸ F , and c y → x ∈ K (q) we obtain u → x ∈ Kc (q). Therefore u → v ∈ Kc (q) follows. Case 4: u ̸= x ̸= v. This case is clear, concluding the proof.

D.3.2

◀

Replacing Variables

Let q ∈ sjfBCQU,A be saturated, and let x, y ∈ Vars(q) be such that x → y, y → x ∈ Kc (q). Let q ′ := (qx7→y ). Let db be a q-saturated database. Since q is saturated and db is q-saturated, there exist an atoms of the form S(x, y, −), T (y, x, −) ∈ q such that S db and T db are consistent. For an atom R(v1 , v2 , . . . , vn ) ∈ q and a fact A = R(a1 , a2 , . . . , an ) ∈ db, define f (A) := R(a′1 , a′2 , . . . , a′n ) where ( a′i :=

ai

if vi ̸= x,

b

if vi = x and there exists a fact of the form S(ai , b, −) ∈ db.

Note that f (A) is well-defined by the q-saturation of db. We define Identifyx,y (db, q) := (db′ , q ′ ), where db′ := DBSaturate(f [db], q ′ ), and g[X] denotes the image of a function g on a set X as usual. Let sjfBCQ= U,A be defined otherwise as sjfBCQU,A , except that it includes also queries that are not variable-repetition-free. ▶ Lemma 45 (Normality, Item 3). Let C (resp. C = ) be the set of pairs (db, q), where q is a saturated query from sjfBCQU,A (resp. from sjfBCQ= U,A ) such that it satisfies Items 1 and 2 of Definition 17, and db is a q-saturated database. Then, for each distinct x, y ∈ Vars(q) with x → y, y → x ∈ Kc (q), (db, q) 7→ Identifyx,y (db, q) is a strict, size-monotone, SCCmonotone, equivalence-preserving, polynomial-time reduction from C to C = ∪ {true, false}.

M. Hannula

35

Proof. Let us write x′ := y, and u′ := u for u ∈ (Vars(q) \ {x}) ∪ {⊥}. Given an atom F ∈ q, let us write F ′ for its corresponding atom in q ′ , that is, F ′ = Fx7→y . By assumption there are atoms of the form S(x, y, −), T (y, x, −) ∈ q. SCC-monotonicity follows by Lemma 43, while size-monotonicity and strictness are clear. Moreover, the reduction is in polynomial time due to Lemma 9. It remains to prove that the reduction is equivalence-preserving while it maintains membership in C = ∪ {true, false}. Suppose (db′ , q ′ ) = Identifyx,y (db, q) ∈ / {true, false}. (Membership of (db′ , q ′ ) in C = ) We divide this into several claims. ▷ Claim 46. q ′ ∈ sjfBCQ= U,A . q′

q

Proof. It suffices to show that G′ ⇝ H ′ entails G ⇝ H for all G′ , H ′ ∈ q ′ . Assume q

′

G′ ⇝ H ′ . Then Gaifman(q ′ ) has a path U ′ = x′1 , . . . , x′n between NonKeyVars(G′ ) and +,q ′ Vars(H ′ ) that is not separated by (G′ ) . If x1 , . . . , xn is a path in Gaifman(q) between NonKeyVars(G) and Vars(H), define U := x1 , . . . , xn . Otherwise, by our assumption, for some i ∈ [2, n − 1] with xi = y it holds that {xi−1 , y} and {x, xi+1 } (or {xi−1 , x} and {y, xi+1 }) are edges in Gaifman(q); in this case, define U := x1 , . . . xi−1 , xi , x, xi+1 , xn (or U := x1 , . . . xi−1 , x, xi , xi+1 , xn ). Since x → y ∈ Kc (q), we obtain that U is a path in Gaifman(q) between NonKeyVars(G) and Vars(H). q

Toward contradiction, suppose G ̸⇝ H. Then u ∈ G+,q , for some u appearing in U . Since x → y ∈ Kc (q) and y appears in U , we may assume without loss of generality that u ̸= x. Now, if D = t, . . . , u is the directed graph witnessing this, then D := t′ , . . . , u′ is a directed +,q graph witnessing u′ ∈ (G′ ) . Since u′ appears in U ′ , this contradicts the fact that U ′ is ′ q +,q not separated by (G′ ) . Hence we conclude by contradiction that G ⇝ H. ◁ ▷ Claim 47. q ′ is saturated. Proof. Let F ′ ∈ q ′ be such that u′ → v ′ ∈ K(F ′ ), v ′ → w′ ∈ Kc (q ′ ), and u′ → w′ ∈ K∗ (q ′ \ {F ′ }). We need to show that u′ → w′ ∈ Kc (q ′ ). We may select u, v such that u → v ∈ K(F ). Then also v → w ∈ Kc (q) by Lemma 44. Furthermore, u′ → w′ ∈ K∗ (q ′ \ {F ′ }) together with x → y, y → x ∈ Kc (q) imply u → w ∈ K∗ (q \ {F }); in particular, for any two edges q → y, y → r ∈ K(q ′ \ {F ′ }), one of the following four possibilities holds: q → x, x → r ∈ K(q \ {F }), q → y, y → r ∈ K(q \ {F }), q → x, x → y, y → r ∈ K(q \ {F }), or q → y, y → x, x → r ∈ K(q \ {F }). Thus, since q is saturated, we obtain u → w ∈ Kc (q), hence u′ → w′ ∈ Kc (q ′ ) by Lemma 44. ◁ ▷ Claim 48. q ′ satisfies Items 1 and 2 of normality Proof. (Item 1) Suppose toward contradiction that u′ → v ′ ∈ Kc (q ′ ) where u′ = Key(F ′ ), v ′ ∈ NonKeyVars(F ′ ), while |NonKeyVars(F ′ )| > 1. Then Lemma 44 implies u → v ∈ Kc (q) where u = Key(F ) and v ∈ NonKeyVars(F ). Furthermore, it is clear that |NonKeyVars(F )| ≥ |NonKeyVars(F ′ )|. This contradicts the normality of q, hence Item 1 holds for q ′ . (Item 2) Suppose toward contradiction that u′ → v ′ ∈ Kc (q ′ ), for distinct u′ , v ′ ∈ NonKeyVars(F ′ ). Then Lemma 44 implies u → v ∈ Kc (q). Since u and v are clearly distinct, and u, v ∈ NonKeyVars(F ′ ), we obtain a contradiction with the normality of q, so Item 2 follows for q ′ . ◁

36

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

This concludes the proof of the membership of (db′ , q ′ ) in C = . (Equivalence-preservation) By Lemma 9, it suffices to prove (db, q) ∈ CERTAINTY if and only if (f [db], q ′ ) ∈ CERTAINTY. We first prove that f is injective. Suppose toward contradiction that f (A) = f (B) for some A= ̸ B from db. If A = R(a1 , a2 , . . . , an ) and B = R(b1 , b2 , . . . , bn ), where R(v1 , v2 , . . . , vn ) ∈ q, then for some i ∈ [n] we have vi = x, ai ̸= bi such that S(ai , c, −), S(bi , c, −) ∈ db for some c. By q-saturation it holds that one of T (c, ai , −) or T (c, bi , −) does not belong to db. However, this contradicts another criterion of q-saturation, pairwise consistency, which entails that any S-fact can be joined with some T -fact. From the contradiction, it follows that f is injective. By an analogous reasoning, if f (A) and f (B) are key-equal, then A and B are key-equal. Hence a subset db′ of db forms a block of db if and only if f [db′ ] forms a block of f [db]. (⇒) Suppose (db, q) ∈ CERTAINTY, and r′ be a repair of f [db]. Since f is injective, it has an inverse function f −1 : f [db] → db. Define r := f −1 [r′ ]. By our arguments above, r is a repair of db. By assumption there exists a valuation θ such that θ(q) ⊆ r. We claim that θ(q ′ ) ⊆ r′ . Indeed, using S(θ(x), θ(y), −) ∈ db, if θ(R) ∈ r, then θ(Rx7→y ) = f (θ(R)) ∈ f (r) = (f ◦ f −1 )[r′ ] = r′ . Hence the claim holds, leading to (f [db], q ′ ) ∈ CERTAINTY. (⇐) Suppose (f [db], q ′ ) ∈ CERTAINTY, and let r be a repair of db. Again, we see that f [r] is a repair of f [db], hence we find a valuation θ such that θ(q ′ ) ⊆ f [r]. In particular, since S(y, y, −) ∈ q ′ , we have S(θ(y), θ(y), −) ∈ f [r]. Now, consider the fact S(a, θ(y), −) = f −1 (S(θ(y), θ(y), −)) ∈ (f −1 ◦ f )[r] = r. Let θ′ be otherwise as θ, except that it maps x to a. Then, for any R ∈ q, we obtain θ′ (R) = f −1 (θ(Rx7→y )). Since θ(Rx7→y ) ∈ f [r], this leads to θ′ (R) ∈ (f −1 ◦ f )[r] = r. Hence θ′ (q) ⊆ r, leading to (db, q) ∈ CERTAINTY. ◀

D.3.3

Removing Repeated Variables

For an atom F = R(t1 , t2 , . . . , tn ), let F norep be obtained by deleting every argument position i such that ti is a variable and ti = tj for some j < i. Then, let q norep := {F norep | F ∈ q}. Also, given a database db and query q, let db0 be obtained from db by dropping those columns that correspond to the positions dropped in the reduction q 7→ q norep . (Formally, ∗norep changes also relation names when the arity changes.) Then, we set RemoveReps(db, q) := (db′ , q ′ ), where q ′ := q norep and db′ := DBSaturate(db0 , q ′ ). Recall the notion of the size-monotone reduction from Section C.1. ▶ Lemma 49. Let C (resp. C = ) be the set of pairs (db, q), where q is a query from sjfBCQU,A (resp. from sjfBCQ= U,A ), and db is a q-saturated database. Then (db, q) 7→ RemoveReps(db, q) is a size-monotone, SCC-monotone, equivalence-preserving, polynomialtime reduction from C = to C ∪ {true, false}. Additionally, if q is saturated and satisfies Items 1 and 2, then so does q ′ . Proof. We provide a sketch and leave the details to the reader. Since ∗norep only removes self-loops from K(q), the reduction is SCC-monotone. Clearly, it is also size-monotone and in polynomial time. Assume (db′ , q ′ ) = RemoveReps(db, q) ∈ / {true, false}. Clearly, q ′ is variable-repetition-free. Also, the attack graphs of q and q ′ are identical (modulo changes in the relation names).

M. Hannula

Algorithm 3 GetFunction(db, q)

Input : A pair (db, q), where q ∈ sjfBCQU,A and db is a q-saturated database Output : A function f : OutKc (q) (⊥) → adom(db) 1 foreach y ∈ OutKc (q) (⊥) do 2 Select the ≺-least atom of the form S(c, y, −) ∈ q, where c is a constant; 3 Set f (y) := b, where b is the unique constant such that S(c, b, −) ∈ db; 4

return f

That saturation and satisfaction of Items 1 and 2 is preserved is straightforward to verify. Moreover, db′ is q ′ -saturated by Lemma 9. Hence (db′ , q ′ ) belongs to C ∪ {true, false}. For equivalence-preservation, observe that due to q-saturation of db, any R-fact A ∈ db contains repeated constants in those positions where the corresponding R-atom of q contains repeated variables. Therefore, (db, q) ∈ CERTAINTY if and only if (db0 , q ′ ) ∈ CERTAINTY. It then follows by Lemma 9 that the reduction is equivalent-preserving. ◀

D.4

Fourth Condition and Substitutable Sets

This section proceeds in two steps. First, we provide some auxiliary concepts and lemmas. One such concept is that of a substitutable set of variables. Such a set can be replaced with constants in a way that is safe with respect to the overall reduction.

D.4.1

Auxiliary Concepts and Lemmas

We use the following result, which states that replacing a variable with a constant in a query (with composite primary keys) does not introduce cycles to the attack graph. ▶ Lemma 50 ([19, Lemma 3.7]). Let q ∈ sjfBCQA , let x ∈ Vars(q), and let c be an arbitrary constant. Then qx7→c ∈ sjfBCQA . The following lemma concerning edge preservation upon substitution is also needed. Note that we only replace sets of variables that are closed under the consistent edges of the key-nonkey graph. ▶ Lemma 51. Let q ∈ sjfBCQU,A be saturated. Let Y ⊆ Vars(q) be such that OutKc (q) (⊥) ⊆ Y and OutKc (q) (Y ) ⊆ Y , and let f : Y → Const be a function. Define q ′ := qf . Let u, v ∈ Vars(q) ∪ {⊥} be such that v ∈ / Y . Then 1. u → v ∈ K(q) implies u′ → v ∈ K(q ′ ); 2. u → v ∈ Ki (q) implies u′ → v ∈ Ki (q ′ ); 3. u → v ∈ Kc (q) if and only if u′ → v ∈ Kc (q ′ ); where u′ := ⊥ if u ∈ Y , and otherwise u′ := u. Consequently, if additionally u ∈ / Y , then u → v ∈ Kc (q) if and only if u → v ∈ Kc (q ′ ). Proof. Item 1 is clear, and Item 2 follows from Items 1 and 3. Thus, we prove the last item. Let us write F ′ for the atom FY 7→f (Y ) , for each F ∈ q. (⇒) Suppose u → v ∈ Kc (q). Then we find F ∈ q and G ∈ q \ {F } such that u → v ∈ K(F ) and u → v ∈ K∗ (G). Clearly, u′ → v ∈ K(F ′ ) and u′ → v ∈ K∗ (G′ ). Hence u′ → v ∈ Kc (q ′ ).

37

38

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

(⇐) Suppose u′ → v ∈ Kc (q ′ ). Then, there exists F ′ ∈ q such that u′ → v ∈ K(F ′ ) and G′ ∈ q ′ \ {F ′ } such that u′ → v ∈ K∗ (G′ ). Consequently, there exists p such that p → v ∈ K(F ) and p′ = u′ . In particular, it holds that p′ → v ∈ K∗ (G′ ). Suppose toward contradiction that p ∈ Y . Since OutKc (q) (Y ) ⊆ Y and v ∈ / Y , we obtain p → v ∈ Ki (q). If p → v ∈ K∗ (G), we obtain p → v ∈ Kc (q), a contradiction. Thus, p→v∈ / K∗ (G), which entails y → v ∈ K(G) for some y ∈ Y such that y ̸= p. But then, y → v ∈ Ki (q), as otherwise by OutKc (q) (Y ) ⊆ Y we would obtain v ∈ Y , a contradiction. However, since p = ̸ y, we obtain then a contradiction with Lemma 16. Hence we conclude that p ∈ / Y. Assume toward contradiction that p = ⊥. Then also u′ = p′ = ⊥. Thus, we obtain either ⊥ → v ∈ K(G) or, for some y ∈ Y , y → v ∈ K(G). Since ⊥ → v ∈ K(F ), both contradict v∈ / Y , OutKc (q) (⊥) ⊆ Y , and OutKc (q) (Y ) ⊆ Y . Hence p ̸= ⊥. It follows that p is a variable not from Y . Consequently, p = p′ = u′ = u, hence u → v ∈ K(F ). If u → v ∈ K∗ (G), then u → v ∈ Kc (q), as required. Otherwise, if u → v ∈ / K∗ (G), we obtain y → v ∈ K(G), for some y ∈ Y . Since v ∈ / Y and OutKc (q) (Y ) ⊆ Y , we obtain y → v ∈ Ki (G). Then, as u ̸= y, Lemma 16 implies u → v ∈ Kc (q), as required. ◀ ▶ Definition 52 (Substitutable Sets). Let q ∈ sjfBCQU,A be saturated query such that it satisfies Items 1–3 of Definition 17. We say that Y ⊆ Vars(q) is substitutable if 1. Y ̸= ∅; 2. OutKc (q) (⊥) ⊆ Y and OutKc (q) (Y ) ⊆ Y ; 3. either of the following holds (i) Y = {y}, where y is not attacked in the attack graph of q, or S (ii) Y = {NonKeyVars(H) | H ∈ q0 , Key(H) = ⊥}, for some q0 ⊆ q. Given an instance (db, q), a substitutable set Y ⊆ Vars(q), and a substitution f : Y → adom(db), define Substitutef (db, q) := (DBSaturate(db, qf ), qf ).

(8)

▶ Lemma 53. Let q ∈ sjfBCQU,A be saturated query such that it satisfies Items 1–3 of Definition 17. If OutKc (q) (⊥) is non-empty, then it is substitutable. Proof. Let us write Y := OutKc (q) (⊥). Considering Item 2 of Definition 52, for any z ∈ OutKc (q) (Y ) there exists y ∈ Y such that y → z ∈ Kc (q). Furthermore, ⊥ → y ∈ Kc (q). By saturation it follows then that ⊥ → z ∈ Kc (q), i.e., z ∈ Y . Hence OutKc (q) (Y ) ⊆ Y . Considering Item 3, Item 1 of Definition 17 implies that each ⊥ → y ∈ Kc (q) is witnessed by an atom Fy ∈ q such that Key(Fy ) = ⊥ and NonKeyVars(Fy ) = {y}. We can then define q0 := {Fy | y ∈ Y } to obtain Item (ii). Hence, OutKc (q) (⊥) is substitutable whenever it is non-empty.

◀

M. Hannula

D.4.2

Substituting Constants for Variables

We can now consider the fourth normalization condition, which stipulates that the special vertex ⊥ has no outgoing consistent edges. The following lemma, especially its first item, is used to replace the target variables of such edges with constants. Additionally, the second item is used later when variables are replaced with constants in the alternating computation that follows the rewriting strategy; there, equivalence-preservation is not needed. ▶ Lemma 54 (Normality, Item 4). Let C be the set of pairs (db, q), where q is a saturated query from sjfBCQU,A such that it satisfies Items 1–3 of Definition 17, and db is a q-saturated database. Then, for each (db, q) ∈ C, substitutable Y ⊆ Vars(q), and function f : Y → Const, (db, q) 7→ Substitutef (db, q) is a strict, size-monotone, SCC-monotone, polynomial-time reduction from C to C ∪ {true, false}. Additionally, the following claims hold: 1. If f := GetFunction(db, q), then Substitutef is equivalence-preserving, 2. The statement remains true if Item 4 of Definition 17 is additionally assumed for the queries q with (db, q) ∈ C. Proof. Given an atom F ∈ q, let us write F ′ for its corresponding atom in q ′ , that is, F ′ = FY 7→f (Y ) . Strictness follows by non-emptiness of Y and SCC-monotonicity by Lemma 43. Moreover, the reduction is clearly size-monotone, and it is in polynomial time due to Lemma 9. It remains to prove the additional statements and the claim that the reduction is into C ∪ {true, false}. For this, suppose (db′ , q ′ ) = Substitutef (db, q) ∈ / {true, false}. (Membership of (db′ , q ′ ) in C) First, observe that db′ is q ′ -saturated by Lemma 9. Also, it is clear that q ′ remains variable-repetition-free, hence by Lemma 50 we obtain q ′ ∈ sjfBCQU,A . We divide the remaining parts into several claims. ▷ Claim 55. q ′ is saturated. Proof. Let F ∈ q be such that u → v ∈ K(F ′ ), v → w ∈ Kc (q ′ ), and u → w ∈ K∗ (q ′ \ {F ′ }). We need to show that u → w ∈ Kc (q ′ ). We observe that u is a variable or ⊥, and v, w are variables. Since Y ∩ (Vars(q ′ ) ∪ {⊥}) = ∅, we have u, v, w ∈ / Y. ▷ Claim 56. v → w ∈ Kc (q). Proof. By v → w ∈ Kc (q ′ ) we find F ′ ∈ q ′ and G′ ∈ q ′ \ {F ′ } such that v → w ∈ K(F ′ ) and v → w ∈ K∗ (G′ ). Clearly, v → w ∈ K(F ), and if additionally v → w ∈ K∗ (G), then the claim follows. Otherwise, if v → w ∈ / K∗ (G), we find y ∈ Y such that y → w ∈ K(G), ′ leading to ⊥ → w ∈ K(G ) and furthermore to v → w ∈ K∗ (G′ ). However, since Y is closed under the edges of Kc (q), and w ∈ / Y , we obtain y → w ∈ Ki (q). Since v ∈ / Y , we have v = ̸ y. Hence, by Lemma 16, it follows that v → w ∈ Kc (q), which was our claim. ◁ Let u′ = Key(F ). Then u′ → v ∈ K(F ), and u′ ̸= u if and only if u′ ∈ Y . In what follows, we prove that u′ ∈ / Y . Toward this, we first prove the following claim. ▷ Claim 57. u′ → w ∈ K∗ (q \ {F }).

39

40

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Proof. Let D = (x1 , . . . , xn−1 , w) be a simple path witnessing u → w ∈ K∗ (q ′ \ {F ′ }). In particular, we have that x1 = u or x1 = ⊥ (or both). Since both u and ⊥ are not from Y , also x1 is not from Y . Since the remaining elements of Y are variables from Vars(q ′ ), they are not from Y either. Hence the suffix D[x2 , w] belongs to K(q \ {F }). Consider the atom G′ ∈ q ′ \ {F ′ } such that x1 → x2 ∈ K(G′ ). If Key(G) ∈ / Y , then x1 → x2 ∈ K(G), i.e., x1 → x2 ∈ K(q \ {F }), and consequently, it can be confirmed that u′ → w ∈ K∗ (q \ {F }), as required Thus, suppose Key(G) = y ∈ Y . Then y → x2 ∈ K(q \ {F }), and in particular, D′ := (y, x2 , . . . , xn−1 , w) is a simple path witnessing y → w ∈ K∗ (q \ {F }). q

We claim that F ̸⇝ y. In the case of Item (i) this is immediate. In the case of Item (ii), we find H ∈ q such that y ∈ NonKeyVars(H) ⊆ Y and Key(H) = ⊥. We observe F ̸= H because K(F ′ ) is non-empty but K(H ′ ) is empty. Since Key(H) = ⊥, we have y ∈ F +,q , q

q

hence F ̸⇝ y. Thus the claim that F ̸⇝ y holds. q

q

q

Next, we claim that F ̸⇝ w. Toward contradiction, suppose F ⇝ w. Then, since F ̸⇝ y and q F ⇝ w, we obtain that y and w are separated by F +,q . In particular, as D′ is also a path in Gaifman(q), some element of D′ belongs to F +,q . Consequently, w belongs to F +,q , as D′ is q a path in K(q \ {F }). This, however, contradicts F ⇝ w, so the claim follows. Now, {v, w} is an undirected (possibly singleton) edge generated by v → w ∈ Kc (q), and q

also we have u′ → v ∈ K(F ). Therefore, we obtain from F ̸⇝ w that one of v or w belongs to F +,q . Moreover, if v belongs to this set, then by Kc (q) ⊆ K(q \ {F }) also so does w. We conclude that w ∈ F +,q , which is tantamount to the claim that u′ → w ∈ K∗ (q \ {F }). This concludes the proof of the claim.

◁

From u′ → v ∈ K(F ), v → w ∈ Kc (q), and u′ → w ∈ K∗ (q \ {F }), we obtain by saturation of q that u′ → w ∈ Kc (q). By the same token u′ is a variable. It follows that u′ ∈ / Y , because w ∈ / Y and Y is closed under Kc (q). Hence u = u′ , and ′ c therefore by u → w ∈ K (q) we obtain u → w ∈ Kc (q). Since u, w ∈ / Y , it follows by c ′ Lemma 51 that u → w ∈ K (q ), as required. This concludes the proof of Claim 55. ◁ ▷ Claim 58. q ′ satisfies Items 1–3 of Definition 17. Proof. Note that we cannot assume Item 4 of normality for q in the proof. (Item 1) Let F ′ ∈ q ′ be such that |NonKeyVars(F ′ )| > 1. Let p = Key(F ′ ). We need to show that p → v ∈ Ki (q ′ ), for each v ∈ NonKeyVars(F ′ ). Suppose toward contradiction that p → v ∈ Kc (q ′ ) for some v ∈ NonKeyVars(F ′ ). Note that in this case v ∈ / Y . Then we find G′ ∈ q ′ \ {F ′ } such that p → v ∈ K∗ (G′ ). Note that NonKeyVars(F ′ ) ⊆ NonKeyVars(F ), i.e., |NonKeyVars(F )| > 1. Furthermore, we clearly have v ∈ NonKeyVars(F ). We claim that p = ⊥. Toward contradiction, suppose p is a variable. Then p = Key(F ), and p → v ∈ K∗ (G), leading to p → v ∈ Kc (q), which contradicts Item 1 of normality for q. Thus p = ⊥. This entails Key(F ) ∈ Y ∪ {⊥} and Key(G) ∈ Y ∪ {⊥}.

M. Hannula

If Key(G) = ⊥, then Key(F ) → v ∈ Kc (q), a contradiction with Item 1 of normality for q. Suppose then Key(G) = y ∈ Y . If Key(F ) = y, we obtain a contradiction with Item 1 as above. Thus suppose Key(F ) ̸= y. Then Lemma 16 entails Key(F ) → v ∈ Kc (q) or y → v ∈ Kc (q). The former case contradicts normality of q, and the latter case is not possible due to v ∈ / Y. Thus, by contradiction, we obtain p → v ∈ Ki (q ′ ), for each v ∈ NonKeyVars(F ′ ). (Item 2) Assume toward contradiction that u → v ∈ Kc (q ′ ), for some distinct u, v ∈ NonKeyVars(F ′ ) and F ′ ∈ q ′ . Then u, v ∈ NonKeyVars(F ) where F ∈ q. Clearly we have u → v ∈ K(q). Denote p = Key(F ), in which case we have p → v ∈ K(F ). Since q satisfies Item 1 of normality, and |NonKeyVars(F )| > 1, it follows that p → v ∈ Ki (F ). Hence, by Lemma 16, and since p ̸= u (as q is variable-repetition-free), it cannot be the case that u → v ∈ Ki (q). Therefore, u → v ∈ Kc (q), but this contradicts Item 2 of normality for q. Thus the assumption is false, and Item 2 follows. (Item 3) Assume toward contradiction that u → v ∈ Kc (q ′ ) and v → u ∈ Kc (q ′ ), for two distinct variables u, v ∈ Vars(q ′ ). Then Lemma 51 implies u → v ∈ Kc (q) and v → u ∈ Kc (q), in contradiction with Item 3 of normality for q. ◁ In the following, we consider the additional statements. (Item 1) Fix f := GetFunction(db, q). Since db is q-saturated, we have that if θ is a valuation such that θ(q) ⊆ db, then θ↾Y = f . Hence, (db, q) 7→ (db, qf ) is equivalencepreserving. Since equivalence-preservation holds for database saturation and is preserved under composition, (db, q) 7→ Substitutef (db, q) is equivalence-preserving. (Item 2) Assume toward contradiction that ⊥ → v ∈ Kc (q ′ ) for some v ∈ Vars(q ′ ). Let F ′ , G′ ∈ q ′ be such that ⊥ → v ∈ K(F ′ )∩K(G′ ). Since q satisfies Item 4 of normality, we have ⊥→v∈ / K(F ) ∩ K(G). Thus Key(F ) ∈ Y or Key(G) ∈ Y . By symmetry, we may assume that Key(F ) = y ∈ Y . If Key(G) ∈ {⊥, y}, we obtain y → v ∈ Kc (q), which leads to v ∈ Y by Item 2 of Definition 52, a contradiction with v ∈ Vars(q ′ ). Since Key(G) ⊆ {⊥} ∪ Y , we may conclude that Key(G) = y ′ ∈ Y \ {y}. Summarizing, we have that y → v, y ′ → v ∈ K(q), where y = ̸ y ′ . By Lemma 16 it follows that y → v ∈ Kc (q) or y ′ → v ∈ Kc (q), which again leads to to v ∈ Y , a contradiction. We conclude by contradiction that ⊥ → v ∈ / Kc (q ′ ) for each v ∈ Vars(q ′ ). Hence Item 4 holds. ◀

D.5

Normalization Step

We can now compose all the individual normalization steps into one lemma. Note that Normalize is the function described in Algorithm 4. ▶ Lemma 19 (Normalization Lemma). Let C be the set of pairs (db, q), where q is a saturated query from sjfBCQU,A and db is a q-saturated database. Then Normalize is an equivalencepreserving, SCC-monotone, polynomial-time reduction from C to C∪{true, false}. Additionally, for each (db, q), assuming (db′ , q ′ ) = Normalize(db, q) ∈ / {true, false}, we have that q ′ is normal. Proof. The equivalence preservation and SCC-monotonicity follow from Proposition 37 and from exhaustively applying the reductions of Lemmas 38, 40, 45, and 54 sequentially in this order, as described in Algorithm 4. (After Lemma 45, note that Lemma 49 is applied to remove variable repetitions.) The lemmas also guarantee that the output query q ′ is normal and from C. It remains to show that the computation runs in polynomial time.

41

42

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Because the size of the query shrinks at each iteration (due to strictness of each reduction used in the lemmas), the total number of iterations is at most ||q||. Moreover, the size of the database does not increase at any iteration (due to size-monotonizity of each reduction). By the lemmas, each iteration is in polynomial time over the temporary input, so each iteration is in polynomial time over the input. Hence, the overall computation is in polynomial time. From these considerations, it can be seen that the lemma statement holds.

◀

Algorithm 4 Normalize(db, q)

Input : A saturated database db and a saturated query q ∈ sjfBCQA . Output : false or (db′ , q ′ ), where db′ is a saturated database and q a saturated and normal query from sjfBCQA . 1 while some F ∈ q, y ∈ NonKeyVars(F ) witness that Item 1 of normality is false for q do 2 (db, q) ← Try(RemoveF,y (db, q)); // Lemma 38 3 4

while some F ∈ q, y ∈ NonKeyVars(F ) witness that Item 2 of normality is false for q do (db, q) ← Try(RemoveF,y (db, q)); // Lemma 40

while some x, y ∈ Vars(q) witness that Item 3 of normality is false for q do (db, q) ← Try(Identifyx,y (db, q)); // Lemma 45 7 (db, q) ← Try(RemoveReps(db, q)); // Lemma 49

5

6

while Item 4 of normality is false for q do f ← GetFunction(db, q); // Lemma 53 entails the assumptions for Lemma 54 w.r.t. Y := OutKc (q) (⊥) 10 (db, q) ← Try(Substitutef (db, q)); // Lemma 54 8

9

11

return (db, q);

D.6

Basic Properties of Saturated and Normal Queries

After the preprocessing stage, the query q is saturated and normal, and the acyclicity of its attack graph has been preserved. In this section, we consider some basic properties of such queries. We say that two (not necessarily distinct) variables x and y are siblings (w.r.t. q), denoted x ∼q y (or x ∼ y if q is understood) if there exists an atom F ∈ q such that x and y are both in NonKeyVars(F ). ▶ Lemma 59. Let q ∈ sjfBCQU,A be saturated and normal. If x → y, u → v ∈ Ki (q), where y ∼ v, then x = u. Proof. The case where y = v is covered by Lemma 16. Consider then the case where y = ̸ v (see Figure 4). Suppose x → y, u → v ∈ Ki (q) and y ∼ v. Let F ∈ q be such that y, v ∈ NonKeyVars(F ). Let w = Key(F ). By normality of q, we have w → y, w → v ∈ Ki (q). By Lemma 16, we obtain x = w = u. ◀

M. Hannula

43

y

y

v

v

=⇒ x

x

u

(= u)

Figure 4 Illustration for Lemma 59

y

v

y

v

x

u

=⇒ x

u

Figure 5 Illustration for Lemma 62.

▶ Lemma 60. Let q ∈ sjfBCQU,A be saturated and normal. Suppose x → y ∈ Ki (q), y → z ∈ Kc (q), and x → z ∈ / Kc (q). If F ∈ q is the atom generating x → y, then F ⇝ z. Proof. The case where y = z is covered by Lemma 15. Thus, we have y ̸= z. It follows that y and z cannot be siblings, because otherwise we obtain a contradiction with the normality of q. Suppose toward contradiction that F ̸⇝ z. Since F ⇝ y by Lemma 15, we obtain x→y∈ / K∗ (q \ {F }). As {y, z} is an edge in Gaifman(q), we obtain x → z ∈ K∗ (q \ {F }). By saturation we obtain x → z ∈ Kc (q), which contradicts the assumption. Hence F ⇝ z. ◀ ▶ Lemma 61. Let q ∈ sjfBCQU,A be saturated and normal. Let D = x1 , . . . , xn be a path of K(q) such that x1 = x, xn = y, and x1 → x2 ∈ Ki (q). Assume that D is shortest among all paths from x1 to xn in K(q). Then xn ∈ ReachK⇝ (q) (x1 ). Proof. By Lemma 14, the path D does not contain two consecutive edges from Kc (q). By definition, then, any edge u → v ∈ Kc (q) that appears on D is preceded by an edge w → u such that w → v ∈ / Kc (q), meaning that u → v ∈ K⇝ (q). The statement of the lemma follows from these observations. ◀ ▶ Lemma 62. Let q ∈ sjfBCQU,A be saturated and normal. Suppose x → y, u → v ∈ Ki (q) and y → v ∈ Kc (q) where y ̸= v. Then x → v belongs to Kc (q). Proof. Note that y ̸= u by u → v ∈ Ki (q) and y → v ∈ Kc (q). We first prove that x = ̸ u. Toward contradiction, suppose x = u. Then we have x = ̸ y (by i c y ̸= u) and x → y, x → v ∈ K (q) and y → v ∈ K (q). Suppose first that there exists a single atom F ∈ q such that y, v ∈ NonKeyVars(F ). Since y = ̸ v, this contradicts normality of q (specifically, Item 2). Then, suppose there exists two distinct F, G ∈ q such that x → y ∈ K(F ) and x → v ∈ K(G). In this case, as y → v ∈ Kc (q), the saturation of q implies x → v ∈ Kc (q), a contradiction. We conclude by contradiction that x ̸= u (see Figure 5). Let F ∈ q be the atom generating u → v. Since y → v ∈ Kc (q), there is an edge {y, v} in Gaifman(q). By Lemma 15, F attacks v, and hence u → v ∈ / K∗ (q \ {F }). By c ∗ y → v ∈ K (q) ⊆ K(q \ {F }) we also observe that u → y ∈ / K (q \ {F }). In particular, {y, v} is not separated by F +,q . If G is the atom generating x → y, we thus obtain F ⇝ G. By acyclicity of the attack graph, we have G ̸⇝ F . By Lemma 15, G attacks y, and hence

44

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

z

z

y

v

x

u

=⇒

z

y

v

x

u

or

y

v

x

u

z

z

y

v

x

u

=⇒

y

v

x

(= u)

Figure 6 Illustration for Lemma 63.

x→y∈ / K∗ (q \ {G}). However, due to the edge {y, v} in Gaifman(q), and since v ∈ Vars(F ), it must be the case x → v ∈ K∗ (q \ {G}). Since x → y ∈ K(G), y → v ∈ Kc (q), it follows by saturation that x → v ∈ Kc (q). ◀ ▶ Lemma 63. Let q ∈ sjfBCQU,A be saturated and normal. Let x → y, u → v ∈ Ki (q) and y → z, v → z ∈ Kc (q). Then one of the following holds: x = u and y ∼ v, x → z ∈ Kc (q), y → z ∈ Kc (q). Proof. Note that y ∼ v implies x = u by Lemma 59 (see Figure 6). Thus, suppose y ̸∼ v. It is possible that y = z or z = v (but not both). Then, by Lemma 62, we obtain that x → z or y → z is in Kc (q), respectively. Thus we may assume that y ̸= z and z ̸= v. By the assumption we find atoms of the form F := R(x, y, −), G := R′ (u, v, −), H := S(y, z, −), I := S ′ (v, z, −) ∈ q. (Note that possibly x = ⊥ or y = ⊥; these cases are treated analogously.) Since y ̸∼ v, we have F ̸= G. In particular, y, z, v is a path in Gaifman(q) connecting NonKeyVars(F ) and NonKeyVars(G). Since the attack graph of q is acyclic, one of F or G does not attack the other. By symmetry, we may assume F does not attack G. Since F ⇝ y by Lemma 15, it follows that at least one of z or v belongs to F +,q . In fact, we obtain z ∈ F +,q , because this is implied by v ∈ F +,q and v → z ∈ Kc (q). Thus we have x → z ∈ K∗ (q \ {F }), x → y ∈ K(F ), and y → z ∈ Kc (q). By the saturation of q, this leads to x → z ∈ Kc (q), showing the statement of the lemma. ◀ The following lemma is a consequence of Lemma 62 and the definition of K⇝ (q) (Definition 20).

M. Hannula

45

▶ Lemma 64. Let q ∈ sjfBCQA be saturated and normal. The following statements hold: 1. If x → y and y → z are in K⇝ (q), then one of them belongs to Ki (q). 2. If x → y is in K⇝ (q) and x ∈ RootVars⇝ (q), then x → y is in Ki (q). Proof. (Item 1) Toward contradiction, suppose both x → y and y → z belong to Kc (q). Then we find edges of the form x0 → x, y0 → y from Ki (q). Since x = ̸ y, it follows by Lemma 62 that x0 → y ∈ Kc (q), a contradiction with x → y being in K⇝ (q). (Item 2) If x → y is in K⇝ (q) ∩ Kc (q), then by definition it has an incoming edge in Ki (q), and thus in K⇝ (q). ◀ ▶ Lemma 65. If q ∈ sjfBCQU,A is saturated and normal, then K⇝ (q) is acyclic. Proof. By Lemma 64 a cycle in K⇝ (q) would contain at least one edge from Ki (q), and no two consecutive edges from Kc (q). Then, by Lemmas 15 and 60, each atom generating an edge in Ki (q) in this cycle would attack the atom generating the next edge in Ki (q). This contradicts the acyclicity of the attack graph. Hence K⇝ (q) is acyclic. ◀ ▶ Lemma 66. Let q ∈ sjfBCQU,A be saturated and normal. Suppose x is connected to y by a path in K⇝ (q) that is of length at least 2. Then x → y ∈ / K(q). Proof. By Lemma 65, we have that x = ̸ y. Moreover, x → y ∈ / Ki (q) by Lemmas 16 and 65. Assume toward contradiction that x → y ∈ Kc (q). By normality of q, we observe that x is a variable (and not ⊥). Let D = x, . . . , y0 , y be the path of K⇝ (q) as in the assumption. We have x ̸= y0 ; otherwise, K⇝ (q) has a cycle in contradiction with Lemma 65. We consider two different possibilities. First, suppose y0 → y ∈ Ki (q). Let F ∈ q be (the unique) atom generating y0 → y. Then F ⇝ y by Lemma 15. In particular, y ∈ / F +,q , and consequently, by x → y ∈ c +,q K (q) ⊆ K(q \ {F }), it holds that x ∈ / F . Since Gaifman(q) has an edge {x, y}, we obtain F ⇝ x. Since x ̸= y0 , there exists an atom G ∈ q \ {F } with x = Key(G) such that some x0 ∈ NonKeyVars(G) is connected to y0 in K⇝ (q) (possibly by the empty path). We obtain + that F ⇝ G and by Lemmas 15, 21, and 64 that G ⇝ F , contradicting the acyclicity of the attack graph. Then, suppose y0 → y ∈ Kc (q). By definition, there exists an edge of the form z → y0 ∈ Ki (q). Let F ∈ q be (the unique) atom generating z → y0 . Since y0 → y belongs to both Kc (q) and K⇝ (q), it follows that z → y ∈ / Kc (q). In particular, this entails z = ̸ y. Moreover, by saturation of q, we obtain z → y ∈ / K∗ (q \ {F }), i.e., y ∈ / F +,q . Hence, x ∈ / F +,q by c x → y ∈ K (q). Since F ⇝ y by Lemma 21, this leads to F ⇝ x, similarly to above. Specifically, x = ̸ z as a consequence. Again, we find an atom G ∈ q \ {F } with x = Key(G) such that some x0 ∈ NonKeyVars(G) is connected to y0 in K⇝ (q). As above, we obtain + F ⇝ G and G ⇝ F , a contradiction. Hence x → y ∈ / Kc (q). Concluding, we have established that x → y ∈ / K(q).

◀

▶ Lemma 67. Let q ∈ sjfBCQU,A be saturated and normal. If u → v ∈ K(q), v → w ∈ Kc (q) \ K⇝ (q), and v ̸= w, then u → w ∈ Kc (q).

46

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Proof. If u → v ∈ Kc (q), then v → w ∈ Kc (q) implies u → w ∈ Kc (q) by Lemma 14. Thus, suppose u → v ∈ Ki (q). Since v → w ∈ Kc (q) and v = ̸ w, we have that v → w ∈ K(q). Then, by definition, u → w ∈ Kc (q). ◀ ▶ Lemma 68. Let q ∈ sjfBCQU,A be saturated and normal. If u → v, v → w ∈ K(q) and v ∈ LeafVars⇝ (q), then u → w ∈ Kc (q). Proof. It follows by the assumption that v → w ∈ Kc (q) \ K⇝ (q). Moreover, v ̸= w since q is variable-repetition-free. Hence, Lemma 67 entails u → w ∈ Kc (q). ◀ ▶ Lemma 69. Let q ∈ sjfBCQU,A be saturated and normal. Then the following statements hold: 1. If x → z, y → z ∈ K⇝ (q) and x ̸= y, then x → z, y → z ∈ Kc (q), where x and y are variables such that x ∼ y; 2. If x → y, x′ → z ∈ K⇝ (q), y ̸= z, and y ∼ z, then x → y, x′ → z ∈ Ki (q) and x = x′ . Consequently, if x → y, x′ → y ′ ∈ K⇝ (q) and y ∼ y ′ , then x ∼ x′ . Proof. (Item 1) By Lemma 15, it cannot be the case that both x → z and y → z belong to Ki (q). Hence one of x → z and y → z belongs to Kc (q). By symmetry, we may assume that x → z ∈ Kc (q). We claim that this entails, y → z ∈ Kc (q). First, observe x → z ∈ Kc (q) entails x0 → x ∈ Ki (q) for some x0 ∈ Vars(q) ∪ {⊥}. Then, y → z ∈ Ki (q) is not possible, because in such a case by x ̸= z and Lemma 62 we would obtain x0 → z ∈ Kc (q), contradicting the assumption that x → z ∈ K⇝ (q). Therefore, it follows that y → z ∈ Kc (q). Now, y → z ∈ Kc (q) ∩ K⇝ (q) implies y0 → y ∈ Ki (q) for some y0 ∈ Vars(q) ∪ {⊥}. From x → z, y → z ∈ K⇝ (q) we obtain x0 → z, y0 → z ∈ / Kc (q). Hence, by Lemma 63, we obtain also x ∼ y, as required. In particular, x and y are variables. (Item 2) Suppose x → y, x′ → z ∈ K⇝ (q), y ̸= z, and y ∼ z. Let F ∈ q be such that y, z ∈ NonKeyVars(F ). By normality of q, we have u → y, u → z ∈ Ki (q) ⊆ K⇝ (q), where u := Key(F ). By Item 1, it holds that x = u = x′ , which shows the claim. ◀ ▶ Lemma 70. Let q ∈ sjfBCQU,A be saturated and normal. Suppose OutK⇝ (q) (⊥) = ∅. There exists a variable x ∈ RootVars⇝ (q) such that x is not attacked and OutKc (q) (x) = {x}. Proof. Assume toward contradiction that all variables in RootVars⇝ (q) are attacked. Since OutK⇝ (q) (⊥) = ∅ and K⇝ (q) is acyclic, there exists at least one element x in RootVars⇝ (q). Then F ⇝ x, for some F ∈ q. In particular, there exists a variable v ∈ NonKeyVars(F ) such that Key(F ) → v ∈ Ki (q) ⊆ K⇝ (q). Hence, Key(F ) ̸= ⊥ by OutK⇝ (q) (⊥) = ∅. Now, either Key(F ) ∈ RootVars⇝ (q), or there exists a non-empty path from a variable y ∈ RootVars⇝ (q) to Key(F ). In the former case, letting y be the variable Key(F ), it holds that F ′ ⇝ y for some F ′ ∈ q. In the latter case, the first edge of the non-empty path, denote it by y → z, belongs to Ki (q) by Lemma 64. Suppose y → z is generated by G ∈ q. By Lemmas 15 + and 60, we have G ⇝ F . Then, F ′ ⇝ y for some F ′ ∈ q, as in the previous case. In both cases, we repeat the reasoning above, substituting y for x. Eventually, this leads to a cycle in the attack graph, a contradiction.

M. Hannula

We conclude by contradiction that there exists a variable x ∈ RootVars⇝ (q) that is not attacked. If OutKc (q) (x) = {x}, we are done. Thus, suppose OutKc (q) (x) ̸= {x}, i.e., x → y ∈ Kc (q), for some y ̸= x. First, we claim that y ∈ RootVars⇝ (q). Suppose this is not the case. Then there exists an edge of the form y0 → y ∈ K⇝ (q). Suppose first that y0 → y ∈ Ki (q), and let F ∈ q be the atom generating y0 → y. Then F ⇝ y by Lemma 15, hence y ∈ / F +,q . Consequently, as c +,q x → y ∈ K (q), we obtain x ∈ / F . However, since {x, y} is an edge Gaifman(q), we obtain F ⇝ x, contradicting the fact that x is unattacked. Suppose then that y0 → y ∈ Kc (q), in which case there exists an edge of the form z → y0 ∈ Ki (q), generated by F ′ . In this case, we obtain by Lemma 21 that F ′ ⇝ y, and the contradiction obtains as above. Hence the claim that y ∈ RootVars⇝ (q) holds. Then, we claim that y is likewise not attacked. Toward contradiction, suppose F ⇝ y, for some F ∈ q. Then, y ∈ / F +,q , hence x ∈ / F +,q due to x → y ∈ Kc (q). By the same token, {x, y} is an edge Gaifman(q), leading to F ⇝ x, a contradiction. Therefore, y is not attacked. By Lemma 14 and Item 3 of normality, Kc (q) is acyclic apart from the dummy self-loops. Consequently, by the above two paragraphs, there exists y ∈ RootVars⇝ (q) such that y is not attacked and OutKc (q) (y) = {y}. This concludes the proof. ◀ ▶ Lemma 71. Let q ∈ sjfBCQU,A be saturated and normal. Let u and v be distinct variables from RootVars⇝ (q). Then ReachK⇝ (q) (u) ∩ ReachK⇝ (q) (v) = ∅. Proof. Assume toward contradiction that ReachK⇝ (q) (u) ∩ ReachK⇝ (q) (v) ̸= ∅, for some distinct variables u and v from RootVars⇝ (q). Choose a vertex w ∈ ReachK⇝ (q) (u) ∩ ReachK⇝ (q) (v). By Lemma 69, if x → y, x′ → y ′ ∈ K⇝ (q) and y ∼ y ′ , then x ∼ x′ . Hence, there exist two vertices u0 ∈ ReachK⇝ (q) (u) and v0 ∈ ReachK⇝ (q) (v) such that u0 ∼ v0 , and u0 = u or v0 = v. By symmetry we may assume that u0 = u, meaning that u ∼ v0 . If u = v0 , then u ∈ ReachK⇝ (q) (v), a contradiction. Hence u = ̸ v0 , which means that there exists F ∈ q such that u, v0 ∈ NonKeyVars(F ). By normality of q, we obtain x → u ∈ Ki (q), for x = Key(F ). By definition, then, u has an incoming edge in K⇝ (q), a contradiction. ◀ The previous lemma establishes that for each vertex in v ∈ Vars(q) ∪ {⊥}, there exists a unique u ∈ RootVars⇝ (q) such that v ∈ ReachK⇝ (q) (u). We then call this vertex u the root of v, denoted RootOf ⇝ (v). Observe that RootOf ⇝ (⊥) = ⊥. ▶ Lemma 72. Let q ∈ sjfBCQU,A be saturated and normal. Let F ∈ q and let x, y ∈ NonKeyVars(F ). Then x → y ∈ / K(q). Proof. Toward contradiction, suppose x → y ∈ K(q). Then by definition there exists G ∈ q such that x → y ∈ K(G). Since q is variable-repetition-free, we obtain x = ̸ y. Hence, i by normality, z → y ∈ K (q), for z := Key(F ). Also by normality, x → y ∈ / Kc (G), so i x → y ∈ K (G). Moreover, variable-repetition-freeness guarantees that z ̸= x. Thus, a contradiction with Lemma 16 arises, whereby we conclude that x → y ∈ / K(q). ◀

E

Definitions and Lemmas for Section 6

This section contains the missing definitions, proofs, and lemmas for Section 6.

47

48

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

E.1

Properties of Guards

First, we consider various properties related to guarding. ▶ Lemma 73. Let q ∈ sjfBCQU,A be saturated and normal. Let x, y ∈ RootVars⇝ (q). If y ∈ ReachK(q) (x), then x → y ∈ Kc (q). ̸ y. Assume toward Proof. If x = y, the statement holds trivially. Thus suppose x = contradiction that x → y ∈ / Kc (q). By y ∈ ReachK(q) (x) there exists a (non-empty) path D from x to y in K(q). Assume D is shortest among such paths. By Lemma 14 and the assumption, some edge u → v on D belongs to Ki (q). Moreover, x ∈ RootVars⇝ (q) entails that u → v is not the last edge on D. We may select u → v so that that none of the edges that follow it in D belongs to Ki (q). Then, due to Lemma 14 and D being shortest, we obtain that u → v is followed by v → y ∈ Kc (q) in D. Since v ̸= y and v → y ∈ / K⇝ (q) ⇝ c (by y ∈ RootVars (q)), it follows by Lemma 67 that u → y ∈ K (q), contradicting the assumption that D is shortest. Hence we conclude that x → y ∈ Kc (q). ◀ ▶ Lemma 74. If q ∈ sjfBCQU,A is saturated and normal, then |GuardVars(q)| ≤ #srcSCC(K(q)). Proof. Let x, y ∈ GuardVars(q). Then, by definition, x, y ∈ RootVars⇝ (q). By Lemma 73, if x and y belong to the same SCC of K(q), then x → y ∈ Kc (q) and y → x ∈ Kc (q). By normality, this is only possible when x = y. Thus, the variables in GuardVars(q) are distributed to distinct source SCCs, which entails the lemma statement. ◀ ▶ Lemma 75. If q ∈ sjfBCQU,A is saturated and normal, then RootVars⇝ (q) ⊆ GuardedVars(q). Proof. Let x ∈ RootVars⇝ (q). If x ∈ GuardVars(q), then x is guarded by itself. If x ∈ / GuardVars(q), then there exists a variable y ∈ GuardVars(q) such that x ∈ ReachK(q) (y) and y∈ / ReachK(q) (x). For this, observe that every source SCC intersects with RootVars⇝ (q). Since y ∈ RootVars⇝ (q), we obtain by Lemma 73 that y → x ∈ Kc (q). That is, y guards x, which means that x ∈ GuardedVars(q). ◀ ▶ Lemma 76. Let q ∈ sjfBCQU,A be saturated and normal. Let y ∈ NotGuardedVars(q) ∩ NotKeyVars(q), x ∈ Vars(q), x = ̸ y, and x → y ∈ Kc (q). Then K(q) contains a path z1 , . . . , zn such that 1. z1 → y ∈ K⇝ (q); 2. zn = x; and 3. zi → y ∈ Kc (q) and zi ̸= y for each i ∈ [n]. Proof. Note that x → y ∈ K(q) due to x ̸= y and x → y ∈ Kc (q). If x → y ∈ K⇝ (q), we can select the path that consists of x only. Thus suppose x → y ∈ Kc (q) \ K⇝ (q). Toward contradiction, suppose the statement of the lemma is false. Now, K(q) contains a path z1 , . . . , zn where z1 ∈ GuardVars(q) and zn = x. Since y ∈ NotKeyVars(q), we have zi ̸= y for each i ∈ [n]. Suppose zk+1 → y, . . . , zn → y ∈ Kc (q) and zk+1 → y ∈ / K⇝ (q). Since zk+1 = ̸ y, c ⇝ we obtain zk → y ∈ K (q) by Lemma 67. If zk → y ∈ K (q), the statement is true for the truncated path (zk , . . . , zn ), a contradiction. Hence, we have that zk → y, . . . , zn → y ∈ Kc (q) and zk → y ∈ / K⇝ (q).

M. Hannula

49

By induction, it follows that z1 → y ∈ Kc (q), contradicting y ∈ NotGuardedVars(q). We conclude by contradiction that the statement is true. ◀ ▶ Lemma 77. Let q ∈ sjfBCQU,A be saturated and normal, and let R ∈ q. Let db be a q-saturated database. Then |Rdb | ≤ |Rdb ↾V | · |adom(db)||GuardVars(q)| , where V := Vars(R) ∩ NotGuardedVars(q). Proof. Let {z1 , . . . , zn } ⊆ GuardVars(q) be such that that y ∈ Vars(R) ∩ GuardedVars(q) if and only if zi → y ∈ Kc (q), for some i ∈ [n]. Write Wi := {y ∈ Vars(R) ∩ GuardedVars(q) | zi → y ∈ Kc (q)}. For each i ∈ [n], select some Si ∈ q such that Si generates z → y (i.e., Si (z, y, −) ∈ q), for some y ∈ Wi . By the q-saturation of db, we obtain |Rdb | ≤|Rdb ↾V | · |Rdb ↾W1 | · . . . · |Rdb ↾Wn | ≤ |Rdb ↾V | · |S1db ↾{z} | · . . . · |Sndb ↾{z} | ≤|Rdb ↾V | · |adom(db)|n ≤ |Rdb ↾V | · |adom(db)||GuardVars(q)| . ◀

This proves the lemma statement.

E.2

Guarded Reductions

Next, we present what we call guarded reductions. These reductions rely on a size-invariance property which is given first. This property ensures that repeated applications of guarded reductions do not cause an uncontrolled blow-up in the intermediate instances. ▶ Definition 78 (N -unguarded-bounded instance). Let db be a database and q ∈ sjfBCQU,A . Let N ∈ N. The pair (db, q) is called N -unguarded-bounded if, for each R ∈ q, |Rdb ↾V | ≤ N, where V := Vars(R) ∩ NotGuardedVars(q). ▶ Definition 79 (Guarded Reduction). A many-one reduction f : DB × sjfBCQU,A → DB × sjfBCQU,A ∪{true, false} is guarded if for every (db, q) ∈ DB×sjfBCQU,A , assuming (db′ , q ′ ) = f (db, q) ∈ / {true, false}, the following statements hold: 1. If (db, q) is N -unguarded-bounded, then (db′ , q ′ ) is N -unguarded-bounded. 2. adom(db′ ) ⊆ adom(db). 3. db′ ↾Rel(q)∩Rel(q′ ) ⊆ db↾Rel(q)∩Rel(q′ ) . c

4. If F ∈ q c , and either Key(F ) ∈ GuardVars(q) or Vars(F ) = ∅, then F ∈ (q ′ ) . 5. GuardedVars(q) = GuardedVars(q ′ ). 6. GuardVars(q) = GuardVars(q ′ ). 7. Vars(q ′ ) ⊆ Vars(q). 8. ||q ′ || ≤ ||q||. By slight abuse of terminology, when we state preservation properties for DBSaturate, we mean the reduction (db, q) 7→ (DBSaturate(db, q), q). The following lemma is an immediate consequence of Lemma 9. ▶ Lemma 80. DBSaturate is a guarded reduction.

50

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

The following proposition shows a useful property. ▶ Proposition 81. Guarded reductions are closed under composition, provided that newly introduced relation names are fresh. Proof. All conditions in the definition of guardedness compose. Item 4 additionally relies on Item 6, while Item 3 requires that introduced relation names are fresh. Informally, freshness guarantees that relation symbols have contiguous lifetimes under guarded reductions. ◀

E.3

Leaf Pruning

A variable y ∈ LeafVars⇝ (q) is called prunable if y ∈ KeyVars(q). The operator LeafPruney is defined on pairs (db, q) such that y is a prunable variable of q. For such a pair, given q0 := {F ∈ q | y = Key(F )} and db0 := db \ db↾q0 , we define LeafPruney (db, q) := (db′ , q ′ ),

(9)

where q ′ := q \ q0 and db′ := DBSaturate(db0 , q ′ ).

(10)

In particular, we have that y ∈ / KeyVars(q ′ ). Furthermore, q ′ inherits variable-repetitionfreeness from q. ▶ Lemma 82. Let q ∈ sjfBCQU,A be saturated and normal. Let y be a prunable variable. Let u, v ∈ Vars(q) ∪ {⊥} be such that u = ̸ y. If (db′ , q ′ ) = LeafPruney (db, q) ∈ / {true, false}, then u → v ∈ K(q) if and only if u → v ∈ K(q ′ ), u → v ∈ Ki (q) if and only if u → v ∈ Ki (q ′ ), u → v ∈ Kc (q) if and only if u → v ∈ Kc (q ′ ), u → v ∈ K⇝ (q) if and only if u → v ∈ K⇝ (q ′ ). Proof. The case where u = v is clear since both q and q ′ are variable-repetition-free. Thus, we assume that u ̸= v. Then, u → v ∈ K(F ) implies F ∈ q ′ . Furthermore, the assumption is that u, v ∈ Vars(q) ∪ {⊥} are such that u = ̸ y. We then obtain that u → v ∈ K(q) implies u → v ∈ K(q ′ ), and u → v ∈ Kc (q) implies u → v ∈ Kc (q ′ ). The converse implications hold trivially. The second equivalence is then a consequence of the first and the third one. The last equivalence follows from the second and third. For instance, if u → v ∈ K⇝ (q) due to u → v ∈ Kc (q), w → u ∈ Ki (q), and w → v ∈ / Kc (q), then w ̸= y (as w ∈ / LeafVars⇝ (q)), c ′ i ′ c ′ hence u → v ∈ K (q ), w → u ∈ K (q ), and w → v ∈ / K (q ). The remaining cases can be checked analogously. ◀ ▶ Lemma 83. Let q ∈ sjfBCQU,A be saturated and normal. Let y be a prunable variable. If (db′ , q ′ ) = LeafPruney (db, q) ∈ / {true, false}, then GuardVars(q) = GuardVars(q ′ ). Proof. We need to prove RootVars⇝ (q) ∩ SrcVars→ (q) = RootVars⇝ (q ′ ) ∩ SrcVars→ (q ′ ). We first prove RootVars⇝ (q) = RootVars⇝ (q ′ ). Assuming v ∈ / RootVars⇝ (q), there exists ⇝ ⇝ an edge of the form u → v in K (q). Since y ∈ LeafVars (q), we obtain u = ̸ y, hence u → v belongs to K⇝ (q ′ ) by Lemma 82, i.e., v ∈ / RootVars⇝ (q ′ ). Conversely, assuming

M. Hannula

51

v∈ / RootVars⇝ (q ′ ), there exists an edge of the form u → v in K⇝ (q ′ ). By construction u = ̸ y, hence u → v belongs to K⇝ (q) by Lemma 82, i.e., v ∈ / RootVars⇝ (q ′ ). Then, we show SrcVars→ (q) ∩ RootVars⇝ (q) ⊆ SrcVars→ (q ′ ). Assuming u ∈ SrcVars→ (q) ∩ / SrcVars→ (q ′ ). Then we find an RootVars⇝ (q), suppose toward contradiction that u ∈ edge u0 → u ∈ K(q ′ ) such that u0 ∈ / ReachK(q′ ) (u). Clearly, u0 → u ∈ K(q). Since u ∈ SrcVars→ (q), it holds that u0 ∈ ReachK(q) (u). In particular, there exists a simple directed path D from u to u0 in K(q). Since no such path exists in K(q ′ ), this path contains an edge of the form y → v. Moreover, as y = ̸ u due to y ∈ LeafVars⇝ (q) and u ∈ RootVars⇝ (q) ⇝ ⇝ (while LeafVars (q) ∩ RootVars (q) = ∅), this edge is preceded in D by an edge of the form p → y. Now, since y ∈ LeafVars⇝ (q), we obtain y → v ∈ Kc (q) \ K⇝ (q). Since y = ̸ v, it follows by Lemma 67 that p → v ∈ Kc (q). Thus, by Lemma 82, the path D′ obtained from D by replacing p → y and y → v with the shortcut edge p → v is a path from u to u0 in K(q ′ ). This raises a contradiction, by which we conclude that u ∈ SrcVars→ (q ′ ). Finally, we prove SrcVars→ (q ′ ) ⊆ SrcVars→ (q). Assuming u ∈ SrcVars→ (q ′ ), suppose toward contradiction that u ∈ / SrcVars→ (q). Then we find an edge u0 → u ∈ K(q) such that u0 ∈ / ReachK(q) (u). If u0 → u ∈ K(q ′ ), then by assumption u0 ∈ ReachK(q′ ) (u), which implies u0 ∈ ReachK(q) (u) by the construction of q ′ , a contradiction. Thus, suppose u0 → u ∈ / K(q ′ ). This entails u0 = y. Therefore, by y ∈ LeafVars⇝ (q) there exists an edge of the form w → u0 ∈ K⇝ (q). Since w → u0 ∈ K(q) by definition, it follows by Lemma 68 that w → u ∈ Kc (q). Now, w = ̸ y as q is variable-repetition-free, so either w = u or w → u ∈ K(q ′ ) obtains. But then, by assumption, w ∈ ReachK(q′ ) (u), which implies w ∈ ReachK(q) (u). Composing with the edge w → u0 , we obtain u0 ∈ ReachK(q) (u), a contradiction. Thus, we conclude that u ∈ SrcVars→ (q). ◀ ▶ Lemma 84. Let q ∈ sjfBCQU,A be saturated and normal. Let y be a prunable variable. If (db′ , q ′ ) = LeafPruney (db, q) ∈ / {true, false}, then GuardedVars(q) = GuardedVars(q ′ ). Proof. Let v ∈ GuardedVars(q). Then we find S(u, v, −) ∈ q such that u ∈ GuardVars(q) and u → v ∈ Kc (q). Since u ∈ RootVars⇝ (q) and y ∈ LeafVars⇝ (q), we obtain y ̸= u. Thus, by Lemma 82 we have that u → v ∈ Kc (q ′ ), and by construction we obtain S(u, v, −) ∈ q ′ . Moreover, by Lemma 83, we obtain u ∈ GuardVars(q ′ ). Assume then that v ∈ GuardedVars(q ′ ). Then we find S(u, v, −) ∈ q ′ such that u ∈ GuardVars(q ′ ) and u → v ∈ Kc (q ′ ). Now y = ̸ u by the construction of q ′ , hence u → c v ∈ K (q) by Lemma 82. Moreover, S(u, v, −) ∈ q is clear, and u ∈ GuardVars(q) follows by Lemma 83. ◀ ▶ Lemma 85. Let q ∈ sjfBCQU,A be a saturated and normal. Let y be a prunable variable. If LeafPruney (db, q) = (db′ , q ′ ), then the following statements hold: (a) q ′ ∈ sjfBCQU,A ; (b) q ′ is saturated; (c) q ′ is normal. Proof. (Item (a)) Clearly, q ′ remains variable-repetition-free. For acyclicity of the attack q′

q

graph, it suffices to prove that F ⇝ G implies F ⇝ G.

52

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

q′

Suppose F ⇝ G. Then Gaifman(q ′ ) contains a (possibly empty and undirected) path U between NonKeyVars(F ) and Vars(G) that is not separated by F +,q . Clearly, U belongs q also to Gaifman(q). Assume toward contradiction that F ⇝ ̸ G. Then, some variable v in U belongs to F +,q . Writing u = Key(F ), this means K(q \ {F }) contains a (directed) path D from t to v, where y = ̸ t ∈ {⊥, u}; for this, recall that y ∈ / Vars(q ′ ). We may assume D is shortest among all such paths. Since D is not included in K(q ′ \ {F }), an edge of the form y → z appears on it. Since y ∈ LeafVars⇝ (q), it holds that y → z ∈ Kc (q) \ K⇝ (q). Since t = ̸ y, some edge v → y precedes y in D. Clearly y = ̸ z, so we obtain by Lemma 67 that v → z ∈ Kc (q) ⊆ K(q \ {F }), q leading to a shortcut in D, a contradiction. We conclude from the contradiction that F ⇝ G. (Item (b)) Suppose F ∈ q ′ , u → v ∈ K(F ), v → w ∈ Kc (q ′ ), and u → w ∈ K∗ (q ′ \ {F }). We need to prove that u → w ∈ Kc (q ′ ). By Lemma 82, v → w ∈ Kc (q), and clearly, u → w ∈ K∗ (q \ {F }). Since F ∈ q, we obtain by saturation of q that u → w ∈ Kc (q). Since u ∈ KeyVars(q ′ ), we have that u = ̸ y. Thus, by Lemma 82, we obtain that u → w ∈ Kc (q ′ ). (Item (c)) In what follows we consider an atom F ∈ q ′ . Assuming that there is a contradiction with the normality of q ′ , possibly witnessed by F , we construct a contradiction with the assumption that q is normal. (Item 1) Suppose toward contradiction that |NonKeyVars(F )| > 1 and p → u ∈ Kc (q ′ ), where p = Key(F ) and u ∈ NonKeyVars(F ). Since F ∈ q and, by Lemma 82, p → u ∈ Kc (q), we obtain a contradiction with the normality of q. (Item 2) Suppose toward contradiction that u → v ∈ Kc (q ′ ), for some distinct u, v ∈ NonKeyVars(F ). Then u → v ∈ K(q ′ ), and in particular u ∈ KeyVars(q ′ ). Since y ∈ / ′ c KeyVars(q ), we have u ̸= y, hence Lemma 82 entails u → v ∈ K (q) in contradiction with the normality of q. (Item 3) If u → v, v → u ∈ Kc (q ′ ), for some distinct u, v ∈ Vars(q ′ ), then analogously to the previous case we obtain u → v, v → u ∈ Kc (q) using Lemma 82, a contradiction with the normality of q. (Item 4) If ⊥ → z ∈ Kc (q ′ ), for some z ∈ Vars(q ′ ), then by Lemma 82 we also obtain ⊥ → z ∈ Kc (q), contradicting the normality of q. ◀ The main lemma of this section follows. ▶ Lemma 86 (Leaf Pruning). Let C consist of all (db, q) ∈ DB × sjfBCQU,A , where q is a saturated and normal query and db is a q-saturated database. For each (db, q) ∈ C and prunable y ∈ Vars(q), (db, q) 7→ LeafPruney (db, q) is a strict, guarded, equivalencepreserving, and polynomial-time reduction from C to C ∪ {true, false}. Proof. Let y be a prunable variable, and suppose LeafPruney (db, q) = (db′ , q ′ ). The reduction LeafPruney is clearly strict and computable in polynomial time. It is into C ∪ {true, false} by Lemmas 9 and 85. It suffices to prove that it is guarded and equivalencepreserving. (Guardedness) Items 5 and 6 of guardedness follow by Lemmas 83 and 84. Items 2–3, 7, and 8 are clear by construction. We prove Items 1 and 4.

M. Hannula

For Item 4, assume that F ∈ q c , and either Key(F ) ∈ GuardVars(q) or Vars(F ) = ∅. Since Key(F ) ̸= y, as y ∈ LeafVars⇝ (q) (and GuardVars(q) is a subset of RootVars⇝ (q), which is c i disjoint with LeafVars⇝ (q)), we obtain F ∈ q ′ . Moreover, F ∈ (q ′ ) , because F ∈ (q ′ ) means i ′ that there exists an edge u → v in K (q ) ∩ K(F ). Since this implies u = ̸ y, we would obtain i i u → v ∈ K (q) by Lemma 82, which entails F ∈ q , a contradiction. Hence, Item 4 holds. It remains to consider Item 1, that is, N -boundedness. Assume that for each F ∈ q, |F db ↾V | ≤ N, where V := Vars(F ) ∩ NotGuardedVars(q). Now, Lemma 84 entails NotGuardedVars(q) ∩ Vars(q ′ ) = NotGuardedVars(q ′ ). Thus, for each for each F ∈ q ′ , given V ′ := Vars(F ′ ) ∩ NotGuardedVars(q ′ ), we obtain V ′ = V . Hence, ′

|F db ↾V ′ | ≤ |F db ↾V | ≤ N, proving Item 1. We conclude that LeafPruney is guarded. (Equivalence-preservation) Given q0 := {F ∈ q | y = Key(F )} and db0 := db \ db↾q0 , by Lemma 9 it suffices to prove that (db, q) ∈ CERTAINTY if and only if (db0 , q ′ ) ∈ CERTAINTY. (⇒) Suppose (db, q) ∈ CERTAINTY, and let r′ be an arbitrary repair of db0 . Define r := r′ ∪ db↾q0 . Since q is saturated and normal, and y ∈ LeafVars⇝ (q), it holds that every F ∈ q0 is of the form S(y, ⃗c) or S(y, z, ⃗c), where z is a variable such that y → z ∈ Kc (q) and ⃗c is a (possibly empty) sequence of constants. Since db is q-saturated, db↾q0 is consistent. In particular, r is a repair of db. Since r |= q by assumption, we obtain r′ |= q ′ . Hence (db0 , q ′ ) ∈ CERTAINTY. (⇐) Suppose (db0 , q ′ ) ∈ CERTAINTY, and let r be a repair of db. Then r′ := r \ r↾q0 is a repair of db0 . Now, (db0 , q ′ ) ∈ CERTAINTY implies we find a valuation θ such that θ(q ′ ) ⊆ r′ . We show that θ(F ) ∈ r, for each F ∈ q0 . For this, consider an atom F ∈ q0 . As observed above, F is of the form S(y, ⃗c) or S(y, z, ⃗c), where z is a variable such that y → z ∈ Kc (q) and ⃗c is a (possibly empty) sequence of constants. Note that S db is consistent due to q-saturation. Since y ∈ LeafVars⇝ (q), there exists an edge of the form x → y ∈ K⇝ (q) ⊆ K(q) (where, as q is variable-repetition-free, x = ̸ y). Then, there exists an atom of the form R(x, y, −) ∈ q generating x → y. Since x ̸= y, we have R(x, y, −) ∈ q ′ , hence R(θ(x), θ(y), −) ∈ r′ . If NonKeyVars(F ) = ∅, then from the q-saturation of db it readily follows that θ(F ) ∈ db. By the consistency of S db we then obtain θ(F ) ∈ r. Thus, suppose NonKeyVars(F ) ̸= ∅. Then, F is of the form S(y, z, ⃗c), where z is a variable such that y → z ∈ Kc (q) and ⃗c is a (possibly empty) sequence of constants. Since y ∈ LeafVars⇝ (q), we obtain by Lemma 68 that x → z ∈ Kc (q). Consequently, there exists an atom of the form T (x, z, −) ∈ q. Since x ̸= y, we have T (x, z, −) ∈ q ′ , hence T (θ(x), θ(z), −) ∈ r′ . As db is q-saturated and r′ ⊆ db, we obtain S(θ(y), θ(z), −) ∈ db. Moreover, by the q-saturation of db, this is tantamount to θ(F ) = S(θ(y), θ(z), ⃗c) ∈ db. Since S db is consistent, we obtain θ(F ) ∈ r. We conclude that θ(q) ⊆ r, hence (db, q) ∈ CERTAINTY. ◀

53

54

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

E.4

Leaf Elimination

A variable y ∈ NotGuardedVars(q) ∩ LeafVars⇝ (q) ∩ NotKeyVars(q) is called eliminable. The operator LeafElimy is defined on pairs (db, q) such that y is an eliminable variable of q. For such a pair, given q ′ := {F −y | F ∈ q} and db0 := {A−y | A ∈ db},

(11)

we define LeafElimy (db, q) := (db′ , q ′ ),

(12)

where db′ := DBSaturate(db0 , q ′ ). The reader is referred to the beginning of Section 5.3 for the definition of the notation F −y . Note that y ∈ / Vars(q ′ ), and in particular, Vars(q) \ {y} = Vars(q ′ ). Furthermore, q ′ inherits variable-repetition-freeness from q. The helping lemmas that follow are analogous to the previous section. ▶ Lemma 87. Let q ∈ sjfBCQ be saturated and normal. Let y be eliminable. Let u, v ∈ Vars(q) ∪ {⊥} be such that v ̸= y. If (db′ , q ′ ) = LeafElimy (db, q) ∈ / {true, false}, then u → v ∈ K(q) if and only if u → v ∈ K(q ′ ); u → v ∈ Ki (q) if and only if u → v ∈ Ki (q ′ ); u → v ∈ Kc (q) if and only if u → v ∈ Kc (q ′ ); u → v ∈ K⇝ (q) if and only if u → v ∈ K⇝ (q ′ ). ̸ v. The first and third items Proof. The case where u = v is clear, so we assume that u = are straightforward. Then, the second item follows. The fourth item is a consequence of the second and third one. For instance, if u → v ∈ K⇝ (q) due to u → v ∈ Kc (q) ∩ K(q), w → u ∈ Ki (q), and w → v ∈ / Kc (q), then u ̸= y by y ∈ NotKeyVars(q), hence we obtain c ′ u → v ∈ K (q ) ∩ K(q), w → u ∈ Ki (q ′ ), and w → v ∈ / Kc (q ′ ) by the second and third item. ′ The converse direction is analogous, as y ∈ / Vars(q ). ◀ ▶ Lemma 88. Let q ∈ sjfBCQ be saturated and normal. Let y be eliminable. If (db′ , q ′ ) = LeafElimy (db, q) ∈ / {true, false}, then GuardVars(q) = GuardVars(q ′ ). Proof. We need to prove RootVars⇝ (q) ∩ SrcVars→ (q) = RootVars⇝ (q ′ ) ∩ SrcVars→ (q ′ ). We first prove RootVars⇝ (q) ⊆ RootVars⇝ (q ′ ). Assuming u ∈ / RootVars⇝ (q ′ ), there exists an ⇝ ′ edge of the form w → u ∈ K (q ). Then u = ̸ y by the construction of q ′ . If w → u ∈ Ki (q ′ ), then w → u ∈ Ki (q) by Lemma 87, i.e., u ∈ / RootVars⇝ (q ′ ). Thus, suppose w → u ∈ Kc (q ′ ) ∩ K(q ′ ). Then we find another edge p → w ∈ Ki (q ′ ) such that p → u ∈ / Kc (q ′ ). By i construction, w ̸= y, hence by Lemma 87 we have p → w ∈ K (q), p → u ∈ Kc (q) and p→u∈ / Kc (q), which is tantamount to w → u ∈ K⇝ (q), i.e., u ∈ / RootVars⇝ (q). We then prove RootVars⇝ (q ′ ) ⊆ RootVars⇝ (q). Assume u ∈ / RootVars⇝ (q). If u = y, then by ⇝ ′ ′ y∈ / Vars(q ) we obtain u ∈ / RootVars (q ). Thus, suppose u = ̸ y. By assumption there exists ⇝ i an edge of the form w → u ∈ K (q). If w → u ∈ K (q), then w → u ∈ Ki (q ′ ) by Lemma 87, i.e., u ∈ / RootVars⇝ (q ′ ). Thus, suppose w → u ∈ Kc (q) ∩ K(q). Then we find another edge p → w ∈ Ki (q) such that p → u ∈ / Kc (q). We have w ∈ KeyVars(q), hence w ̸= y. Consequently, Lemma 87 implies p → w ∈ Ki (q ′ ), p → u ∈ Kc (q ′ ), and p → u ∈ / Kc (q ′ ), ⇝ which is tantamount to w → u ∈ K⇝ (q ′ ), i.e., u ∈ RootVars (q ′ ).

M. Hannula

55

Next, we prove SrcVars→ (q) ∩ RootVars⇝ (q) ⊆ SrcVars→ (q ′ ). Assuming u ∈ / SrcVars→ (q ′ ), ′ there exists an edge of the form u0 → u ∈ K(q ) such that u0 ∈ / ReachK(q′ ) (u). Clearly, we have u0 → u ∈ K(q). Now, suppose toward contradiction that u ∈ SrcVars→ (q) ∩ RootVars⇝ (q). Then we obtain u0 ∈ ReachK(q) (u). In particular, there exists a simple directed path D from u to u0 in K(q). Since no such path exists in K(q ′ ), this path contains an edge of the form w → y as an intermediate vertex. Since y ∈ NotKeyVars(q), this edge must be the last one in D, i.e., y = u. But then, u ∈ RootVars⇝ (q) and y ∈ LeafVars⇝ (q) raise a contradiction, as RootVars⇝ (q) ∩ LeafVars⇝ (q) = ∅. Thus the claim follows. Finally, we show SrcVars→ (q ′ ) ⊆ SrcVars→ (q). Assuming u ∈ SrcVars→ (q ′ ), suppose toward contradiction that u ∈ / SrcVars→ (q). Then we find an edge u0 → u ∈ K(q) such that u0 ∈ / ReachK(q) (u). If u0 → u ∈ K(q ′ ), then by assumption u0 ∈ ReachK(q′ ) (u), which implies u0 ∈ ReachK(q) (u) by the construction of q ′ , a contradiction. Thus, suppose u0 → u ∈ / K(q ′ ). → ′ ′ This entails u = y, in which case u ∈ / Vars(q ), and in particular u ∈ / SrcVars (q ), a contradiction. Therefore, by contradiction we obtain u ∈ SrcVars→ (q). ◀ ▶ Lemma 89. Let q ∈ sjfBCQ be saturated and normal. Let y be eliminable. If (db′ , q ′ ) = LeafElimy (db, q) ∈ / {true, false}, then GuardedVars(q) = GuardedVars(q ′ ). Proof. Let v ∈ GuardedVars(q). Then we find u ∈ GuardVars(q) such that u → v ∈ Kc (q). Since y ∈ NotGuardedVars(q), we obtain y ̸= v. Then, by Lemma 87 we obtain u ∈ GuardVars(q ′ ) and by Lemma 88 that u → v ∈ Kc (q ′ ), hence v ∈ GuardedVars(q ′ ). Assume then that v ∈ GuardedVars(q ′ ). Then we find u ∈ GuardVars(q ′ ) such that u → v ∈ Kc (q ′ ). Now y = ̸ u by the construction of q ′ , hence u → v ∈ Kc (q) by Lemma 87. Moreover, u ∈ GuardVars(q) follows by Lemma 88. Thus v ∈ GuardedVars(q). ◀ ▶ Lemma 90. Let q ∈ sjfBCQU,A be saturated and normal. Let y be eliminable. If (db′ , q ′ ) = LeafElimy (db, q) ∈ / {true, false}, then (a) q ′ ∈ sjfBCQU,A ; (b) q ′ is saturated; (c) q ′ is normal. Proof. (Item (a)) Clearly, q ′ remains variable-repetition-free. For acyclicity of the attack q′

q

graph, it suffices to prove that F ⇝ G implies F ⇝ G. q′

Suppose F ⇝ G. Then Gaifman(q ′ ) contains a (possibly empty) path U between NonKeyVars(F ) and Vars(G) that is not separated by F +,q . Clearly, U belongs also to Gaifman(q). Assume q toward contradiction that F ⇝ ̸ G. Then, some variable v in U belongs to F +,q . Writing u = Key(F ), this means K(q \ {F }) contains a (directed) path D from t to v, where t ∈ {u, ⊥}. We may assume D is shortest among all such paths. Since D is not included in K(q ′ \ {F }), we observe that an edge of the form x → y appears on D. Since y ∈ NotKeyVars(q), it must be the case that y is the last element of D, in which case y appears on U . However, U is a path on Gaifman(q ′ ), and y ∈ / Vars(q ′ ), meaning that y cannot appear on U . From this q contradiction, we conclude that F ⇝ G. (Item (b)) Suppose F ∈ q ′ , u → v ∈ K(F ), v → w ∈ Kc (q ′ ), and u → w ∈ K∗ (q ′ \ {F }). We need to prove u → w ∈ Kc (q ′ ).

56

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Let F = G−y , where G ∈ q. Now u, v, w ∈ Vars(q ′ ), which entails that none of u, v, w is y. Hence, by Lemma 87, we have v → w ∈ Kc (q), and clearly u → w ∈ K∗ (q \ {G}). Since also u → v ∈ K(G), by saturation of q it follows that u → w ∈ Kc (q), hence u → w ∈ Kc (q ′ ) by Lemma 87. (Item (c)) In what follows we write H ′ := H −y , for each H ∈ q. We assume, for the sake of a contradiction, that q ′ is not normal. There are four different cases. (Item 1) Suppose toward contradiction that |NonKeyVars(F ′ )| > 1, and p → u ∈ Kc (q ′ ), for p = Key(F ′ ) and some u ∈ NonKeyVars(F ′ ). Then p, u are distinct from y, and hence Lemma 87 entails u → v ∈ Kc (q). Clearly also |NonKeyVars(F )| > 1, p = Key(F ′ ) and u ∈ NonKeyVars(F ′ ). This raises a contradiction with the normality of q. (Item 2) If u → v ∈ Kc (q ′ ), for some distinct u, v ∈ NonKeyVars(F ′ ), then u, v are disctinct from y, leading to u → v ∈ Kc (q) by Lemma 87. Moreover u, v ∈ NonKeyVars(F ), leading to a contradiction with the normality of q. Therefore this items follows, too. (Item 3) If u → v, v → u ∈ Kc (q ′ ), for some distinct u, v ∈ Vars(q ′ ), then u, v ∈ Vars(q) \ {y}, and u → v, v → u ∈ Kc (q) obtains by Lemma 87, a contradiction with the normality of q. (Item 4) If ⊥ → z ∈ Kc (q ′ ), for some z ∈ Vars(q ′ ), then ⊥ → z ∈ Kc (q) by Lemma 87, a contradiction. Hence this item follows. ◀ ▶ Lemma 91 (Leaf Elimination). Let C consist of all (db, q) ∈ DB × sjfBCQU,A , where q is a saturated and normal query and db is a q-saturated database. For each (db, q) ∈ C and eliminable y ∈ Vars(q), (db, q) 7→ LeafElimy (db, q) is strict, guarded, equivalencepreserving, and polynomial-time reduction from C to C ∪ {true, false}. Proof. Let y be an eliminable variable, and suppose LeafElimy (db, q) = (db′ , q ′ ). The reduction LeafElimy is clearly strict and computable in polynomial time. It is into C ∪ {true, false} by Lemmas 9 and 90. It suffices to prove that it is guarded and equivalencepreserving. (Guardedness) Items 5 and 6 of guardedness follow by by Lemmas 88 and 89. Items 2–3, 7, and 8 are clear by construction. We prove Items 1 and 4. For Item 4, assume that F ∈ q c , and either Key(F ) ∈ GuardVars(q) or Vars(F ) = ∅. Toward contradiction, suppose first that F ∈ / q ′ . Then, y ∈ NonKeyVars(F ) by the construction of q ′ . In particular, Vars(F ) ̸= ∅, so we obtain x := Key(F ) ∈ GuardVars(q). Since F ∈ q c , this entails x → y ∈ Kc (q). Hence, y ∈ GuardedVars(q) in contradiction with the assumption that c i y is eliminable. By contradiction, we obtain F ∈ q ′ . Moreover, F ∈ (q ′ ) , because F ∈ (q ′ ) i ′ means that there exists an edge u → v ∈ K (q ) ∩ K(F ) ̸= ∅. Since this implies v ̸= y, we would obtain u → v ∈ Ki (q) by Lemma 87, which entails F ∈ q i , a contradiction. Hence, Item 4 holds. For Item 1 assume that for each F ∈ q, |F db ↾V | ≤ N, where V := Vars(F )∩NotGuardedVars(q). By Lemma 89, we obtain NotGuardedVars(q) ∩ Vars(q ′ ) = NotGuardedVars(q ′ ). Thus, for each for each F ∈ q ′ , given V ′ := Vars(F ′ ) ∩ NotGuardedVars(q ′ ), we obtain V ′ = V ′

|F db ↾V ′ | ≤ |F db ↾V | ≤ N. We may thus conclude that the stated reduction is guarded.

M. Hannula

(Equivalence-preservation) By Lemma 9 it suffices to prove that (db, q) ∈ CERTAINTY if and only if (db0 , q ′ ) ∈ CERTAINTY, given (11). (⇒) Suppose (db, q) ∈ CERTAINTY, and let r′ be an arbitrary repair of db0 . We first construct a repair r of db from r′ as follows: For each A′ ∈ r′ , add to r an arbitrary fact A ∈ db0 such that A−y = A′ . Clearly, r is a repair of db. Since r |= q by assumption, we obtain r′ |= q ′ . Hence (db0 , q ′ ) ∈ CERTAINTY. (⇐) Let r be a repair of db. Then r′ := r−y is a repair of db0 . Now, (db0 , q ′ ) ∈ CERTAINTY implies we find a valuation θ such that θ(q ′ ) ⊆ r′ . Our aim is to find a constant b such that θ′ (q) ⊆ r, where θ′ := θy7→b . Construction of θ′ . Since y ∈ LeafVars⇝ (q), we find an edge of the form x → y in K⇝ (q). Note that x = ̸ y by definition of K⇝ (q) and the fact that q is variable-repetition-free. In particular, there exists an atom of the form F = R(x, y, ⃗z), where ⃗z is possibly empty. Then, F −y = R′ (x, ⃗z), and we have R′ (θ(x), θ(⃗z)) ∈ r′ . By construction, there exists b such that R(θ(x), b, θ(⃗z)) ∈ r. Then, setting θ′ := θy7→b , we have θ′ (F ) ∈ r. Let G ∈ q\{F }. We need show that θ′ (G) ∈ r. Note that y ∈ / Key(G) since y ∈ NotKeyVars(q). ′ If y ∈ / Vars(G), then we clearly obtain θ (G) ∈ r. Thus, suppose that y ∈ NonKeyVars(G). Note that y ̸= Key(G), as q is variable-repetition-free. In particular, we can write G = S(u, y, ⃗v ), where u = ̸ y. Then u → y ∈ K(q). Note that the case that u → y ∈ Ki (q) is not possible due to the normality of q and Lemma 69. Thus u → y ∈ Kc (q). Since y ∈ NotGuardedVars(q) ∩ NotKeyVars(q) and u = ̸ y, we obtain by Lemma 76 a path z1 , . . . , zn in K(q) such that 1. z1 → y ∈ K⇝ (q), 2. zn = u, and 3. zi → y ∈ Kc (q) and zi ̸= y for each i ∈ [n]. Let us write Si (zi , y, −) for the atom of q generating zi → y, for each i ∈ [n]. In particular, let us set Sn as S. Now we have x → y ∈ K⇝ (q) and z1 → y ∈ Kc (q) ∩ K⇝ (q). If x = z1 , then S1 (θ(z1 ), b, −) ∈ r by R(θ(x), b, −) and the fact that db is q-saturated. Suppose x = ̸ z1 . By Lemma 69, we obtain x → y ∈ Kc (q) and z1 ∼ x, where x is a variable. Then, q contains an atom of the form T (t, x, z1 , w). ⃗ By normality of q we have T ∈ q i . Note ⇝ that y ∈ / Vars(T ): if y = t, then K (q) contains a cycle y, x, y (contradicting Lemma 65), and if y appears in (z1 , w) ⃗ (recall y = ̸ x), then K⇝ (q) contains two edges colliding at y, one i edge from K (q) and the other from Kc (q) (contradicting Lemma 69). This entails θ(T ) ∈ r. Since db is q-saturated, we obtain S1 (θ(z1 ), b, −) ∈ r. For an inductive argument, suppose Si (θ(zi ), b, −) ∈ r. Since zi → zi+1 ∈ K(q), there exists an atom of the form U (zi , zi+1 , ⃗u) in q. Recall zi+1 → y ∈ Kc (q), which entails, by normality of q, that y does not appear on ⃗u. Moreover, y is neither of zi or zi+1 . Hence it is correct to conclude that θ(U ) ∈ r. By saturation of db, we obtain Si+1 (θ(zi+1 ), b, −) ∈ r. In this way, we obtain by induction that S(θ(u), b, −) ∈ r. To conclude the argument, observe that θ(G−y ) = S ′ (θ(u), θ(⃗v )) ∈ r′ . Consequently, S(θ(u), c, θ(⃗v )) ∈ r for some constant c. Then, by u → y ∈ Kc (q) and the q-saturation of db we obtain b = c, leading to θ′ (G) ∈ r.

57

58

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

We conclude that θ(q) ⊆ r, hence (db, q) ∈ CERTAINTY.

E.5

◀

Consistent Edge Elimination

We say that F ∈ q i , with Y := NonKeyVars(F ) and Z := OutK⇝ (q) (Y ), is extendable if following conditions hold: 1. OutKi (q) (Y ) = ∅, 2. Z ⊆ LeafVars⇝ (q) ∩ NotKeyVars(q) ∩ GuardedVars(q), 3. Z ̸= ∅. By Item 3 also Y is non-empty. Moreover, by Item 1 we have OutK⇝ (q) (y) ⊆ OutKc (q) (y) for each y ∈ Y . The operator ConsEdgeElimF is defined on pairs (db, q) such that F is an extendable atom of q. Assuming F = R(x, ⃗y ), define first q0 := {G ∈ q | Key(G) ∈ Y }.

(13)

Then, let ⃗z = (z1 , . . . , zℓ ) list the variables in Z. Define q ′ := (q \ (q0 ∪ {R(x, ⃗y )})) ∪ {R′ (x, ⃗y , ⃗z)}.

(14)

Note that q0 ⊆ q c

(15)

by Item 1 and normality of q. For each i ∈ [ℓ], choose the ≺-least atom Si (yji , zi , −) ∈ q c that generates yji → zi ∈ Kc (q), for some variable yji ∈ Y . Then, let db0 := (db \ db↾q0 ) ∪ {R′ (a, ⃗b, ⃗c) | R(a, ⃗b) ∈ db, ∀i ∈ [ℓ] : Si (bji , ci , −) ∈ db}.

(16)

We define ConsEdgeElimF (db, q) := (db′ , q ′ ),

(17)

where db′ := DBSaturate(db0 , q ′ ). It can be observed that Vars(q) = Vars(q ′ ). Therefore, and since Z ⊆ NotKeyVars(q) and x∈ / Y ∪ Z by Lemma 65, we have Y ∪ Z ⊆ NotKeyVars(q ′ ). Due to x ∈ / Y ∪ Z we have ′ that q inherits variable-repetition-freeness from q. Also, due to normality, if F ∈ q i , then x → y ∈ K(F ) implies x → y ∈ Ki (q). ▶ Lemma 92. Let q ∈ sjfBCQU,A be a saturated and normal. Let I ∈ q i be extendable. If (db′ , q ′ ) = ConsEdgeElimI (db, q) ∈ / {true, false}, then q ′ is variable-repetition-free. Proof. Let us assume that F = R(x, ⃗y ). Recall that, beside dropping atoms, q ′ only replaces R(x, ⃗y ) with R′ (x, ⃗y , ⃗z). Thus we only need to exclude the possibility that Y ∩ Z ̸= ∅ or x ∈ Z. The first case implies that there are y, y ′ ∈ Y such that y → y ′ ∈ K⇝ (q). In particular, y → y ′ ∈ K(q). Since then y = ̸ y ′ due to q being variable-repetition-free, we obtain a contradiction with Lemma 72. The second case, in turn, leads to a cycle in K⇝ (q), in contradiction with Lemma 65. Therefore, Y ∩ Z = ∅ and x ∈ / Z, and it is correct to conclude that q ′ remains variable-repetition-free. ◀

M. Hannula

▶ Lemma 93. Let q ∈ sjfBCQU,A be saturated and normal. Let F ∈ q i be extendable. Let u ∈ Vars(q)\Y and v ∈ Vars(q), where Y := NonKeyVars(F ). If (db′ , q ′ ) = ConsEdgeElimF (db, q) ∈ / {true, false}, then u → v ∈ K(q) implies u → v ∈ K(q ′ ), u → v ∈ Ki (q) implies u → v ∈ Ki (q ′ ), u → v ∈ Kc (q) if and only if u → v ∈ Kc (q ′ ). Proof. The case where u = v follows by Lemma 92, so we assume that u = ̸ v. The first item is clear, and the second item follows from the first and the third item. Thus, we prove the third item. Let us write F ′ for the atom corresponding to F ∈ q in q ′ ; that is, F ′ = F for F ̸= R and F ′ = R′ (x, ⃗y , ⃗z) for F = R(x, ⃗y ). Assume that u → v ∈ Kc (q). Then we find distinct G, H ∈ q such that u → v ∈ K(G) and u → v ∈ K∗ (H). Since u ∈ / Y , it follows that u → v ∈ K(G′ ) and u → v ∈ K∗ (H ′ ). Thus c ′ u → v ∈ K (q ). Assume that u → v ∈ Kc (q ′ ). Then we find distinct G′ , H ′ ∈ q ′ such that u → v ∈ K(G′ ) and u → v ∈ K∗ (H ′ ). If u → v ∈ K(G) and u → v ∈ K∗ (H), then u → v ∈ Kc (q). Thus, suppose first that u → v ∈ / K(G). This is only possible when G = R, u = x, and v ∈ Z. Since G and H are distinct, we have H = H ′ and consequently u → v ∈ K∗ (H). Then we have x → v ∈ K(H) or ⊥ → v ∈ K(H). The first case contradicts Lemma 66, and the second case entails ⊥ → v ∈ Kc (q) by Lemma 69, contradicting the normality of q. Thus this is case is not possible. Suppose then that u → v ∈ K(G) and u → v ∈ / K∗ (H). This is only possible when H = R ⇝ c and v ∈ Z. Now, we have y → v ∈ K (q) ∩ K (q), for some y ∈ Y , and u → v ∈ K(q), which entails using Lemma 69 that u → v ∈ Kc (q), as required. ◀ ▶ Lemma 94. Let q ∈ sjfBCQU,A be saturated and normal. Let F ∈ q i be extendable. If (db′ , q ′ ) = ConsEdgeElimF (db, q) ∈ / {true, false}, then GuardVars(q) = GuardVars(q ′ ). Proof. We need to prove RootVars⇝ (q) ∩ SrcVars→ (q) = RootVars⇝ (q ′ ) ∩ SrcVars→ (q ′ ). Let us write F ′ for the atom corresponding to F ∈ q in q ′ ; that is, F ′ = F for F = ̸ R and F ′ = R′ (x, ⃗y , ⃗z) for F = R(x, ⃗y ). We divide the proof into separate claims, from which the lemma statement follow. ▷ Claim 95. RootVars⇝ (q) ⊆ RootVars⇝ (q ′ ). Proof. Toward contradiction, suppose that u ∈ RootVars⇝ (q) \ RootVars⇝ (q ′ ). Then there exists an edge of the form w → u ∈ K⇝ (q ′ ). Since Y ∪ Z ⊆ NotKeyVars(q ′ ), we have w∈ / Y ∪ Z. We consider two cases. Suppose first that w → u ∈ Ki (q ′ ). Since u ∈ RootVars⇝ (q), we also have w → u ∈ / Ki (q). c Furthermore, we have w → u ∈ / K (q) by w ∈ / Y , and Lemma 93. Therefore, w → u ∈ K(q ′ ) \ K(q), which is only possible when w = x and u ∈ Z. However, Z ∩ RootVars⇝ (q) = ∅, while u ∈ RootVars⇝ (q), a contradiction. Suppose then that w → u ∈ K(q ′ ) ∩ Kc (q ′ ). Then we find another edge p → w ∈ Ki (q ′ ) such that p → u ∈ / Kc (q ′ ). Since Y ∪ Z ⊆ NotKeyVars(q ′ ) and w → u, p → w ∈ K(q ′ ), we have w, p ∈ / Y . Hence, Lemma 93 implies w → u ∈ K(q) ∩ Kc (q) and p → u ∈ / Kc (q). Since

59

60

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

u ∈ RootVars⇝ (q), it holds that p → w ∈ / Ki (q) (otherwise, we would obtain p → u ∈ K⇝ (q)). Moreover, by Lemma 14 we have p → w ∈ / Kc (q). Summing up, p → w ∈ K(q ′ ) \ K(q). This entails p = x and w ∈ Z. However, this contradicts w ∈ / Z, which was established above. We conclude by contradiction that neither the case that w → u ∈ K(q ′ ) ∩ Kc (q ′ ) is possible. Hence RootVars⇝ (q) ⊆ RootVars⇝ (q ′ ). ◁ ▷ Claim 96. RootVars⇝ (q ′ ) ⊆ RootVars⇝ (q). Proof. Suppose u ∈ / RootVars⇝ (q). By assumption there exists an edge of the form w → u ∈ K⇝ (q). Assume first that w → u ∈ Ki (q). Since OutKi (q) (Y ) = ∅, this implies w∈ / Y , hence w → u ∈ Ki (q ′ ) by Lemma 93, i.e., u ∈ / RootVars⇝ (q ′ ). Then, suppose that c w → u ∈ K(q) ∩ K (q). This entails that we find another edge p → w ∈ Ki (q) such that p→u∈ / Kc (q). In particular, we obtain p ∈ / Y by OutKi (q) (Y ) = ∅. Assume first that w ∈ / Y . Then, Lemma 93 implies p → w ∈ Ki (q ′ ), w → u ∈ Kc (q ′ ), and c ′ p→u∈ / K (q ), which is tantamount to w → u ∈ K⇝ (q ′ ), i.e., u ∈ / RootVars⇝ (q ′ ). Assume then that w ∈ / Y . Then we obtain u ∈ Z by w → u ∈ K⇝ (q). Toward contradiction, suppose u ∈ RootVars⇝ (q ′ ). Then, the edge x → u that belongs to K(q ′ ) cannot belong to Ki (q ′ ), i.e., it belongs to Kc (q ′ ). In particular, there exists an edge t → u in K(q ′ \ {F ′ }) ⊆ K(q \ {F }), where t ∈ {x, ⊥}. Note that t = x would contradict Lemma 66, as the sequence x, y, z form a path of length 2 in K⇝ (q). Hence t = ⊥, in which case by normality we obtain ⊥ → u ∈ Ki (q). However, we also have w → u ∈ K⇝ (q) ∩ Kc (q), in which case w = ̸ ⊥. Hence, we have a contradiction with Lemma 69, by which we conclude that u ∈ / RootVars⇝ (q ′ ). This concludes the proof of the claim. ◁ ▷ Claim 97. SrcVars→ (q) ∩ RootVars⇝ (q) ⊆ SrcVars→ (q ′ ). Proof. Suppose toward contradiction that the claim is false. Let u ∈ (SrcVars→ (q) ∩ RootVars⇝ (q)) \ SrcVars→ (q ′ ). This means we find an edge u0 → u ∈ K(q ′ ) such that u0 ∈ / ReachK(q′ ) (u). Moreover, u ∈ / Y by Y ∩ RootVars⇝ (q) = ∅. By construction, it is not difficult to see that u ∈ ReachK(q) (u0 ); in particular, if u0 → u is an edge from x to a variable in Z, it can be replaced with two edges: one from x to a variable y ∈ Y such that y → z ∈ K⇝ (q), and the other being the edge y → z. Now, let D = (u, . . . , u0 ) be a shortest path witnessing u ∈ ReachK(q) (u0 ). We claim that D gives rise to a path D′ in K(q ′ ) from u to u0 , contradicting u0 ∈ / ReachK(q′ ) (u). For this, suppose D contains an edge p → w generated by G ∈ q \ q ′ . Then either G = R or p ∈ Y . In the first case p → w is generated by R′ ∈ q ′ , so assume the second case where p ∈ Y . In this case, p ̸= u (as u ∈ / Y ), and moreover Item 1 entails p → w ∈ Kc (q). Let r → p be the edge preceding p → w in D. Then r → p ∈ / Kc (q), because otherwise by Lemma 14 c we obtain r → p ∈ K (q) in contradiction with the minimality of D. Hence r → p ∈ Ki (q). Then p ∈ Y , x → p ∈ Ki (q), and Lemma 16 entail r = x. Summing up, we have shown that p → w belongs to Kc (q) and is preceded by x → p ∈ Ki (q) in D, and p ∈ Y . Note that p → w ∈ / K⇝ (q) implies x → w ∈ Kc (q), contradicting the minimality of D. Hence we have p → w ∈ K⇝ (q). In this case, we obtain w ∈ Z and x → w ∈ K(R′ ), meaning that the edges x → p and p → w in D can be replaced with the edge x → w from K(q ′ ). In this way, D gives rise to a path D′ in K(q ′ ) from u to u0 , in contradiction with u0 ∈ / ReachK(q′ ) (u). Therefore we conclude that SrcVars→ (q) ∩ RootVars⇝ (q) ⊆ SrcVars→ (q ′ ). ◁

M. Hannula

61

▷ Claim 98. SrcVars→ (q ′ ) ⊆ SrcVars→ (q). Proof. Assuming u ∈ SrcVars→ (q ′ ), suppose toward contradiction that u ∈ / SrcVars→ (q). Then we find an edge u0 → u ∈ K(q) such that u0 ∈ / ReachK(q) (u). If u0 → u ∈ K(q ′ ), then by assumption u0 ∈ ReachK(q′ ) (u), which implies u0 ∈ ReachK(q) (u); for this, recall that any edge in K(q ′ ) \ K(q) proceeds from x to Z and is replaceable with two edges in K(q). However, this contradicts the fact that u0 ∈ / ReachK(q) (u). Thus, suppose u0 → u ∈ / K(q ′ ). c This entails u0 ∈ Y . By Item 1 we then obtain u0 → u ∈ K (q), and moreover, we have x → u0 ∈ Ki (q). Consider first the possibility that u0 → u ∈ K⇝ (q). This means that u ∈ Z. However, as x → u ∈ K(q ′ ) and Z ⊆ NotKeyVars(q ′ ), this creates a contradiction with u ∈ SrcVars→ (q ′ ). Hence, suppose u0 → u ∈ / K⇝ (q). In this case, however, x → u ∈ Kc (q) obtains. Since x ∈ / Y , we then have x → u ∈ Kc (q ′ ) by Lemma 93. Thus, by u ∈ SrcVars→ (q ′ ) we obtain x ∈ ReachK(q′ ) (u), which implies x ∈ ReachK(q) (u). Hence, composing with the edge x → u0 ∈ Ki (q) we obtain u0 ∈ ReachK(q) (u), a contradiction. We conclude by contradiction that SrcVars→ (q ′ ) ⊆ SrcVars→ (q). ◁ ◀

This concludes the proof.

▶ Lemma 99. Let q ∈ sjfBCQU,A be a saturated and normal. Let F ∈ q i be extendable. If (db′ , q ′ ) = ConsEdgeElimF (db, q) ∈ / {true, false}, then GuardedVars(q) = GuardedVars(q ′ ). Proof. Let v ∈ GuardedVars(q). Then, there exists u ∈ GuardVars(q) such that u → v ∈ Kc (q). In particular, u ∈ / Y , since Y ∩ RootVars⇝ (q) = ∅ (and, by definition, GuardVars(q) ⊆ RootVars⇝ (q)). By Lemma 94 we obtain u ∈ GuardVars(q ′ ), and by Lemma 93 we have u → v ∈ Kc (q ′ ). Hence u ∈ GuardedVars(q ′ ). Conversely, assume v ∈ GuardedVars(q ′ ). Then, we find u ∈ GuardVars(q ′ ) such that u → v ∈ Kc (q ′ ). Note that u ∈ / Y ; otherwise, if u ∈ Y , we obtain x → u ∈ K(q ′ ), which together with Y ⊆ NotKeyVars(q ′ ) implies u ∈ / SrcVars→ (q), a contradiction. (Recall that by definition, GuardVars(q ′ ) ⊆ SrcVars→ (q ′ ).) Now, by Lemma 94 we obtain u ∈ GuardVars(q), and by Lemma 93 we have u → v ∈ Kc (q). Hence u ∈ GuardedVars(q). ◀ ▶ Lemma 100. Let q ∈ sjfBCQU,A be a saturated and normal. Let I ∈ q i be extendable. If (db′ , q ′ ) = ConsEdgeElimI (db, q) ∈ / {true, false}, then (a) q ′ ∈ sjfBCQU,A ; (b) q ′ is saturated; (c) q ′ is normal. Proof. Let us write F ′ for the atom corresponding to F ∈ q in q ′ ; that is, F ′ = F for F = ̸ R and F ′ = R′ (x, ⃗y , ⃗z) for F = R(x, ⃗y ). q′

q

(Item (a)) By Lemma 92, it suffices to show that if F ′ ⇝ G′ , then F ⇝ G. Suppose q

′

F ′ ⇝ G′ . Then Gaifman(q ′ ) contains an (undirected) path U = x1 , . . . , xℓ

(ℓ ≥ 1)

62

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

between some x1 ∈ NonKeyVars(F ′ ) and xn ∈ Vars(G′ ) such that U is not separated by +,q ′ (F ′ ) . Assume toward contradiction that U is separated by F +,q . Then K(q \ {F }) contains a directed graph D = t, . . . , xi , where t ∈ {Key(F ), ⊥}. Since, for each H ′ ∈ q ′ , Key(H) = Key(H ′ ) ∈ / Y , we obtain t ∈ / Y. We may assume that D is the shortest path witnessing xi ∈ F +,q . In particular, D is simple. Then, an edge u → v, where u ∈ Y , appears in D. In particular, u ̸= t. ▷ Claim 101. Assume that an edge u → v, where u ∈ Y , appears in D. Then v ∈ Z, and u is preceded in D by x. Moreover, u → v ∈ K⇝ (q). Proof. Since t ∈ / Y , we have u = ̸ t. Hence u is preceded in D by some vertex w. That is, the edge w → u precedes the edge u → v in D. We prove that w = x. Since u ∈ Y , by Item 1 we have u → v ∈ Kc (q). If w → u ∈ Kc (q), we obtain by Lemma 14 that w → v ∈ Kc (q), which implies D is not a shortest path witnessing xi ∈ F +,q , a contradiction. Hence, assume w → u ∈ Ki (q). Since also x → u ∈ Ki (q), we obtain by Lemma 59 that x = w. To complete the proof, we prove u → v ∈ K⇝ (q) and v ∈ Z. We now have x → u ∈ Ki (q) and u → v ∈ K(q) ∩ Kc (q). If u → v ∈ / K⇝ (q), then by Lemma 67 x → v ∈ Kc (q), in which ∗ := case the path D t, . . . x, v, . . . , xi witnesses xi ∈ F +,q , contradicting the minimality of D. Hence u → v ∈ K⇝ (q), which also entails v ∈ Z. ◁ By Claim 101, we can write D = t, . . . x, u, v, . . . , xi , where v ∈ Z, and possibly t = x or v = xi . Since x → u ∈ Ki (q), and R ∈ q is the unique atom in q generating x → u, we obtain R = ̸ F. In particular, R′ ̸= F ′ , which entails x → v ∈ K(q \ {F ′ }) due to v ∈ Z. We now claim that the paths D[t : x] and D[v : xi ] belong also to K(q \ {F ′ }). This entails +,q ′ xi ∈ (F ′ ) , contradicting the assumption. Recall now q0 from (13). By Claim 101, if some edge in D[t : x] or D[v : xi ] is generated by an atom of q0 , then x appears twice in D, contradicting the minimality assumption. Since K(q \ ({F } ∪ q0 )) ⊆ K(q ′ \ {F ′ }), we obtain that each edge in D[t : x] or D[v : xi ] belongs to K(q ′ \ {F ′ }). This creates a contradition, as described above. We conclude by contradiction that U is not separated by F +,q q

If U is a path between NonKeyVars(F ) and Vars(G), then F ⇝ G. Otherwise, suppose U is not a path of Gaifman(q) between NonKeyVars(F ) and Vars(G). Then there is at least one z ∈ Z such that one of the following cases applies: Case A: z appears as an endpoint in U and belongs to NonKeyVars(F ′ ) (resp. Vars(G′ )), while z does not belong to NonKeyVars(F ) (resp. Vars(G)). (Informally, F or respectively G is R.)

M. Hannula

Case B: {u, z}, for some u ∈ {x} ∪ Y , is an edge in U which does not belong to Gaifman(q). (Informally, U contains an edge generated by R but not R′ .) For each such z, choose an arbitrary y ∈ Y such that y → z ∈ K⇝ (q). Then, proceed in cases as follows: Case A: extend the endpoint z with the edge {y, z}. Case B: replace the edge {u, z} with the edges {u, x}, {x, y}, {y, z} when u ∈ Y , and with the edges {u, y}, {y, z} when u = x. Denote by U ′ the undirected path obtained from U by treating each occurring case in this way. Then, U ′ is a path between NonKeyVars(F ) and Vars(G). We claim that U ′ is not separated by F +,q . Assume toward contradiction that U ′ is separated by F +,q . As we have already established that U is not separated by F +,q , we obtain that x or y belongs to F +,q . Since x → y ∈ K(q \ {F }) (due to R = ̸ F ), and y → z ∈ Kc (q) ⊆ K(q \ {F }) (due to Item 1), we obtain z ∈ F +,q . As z belongs to U , this contradicts the fact that U is q not separated by F +,q . Hence U ′ is not separated by F +,q . In particular, we obtain F ⇝ G. This concludes the proof of the first item. (Item (b)) Suppose that for some F ′ ∈ q ′ , we have u → v ∈ K(F ′ ), v → w ∈ Kc (q ′ ), and u → w ∈ K∗ (q ′ \ {F ′ }). We need to prove that u → w ∈ Kc (q ′ ) We show first that u → w ∈ Kc (q). For this, we first prove two helping claims. ▷ Claim 102. v → w ∈ Kc (q). Proof. By assumption there are G′ ∈ q ′ and H ′ ∈ q ′ \ {G′ } such that v → w ∈ K(G′ ) and v → w ∈ K∗ (H ′ ). We claim that v → w ∈ K(G). Toward contradiction, suppose v → w ∈ / K(G). Then G′ = R′ , v = x, and w ∈ Z. In this case, since G′ = ̸ H ′ , we have H ′ = H ∈ q. Now, either x → w or ⊥ → w belongs to K(H ′ ). The former case violates Lemma 66, because there exists y ∈ Y such that x → y ∈ Ki (q) and y → z ∈ K⇝ (q). In the latter case, we have y → w ∈ K⇝ (q) ∩ Kc (q) (by Item 1), for some y ∈ Y . However, by normality of q, we also have ⊥ → w ∈ Ki (q), which creates a contradiction with Lemma 69. Hence v → w ∈ K(G). If also v → w ∈ K∗ (H), then the claim follows. Thus, assume v → w ∈ / K∗ (H). Then ′ ′ ′ ′ ′ H = R and w ∈ Z. In this case, since G ̸= H , we have G = G ∈ q. In particular, v → w ∈ K(q). Since w ∈ Z, we obtain y → w ∈ K⇝ (q), for some y ∈ Y . By Item 1, it holds that y → w ∈ Kc (q). Hence, v → w ∈ Kc (q) by Lemma 69, establishing the claim. ◁ ▷ Claim 103. u → w ∈ K∗ (q \ {F }). Proof. Let D = t, . . . , w be a path in K(q ′ \ {F ′ }) where t ∈ {u, ⊥}. Then, every edge from D belongs to K(q \ {F }), except possibly for an edge of the form x → z, z ∈ Z, that has been generated by R′ . In this case, R′ ̸= F ′ , and the edge can be replaced with two edges x → y, y → z, where y ∈ Y . In particular, the edge x → y is generated by R ̸= F , and the edge y → z is generated by an atom G ∈ q that does not appear in q ′ (hence G ̸= F ). This proves the claim. ◁ Let us then consider two alternative cases.

63

64

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Case u → v ∈ K(F ′ ). Then, Claims 102 and 103 and the saturation of q imply u → w ∈ Kc (q). Case u → v ∈ / K(F ′ ). Then F ′ = R′ , u = x, and v ∈ Z. In this case, however, we find y ∈ Y such that u → y ∈ K(F ) and y → v ∈ K⇝ (q). Moreover, we have y → v ∈ Kc (q) by Item 1. Then, Claim 102 and Lemma 14 yield y → w ∈ Kc (q). Then, using Claim 103 and the saturation of q, we obtain u → w ∈ Kc (q). Hence we have proven that u → w ∈ Kc (q). To finish the proof of the item, assume toward contradiction that u → w ∈ / Kc (q ′ ). By the construction of q ′ , it is correct to conclude that u ∈ Y . However, by assumption q ′ includes the atom F ′ such that Key(F ′ ) = u. This contradicts the fact that Y ⊆ NotKeyVars(q ′ ). We conclude by contradiction that u → w ∈ Kc (q ′ ). (Item (c)) In what follows we consider an atom F ′ ∈ q ′ . Toward contradiction, suppose q ′ is not normal. We consider the different cases of normality in the following. (Item 1) Suppose that |NonKeyVars(F ′ )| > 1, and p → u ∈ Kc (q ′ ), for p = Key(F ′ ) and some u ∈ NonKeyVars(F ′ ). Then p → u ∈ K(F ′ ), and there exists G′ ∈ q ′ \ {F ′ } such that p → u ∈ K∗ (G′ ). Case 1: F ′ ̸= R′ . Then F = F ′ , hence |NonKeyVars(F )| > 1 and p → u ∈ K(F ). If p → u ∈ K∗ (G), then p → u ∈ Kc (q), contradicting the normality of q. Suppose thus that p → u ∈ / K∗ (G). This implies G = R and u ∈ Z. Hence, we find y ∈ Y such that ⇝ y → u ∈ K (q), and consequently, by Item 1, y → u ∈ Kc (q). Thus, by p → u ∈ K(q) and Lemma 69 we obtain p → u ∈ Kc (q). This contradicts the normality of q. Case 2: F ′ = R′ . Then p = x and u ∈ Y ∪ Z. Since G′ ̸= F ′ , we obtain G = G′ and hence x → u ∈ K∗ (G). Moreover, we have F = R. Suppose that x → u ∈ / K(F ). Since x → u ∈ K(F ′ ), this entails u ∈ Z. From x → u ∈ K∗ (G) we obtain that there exists v ∈ {x, ⊥} such that v → u ∈ K(q). From this and u ∈ Z, we obtain v → u ∈ Kc (q) using again Lemma 69. By normality of q, then, v = ̸ ⊥, i.e., v = x. However, x → u ∈ K(q) contradicts Lemma 66. Suppose then that x → u ∈ K(F ). From x → u ∈ K∗ (G) and G = ̸ F it follows that x → u ∈ Kc (q). However, we have F = R, and thus by the assumption that R ∈ q i , it follows that x → u ∈ Ki (q), a contradiction. (Item 2) Suppose toward contradiction that u → v ∈ Kc (q ′ ), for some distinct u, v ∈ NonKeyVars(F ′ ). Then, in particular, u → v ∈ K(q ′ ). It follows that u ∈ / Y ∪ Z, since ′ ′ ′ Y ∪ Z ⊆ NotKeyVars(q ). Since NonKeyVars(R ) ⊆ Y ∪ Z, we obtain F ̸= R′ , and hence F ′ = F . Now, u → v ∈ Kc (q ′ ) means that there exist G′ ∈ q ′ and H ′ ∈ q ′ \ {G′ } such that u → v ∈ K(G′ ) and u → v ∈ K∗ (H ′ ). We claim that u → v ∈ K(G). Toward contradiction, suppose u → v ∈ / K(G). Since u → v ∈ K(G′ ), this entails G = R, u = x, and v ∈ Z. Then H ′ ̸= R′ , i.e., H ′ = H and we have that x → v or ⊥ → v belongs to K(H). The first case contradicts Lemma 66. The second case entails, by normality, that ⊥ → v ∈ Ki (q); this, however, contradicts Lemma 69 due to y → v ∈ Kc (q) ∩ K⇝ (q), for some y ∈ Y . The claim thus follows by contradiction. If u → v ∈ K∗ (H), then by the above claim we obtain u → v ∈ Kc (q). Since u, v are distinct variables in NonKeyVars(F ), this contradicts the normality of q. Thus, assume u→v∈ / K∗ (H). Since u → v ∈ K∗ (H ′ ), this entails H = R and v ∈ Z. Since u → v ∈ K(q)

M. Hannula

and v ∈ Z, we obtain u → v ∈ Kc (q) using again Lemma 69. As above, this contradicts the normality of q. (Item 3) Suppose, toward contradiction that u → v, v → u ∈ Kc (q ′ ), for some distinct u, v ∈ Vars(q ′ ). In particular, u → v, v → u ∈ K(q ′ ). Since Y ⊆ NotKeyVars(q ′ ), we obtain u, v ∈ Vars(q) \ Y , hence Lemma 93 entails u → v, v → u ∈ Kc (q), a contradiction with the normality of q. (Item 4) Suppose toward contradiction that ⊥ → z ∈ Kc (q ′ ), for some z ∈ Vars(q ′ ). Then ⊥ → z ∈ K(G′ ) ∩ K(H ′ ), for some distinct G′ , H ′ ∈ q ′ . Now, ⊥ → z ∈ / K(G) ∩ K(H) due to the normality of q. Suppose, by symmetry, that ⊥ → z ∈ / K(G). This is only possible when G = R and z ∈ Z. Since G′ , H ′ are distinct, so are G, H, and we obtain H ′ = H. In particular, we have ⊥ → z ∈ K(H), i.e., ⊥ → z ∈ K(q). Using Lemma 69, we again obtain ⊥ → z ∈ Kc (q), but this contradicts the normality of q. ◀ ▶ Lemma 104 (Consistent Edge Elimination). Let C consist of all (db, q) ∈ DB × sjfBCQU,A , where q is a saturated and normal query and db is a q-saturated database. For each (db, q) ∈ C and extendable F ∈ q i , (db, q) 7→ ConsEdgeElimF (db, q) is a strict, guarded, equivalence-preserving, and polynomial-time reduction from C to C ∪ {true, false}. Proof. Recall that we write Y = NonKeyVars(F ) and Z = OutK⇝ (q) (Y ). Recall that both Y and Z are non-empty by definition. The reduction ConsEdgeElimF is clearly strict and computable in polynomial time. It is into C ∪ {true, false} by Lemmas 9 and 100. It suffices to prove that it is guarded and equivalence-preserving. (Guardedness) Items 5 and 6 of guardedness follow by by Lemmas 94 and 99. Items 2–3, 7, and 8 are clear by construction. We prove Items 1 and 4. For Item 4, assume that G ∈ q c , and either Key(G) ∈ GuardVars(q) or Vars(G) = ∅. Toward contradiction, suppose first that G ∈ / q ′ . Then, by construction, Key(G) ∈ Y or G = F . The former case is not possible since Y ∩ GuardVars(q) = ∅. The latter case is not possible since F ∈ q i by the definition of extendability. This proves that G ∈ q ′ . Moreover, c i G ∈ (q ′ ) , because G ∈ (q ′ ) means that there exists an edge u → v ∈ Ki (q ′ ) ∩ K(G). Since Y ⊆ NotKeyVars(q ′ ), this would imply u ∈ / Y . Thus, by Lemma 93, we would obtain u → v ∈ Ki (q), which entails G ∈ q i , a contradiction. Hence, Item 4 holds. For Item 1, assume that for each S ∈ q, |S db ↾V | ≤ N, where V := Vars(S)∩NotGuardedVars(q). By Lemma 99, and due to Vars(q) = Vars(q ′ ), we have NotGuardedVars(q) = NotGuardedVars(q ′ ). Let S ∈ q \ (q0 ∪ {R}). Then by Item 3 of guardedness (whose verification we omitted), ′ ′ we obtain S db ≤ S db . Hence, by assumption we obtain |S db ↾V ′ | ≤ |S db ↾V | ≤ N, where V ′ := Vars(S) ∩ NotGuardedVars(q ′ ) and V := Vars(S) ∩ NotGuardedVars(q) (i.e., V ′ = V ). Consider then the atom R′ ∈ q ′ . Since Z ⊆ GuardedVars(q), by Lemma 99 we obtain Z ⊆ GuardedVars(q ′ ). In particular, Z ∩ NotGuardedVars(q ′ ) = ∅. Hence, writing V ′ := Vars(R′ ) ∩ NotGuardedVars(q ′ ) and V := Vars(R) ∩ NotGuardedVars(q), we have V ′ = V ′ by Lemma 99. By assumption and the construction of db′ , this leads to |(R′ )db ↾V ′ | = |Rdb ↾V | ≤ N . Hence, Item 1 holds, too. We may thus conclude that the stated reduction is guarded.

65

66

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

(Equivalence-preservation) By Lemma 9 it suffices to prove that (db, q) ∈ CERTAINTY if and only if (db0 , q ′ ) ∈ CERTAINTY, assuming db0 and q ′ are as in (16) and (14). (⇒) Suppose (db, q) ∈ CERTAINTY, and let r′ be an arbitrary repair of db0 . Let r := (r′ \ r′ ↾R′ ) ∪ {R(a, ⃗b) ∈ db | ∃⃗c : R′ (a, ⃗b, ⃗c) ∈ r′ } ∪ db↾q0 . Note that db↾q0 is consistent by (15) and the q-saturation of db. Also, {R(a, ⃗b) ∈ db | ∃⃗c : R(a, ⃗b, ⃗c) ∈ r′ } is consistent since r′ is consistent. Moreover, since db is q-saturated, for each R(a, ⃗b) ∈ db there exists a (unique) extension R′ (a, ⃗b, ⃗c) ∈ db0 . Hence it can be seen that r is a repair of db. Since r |= q by assumption, there exists a valuation θ on Vars(q) such that θ(q) ⊆ r. In particular, we obtain θ(q ′ \ {R′ }) ⊆ r′ and θ(R) ∈ r. We claim that θ(R′ ) ∈ r′ . Let ⃗c be the (unique) sequence of constants such that R′ (θ(x), θ(⃗y ), ⃗c) ∈ r′ . Let i ∈ [ℓ]. By definition we have Si (θ(yji ), ci , −) ∈ db. Since yji → zi ∈ Kc (q), q is normal, and db is q-saturated, it follows that db↾Si is consistent. In particular, we have Si (θ(yji ), ci , −) ∈ r. Since Si (θ(yji ), θ(zi ), −) ∈ r, it is the case that θ(zi ) = ci . This proves θ(R′ ) ∈ r′ . Hence r′ |= q ′ , which leads to (db0 , q ′ ) ∈ CERTAINTY. (⇐) Suppose (db0 , q ′ ) ∈ CERTAINTY, and let r be an arbitrary repair of db. Let r′ := (r \ r↾q0 ∪{R} ) ∪ {R′ (a, ⃗b, ⃗c) ∈ db0 | R(a, ⃗b) ∈ r}. Since r is consistent, for each ⃗a there exists at most one ⃗b such that R(a, ⃗b) ∈ r. Moreover, for each R(a, ⃗b) ∈ r, there is precisely one extension R(a, ⃗b, ⃗c) ∈ db0 ; this follows by definition since yji → zi ∈ Kc (q), for each i ∈ [ℓ], and db is q-saturated. Hence, {R′ (a, ⃗b, ⃗c) ∈ db0 | R(a, ⃗b) ∈ r} is consistent. Furthermore, since r is a repair, for each R′ (a, ⃗b, ⃗c) ∈ db0 there exists a fact R(a, ⃗b′ ) ∈ r with the same primary-key value. Now, for each i ∈ [ℓ], as Si (yji , zi , −) ∈ q and db is q-saturated, there is a (unique) fact of the form Si (b′ji , c′i , −) ∈ db. Hence, setting ⃗c′ := (c′ , . . . , c′ ), we obtain R′ (a, ⃗b′ , ⃗c′ ) ∈ db0 . Thus we may conclude that r′ 1

ℓ

picks precisely one fact from each R′ -block of db0 . It follows that r′ is a repair of db0 . By assumption we find a valuation θ such that θ(q ′ ) ⊆ r′ . We prove that θ(q) ⊆ r. Clearly, it holds θ(q \ q0 ) ⊆ r. Let H ∈ q0 . Then Key(H) ∈ Y , and as observed in (15), H ∈ q c . In particular, we can write H = S(y, v1 , . . . , vℓ ), where y ∈ Y , y ∈ / {v1 , . . . , vℓ }, and y → vi ∈ Kc (q) whenever vi is a variable. Note that db↾S is consistent, which means that db↾S = r↾S . We prove θ(H) ∈ r. If NonKeyVars(H) = ∅, then, since db is q-saturated and θ(R) ∈ r, the reader can verify that θ(H) ∈ r. Thus, suppose NonKeyVars(H) ̸= ∅. Then, by the saturation and normality of q, H is of the form S(y, z, ⃗c), where z is a variable such that y → z ∈ Kc (q) and ⃗c is a (possibly empty) sequence of constants Let us first isolate a single variable v ∈ NonKeyVars(H), and write H = S(y, v, −). We prove the following claim. ▷ Claim 105. S(θ(y), θ(v), −) ∈ db. Proof. Suppose first that y → v ∈ K⇝ (q). Then v ∈ Z, and in particular v = zi , for some i ∈ [ℓ]. From R′ (θ(x), θ(⃗y ), θ(⃗z)) ∈ r′ we obtain Si (θ(yji ), θ(v), −) ∈ db, where

M. Hannula

67

yji → v ∈ Kc (q). Note that we also have R(θ(x), θ(⃗y )) ∈ db. Since y ∈ Y (i.e., y is listed in ⃗y ) and y → v ∈ Kc (q), we obtain S(θ(y), θ(v), −)) ∈ db by q-saturation of db (collision consistency). Suppose then that y → v ∈ / K⇝ (q). Since y → v ∈ K(q) ∩ Kc (q) and x → y ∈ Ki (q), we c obtain x → v ∈ K (q). Let T (x, v, −) ∈ q c be an atom generating x → v. Note that x ∈ / Y due to variable-repetition-freeness of q. Then, as T = ̸ R due to R ∈ q i , ′ ′ ′ we obtain T ∈ q \ (q0 ∪ {R}) ⊆ q . Hence θ(q ) ⊆ r implies T (θ(x), θ(v), −) ∈ r. Since furthermore R(θ(x), θ(⃗y )) ∈ db, y → v ∈ Kc (q), and y ∈ Y (i.e., y is a variable listed in ⃗y ), it follows by q-saturation of db that S(θ(y), θ(v), −) ∈ db. This proves the claim. ◁ Since db↾S is consistent and db is q-saturated, the claim implies θ(H) = S(θ(y), θ(v), ⃗c) ∈ r. Thus θ(q) ⊆ r, concluding the proof. ◀

E.6

Inconsistent Edge Elimination

We say that S ∈ q i , with Z := NonKeyVars(S), is eliminable if the following conditions hold: 1. Key(S) ∈ ReachK⇝ (q) (⊥) ∩ NotRootVars⇝ (q); 2. Z ⊆ LeafVars⇝ (q) ∩ NotKeyVars(q) ∩ GuardedVars(q); 3. Z ̸= ∅. Let S(y, ⃗z) ∈ q i be eliminable. We define a query q ′ by two cases. (i) The incoming edge of y in K⇝ (q) is of the form x → y ∈ Ki (q) generated by R(x, y, ⃗u) ∈ q i . We define q ′ := (q \ {R(x, y, ⃗u), S(y, ⃗z)})) ∪ {R′ (x, y, ⃗u, ⃗z)}.

(18)

(ii) The incoming edge of y in K⇝ (q) is of the form y ′ → y ∈ Kc (q) generated by T (y ′ , y, −) ∈ q c . Consequently, there exists an edge of the form x → y ′ ∈ Ki (q) generated by R(x, y ′ , ⃗u) ∈ q i . We define q ′ := (q \ {R(x, y ′ , ⃗u), S(y, ⃗z)}) ∪ {R′ (x, y ′ , ⃗u, ⃗z)}.

(19)

Note that Vars(q) = Vars(q ′ ) and Z ⊆ NotKeyVars(q ′ ). For a database db, define first a database db0 in the above two cases. ⃗ | R(a, b, ⃗c), S(b, d) ⃗ ∈ db}. (i) db0 := (db \ db↾{R,S} ) ∪ {R′ (a, b, ⃗c, d) ⃗ | R(a, b′ , ⃗c), T (b′ , b, −), S(b, d) ⃗ ∈ db}. (ii) db0 := (db \ db↾{R,S} ) ∪ {R′ (a, b′ , ⃗c, d) Then, define InconsEdgeElimS (db, q) := (db′ , q ′ ),

(20)

where db′ := DBSaturate(db0 , q ′ ). Before moving on to the reduction lemma concerning InconsEdgeElimS , let us first consider the following example which illustrates why the root of Key(S) in K⇝ (q) needs to be ⊥.

68

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

z

w

w

“InconsEdgeElimS ”

y

v

x

u

y

z

x

v

u

Figure 7 Illustration of attack-propacation graph: left K⇝ (q), right K⇝ (q ′ ). Guarded variables are in blue and unguarded ones in red.

Note that this restriction is unique to the inconsistent edge elimination; all other reduction steps allow the root of the modified variable or atom to be a variable. ▶ Example 106. Consider the following query from sjfBCQU : q := {R(x, y), S(y, z), T (u, v)} ∪ {Ui (w, z), Vi (w, v), Wi (u, z) | i ∈ {0, 1}}. Observe that q is saturated and normal. The root variables are x, u, w, the guarded variables are x, u, w, z, v, and the only unguarded variable is y. However, in contrast to the requirements of inconsistent edge elimination w.r.t. S, we have that Key(S) = x ̸= ⊥. Now, applying inconsistent edge elimination to q, would yield the query q ′ := {R(x, y, z), T (u, v)} ∪ {Ui (w, z), Vi (w, v), Wi (u, z) | i ∈ {0, 1}}. For illustrations, see Figure 7. Now, q has an acyclic attack graph, but q ′ has a cyclic attack graph due to R ⇝ T and T ⇝ R. In particular, T does not attack R in the query q. Consider then the queries qx7→c and qx7′ →c , for some constant. The attack-propagation graphs K⇝ (qx7→c ) and K⇝ (qx7′ →c ) are then obtained from those of q and q ′ by replacing the vertex x with ⊥. In this case, atom elimination w.r.t. S on qx7→c yields qx7′ →c , and both queries have an acyclic attack graph. Now, let us start with the preparatory results, as in earlier sections. ▶ Lemma 107. Let q ∈ sjfBCQ be saturated and normal. Let S ∈ q i be eliminable. Let u, v ∈ / Z, where Z := NonKeyVars(I). If (db′ , q ′ ) = InconsEdgeElimS (db, q) ∈ / Vars(q) be such that v ∈ ′ {true, false}, then q is variable-repetition-free. Proof. Consider first Item (i). Given that q is repetition-free, repetition can only arise if x appears in ⃗z or if ⃗z and ⃗u share a variable. In the first case, we obtain that K⇝ (q) contains two edges x → y and y → x, contradicting Lemma 65. In the second case, we obtain that NonKeyVars(R) contains two distinct variables y and z, where z is the common variable of ⃗z and ⃗u, such that y → z ∈ K(q), contradicting Lemma 72. Consider then Item (ii). In this case, repetition can only arise if x or y ′ appears in ⃗z or if ⃗u and ⃗z share a variable. In the first case, we obtain a contradiction with Lemma 65 analogously to the previous case. Considering the second case, suppose z is a variable appearing in both

M. Hannula

69

⃗u and ⃗z. Then, x → z and y → z are both edges in Ki (q). Since x ̸= y, due to acyclicity of K⇝ (q), we obtain a contradiction with Lemma 16. We conclude that in both cases q ′ is variable-repetition-free.

◀

▶ Lemma 108. Let q ∈ sjfBCQ be saturated and normal. Let S ∈ q i be eliminable. Let u, v ∈ Vars(q) be such that v ∈ / Z, where Z := NonKeyVars(I). If (db′ , q ′ ) = InconsEdgeElimS (db, q) ∈ / {true, false}, then u → v ∈ K(q) implies u → v ∈ K(q ′ ) u → v ∈ Ki (q) implies u → v ∈ Ki (q ′ ) u → v ∈ Kc (q) if and only if u → v ∈ Kc (q ′ ) The third item holds unconditionally, that is, even if v ∈ Z. ̸ v. The first item is clear, Proof. By Lemma 107 it suffices to focus on the case where u = and the second item follows from the first and the third item. Thus, we prove the third item. Let us write I ′ for the atom in q ′ corresponding to an atom I in q. That is, R′ := R, S ′ is undefined, and I ′ := I for I ∈ q \ {R, S}. Assume that u → v ∈ Kc (q). Then we find distinct G, H ∈ q such that u → v ∈ K(G) and u → v ∈ K∗ (H). We observe that G ∈ / {R, S} because R, S ∈ q i , hence G′ = G and ′ ∗ u → v ∈ K(G ). Furthermore, u → v ∈ K (H) implies u → v ∈ K(H) or ⊥ → v ∈ K(H). In the first case, we obtain u → v ∈ K(H ′ ), as above. In the second case, since y is a variable we have H ̸= S, hence ⊥ → v ∈ K(H ′ ) follows. Thus we conclude that u → v ∈ K∗ (H) implies u → v ∈ K∗ (H ′ ). This leads to u → v ∈ Kc (q ′ ). For the converse direction, assume that u → v ∈ Kc (q ′ ). Then we find distinct G′ , H ′ ∈ q such that u → v ∈ K(G′ ) and u → v ∈ K∗ (H ′ ). If u → v ∈ K(G) and u → v ∈ K∗ (H), then u → v ∈ Kc (q). Thus, suppose first that u → v ∈ / K(G). This is only possible when G = R, u = x, and v ∈ Z. Since G and H are distinct, we have H = H ′ and consequently u → v ∈ K∗ (H). Then we have x → v ∈ K(H) or ⊥ → v ∈ K(H). The first case contradicts Lemma 66, and the second case entails ⊥ → v ∈ Kc (q) by Lemma 16, y → v ∈ Ki (q), and y = ̸ ⊥, contradicting the normality of q. Thus this is case is not possible. Suppose then that u → v ∈ K(G) and u → v ∈ / K∗ (H). This is only possible when H = R and v ∈ Z. Moreover, we have that x = u or x = ⊥. If x = u, then x → v ∈ K(q) and Lemma 66 lead to a contradiction. If u = ⊥, then again we obtain ⊥ → v ∈ Kc (q) in contradiction with the normality of q. Hence we conclude that u → v ∈ Kc (q).

◀

▶ Lemma 109. Let q ∈ sjfBCQ be saturated and normal. Let S ∈ q i be eliminable. If (db′ , q ′ ) = InconsEdgeElimS (db, q) ∈ / {true, false}, then GuardVars(q) = GuardVars(q ′ ). Proof. We need to prove RootVars⇝ (q) ∩ SrcVars→ (q) = RootVars⇝ (q ′ ) ∩ SrcVars→ (q ′ ). The proof is divided into separate claims. ▷ Claim 110. RootVars⇝ (q) ⊆ RootVars⇝ (q ′ ).

70

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Proof. Toward contradiction, suppose that u ∈ RootVars⇝ (q) \ RootVars⇝ (q ′ ). Then there exists an edge of the form w → u ∈ K⇝ (q ′ ). In particular, w → u ∈ K(q ′ ), which leads to w ̸= u due to Lemma 107. Consider two cases. Suppose first that w → u ∈ Ki (q ′ ). Then we have w → u ∈ / Kc (q) by Lemma 108. Since ⇝ u ∈ RootVars (q), we also have w → u ∈ / Ki (q). Therefore, w → u ∈ K(q ′ ) \ K(q), which is only possible when w = x and u ∈ Z. However, in this case u ∈ / RootVars⇝ (q) due to the i edge y → u ∈ K (q), for some y ∈ Y , a contradiction. Thus the case that w → u ∈ Ki (q ′ ) is not possible. Suppose then that w → u ∈ Kc (q ′ ). Since w = ̸ u, we have that w → u ∈ K(q). Now, we i ′ find another edge p → w ∈ K (q ) such that p → u ∈ / Kc (q ′ ). By Lemma 108 we also have c c w → u ∈ K (q) and p → u ∈ / K (q). Since u ∈ RootVars⇝ (q), it holds that p → w ∈ / Ki (q) ⇝ c (otherwise, w → u ∈ / K (q)). Moreover, by Lemma 14 we have p → w ∈ / K (q). Summing up, p → w ∈ K(q ′ )\K(q), and thus p = x and w ∈ Z. In particular, it follows that x → u ∈ / Kc (q). We deal with the two cases separately. In the case of Item (i), we find y ∈ Y such that y → w ∈ Ki (q) and w → u ∈ Kc (q), while w →u∈ / K⇝ (q) due to u ∈ RootVars⇝ (q). Recalling that w → u ∈ K(q), this leads to y → u ∈ Kc (q). Since y ∈ NotRootVars⇝ (q), we have that u = ̸ y, leading to y → u ∈ K(q). Then, by x → y ∈ Ki (q) and y → u ∈ / K⇝ (q), it follows that x → u ∈ Kc (q), a contradiction. In the case of Item (ii), we find y ∈ Y such that y → u ∈ Kc (q) obtains similarly, and consequently also y ′ → u ∈ Kc (q) transitively via y ′ → y ∈ Kc (q). Since y ′ ∈ NotRootVars⇝ (q) due to the edge x → y ∈ Ki (q), we obtain y ′ ̸= u, leading to y ′ → u ∈ K(q) Then, we obtain x → u ∈ Kc (q) from x → y ′ ∈ Ki (q), y ′ → u ∈ Kc (q) ∩ K(q), and y ′ → u ∈ / K⇝ (q). Again, this leads to a contradiction. Hence neither the case that w → u ∈ Kc (q ′ ) is possible. We conclude by contradiction that RootVars⇝ (q) ⊆ RootVars⇝ (q ′ ). ◁ ▷ Claim 111. RootVars⇝ (q ′ ) ⊆ RootVars⇝ (q). Proof. Suppose u ∈ / RootVars⇝ (q). By assumption there exists an edge of the form w → u ∈ ⇝ K (q). Since q is variable-repetition-free, we have w ̸= u. Suppose first that w → u ∈ Ki (q). If u ∈ / Z, then w → u ∈ Ki (q ′ ) by Lemma 108, i.e., ⇝ ′ u∈ / RootVars (q ). Thus, suppose u ∈ Z. Then, we have x → u ∈ K(R′ ). If x → u ∈ Ki (q ′ ), we are done, so assume that x → u ∈ Kc (q ′ ). Then, we find G ∈ q ′ \ {R′ } such that x → u ∈ K∗ (G). In particular, we have t → u ∈ K(G), where t ∈ {x, ⊥}. Note that it holds that G ∈ q \ {R}. Thus, by Lemma 66, the case where t = x is not possible, i.e., ⊥ → u ∈ K(G). Since q is normal, it holds that ⊥ → u ∈ Ki (G). But then, since y = ̸ ⊥ and i y → u ∈ K (q), we obtain a contradiction with Lemma 16. Then, suppose w → u ∈ Kc (q). Then, we find another edge p → w ∈ Ki (q) such that p → u ∈ / Kc (q). In this case, by Z ⊆ LeafVars⇝ (q) we obtain w ∈ / Z. Note that also u∈ / Z; if this were not the case, we would have w → u ∈ Kc (q) ∩ K⇝ (q) and y → u ∈ Ki (q), contradicting Lemma 69. Consequently, Lemma 108 implies p → w ∈ Ki (q ′ ), w → u ∈ Kc (q ′ ), and p → u ∈ / Kc (q ′ ). Since w = ̸ u, we also have w → u ∈ K(q ′ ). This leads to to ⇝ ′ w → u ∈ K (q ), i.e., u ∈ / RootVars⇝ (q ′ ). ◁ ▷ Claim 112. SrcVars→ (q) ⊆ SrcVars→ (q ′ ).

M. Hannula

71

Proof. Toward contradiction, suppose u ∈ SrcVars→ (q) \ SrcVars→ (q ′ ). Then we find an edge u0 → u ∈ K(q ′ ) such that u0 ∈ / ReachK(q′ ) (u). Note that the edges in K(q ′ ) \ K(q) are of the form x → z, where z ∈ Z. However, u0 → u is not of this form; otherwise, due to Item 1, u ∈ ReachK(q) (⊥), contradicting the fact that u ∈ SrcVars→ (q), as ⊥ has no incoming edges in K(q). Hence u0 → u ∈ K(q), so u0 ∈ ReachK(q) (u) obtains by assumption. As above, we note that any path in K(q) from u to u0 does not include edges from K(q) \ K(q ′ ), all of which take the form y → z, where z ∈ Z. It is then correct to conclude that u0 ∈ ReachK(q′ ) (u), a contradiction. Hence SrcVars→ (q) ⊆ SrcVars→ (q ′ ) obtains. ◁ ▷ Claim 113. SrcVars→ (q ′ ) ⊆ SrcVars→ (q). Proof. Assuming u ∈ SrcVars→ (q ′ ), suppose toward contradiction that u ∈ / SrcVars→ (q). Then we find an edge u0 → u ∈ K(q) such that u0 ∈ / ReachK(q) (u). If u0 → u ∈ K(q ′ ), then by assumption u0 ∈ ReachK(q′ ) (u), which implies u0 ∈ ReachK(q) (u); for this, observe that any edge in K(q ′ ) \ K(q) proceeds from x to Z and is replaceable with two or three edges in K(q), depending on the case. However, this contradicts the fact that u0 ∈ / ReachK(q) (u). Thus, suppose u0 → u ∈ / K(q ′ ). This entails u0 = y and u ∈ Z. Then, we observe x → u ∈ K(q ′ ) while Z ⊆ NotKeyVars(q ′ ) (by Lemma 107 and Item 2), contradicting u ∈ SrcVars→ (q ′ ). We conclude by contradiction that SrcVars→ (q ′ ) ⊆ SrcVars→ (q). ◁ This concludes the proof.

◀

▶ Lemma 114. Let q ∈ sjfBCQ be saturated and normal. Let S ∈ q i be eliminable. If (db′ , q ′ ) = InconsEdgeElimS (db, q) ∈ / {true, false}, then GuardedVars(q) = GuardedVars(q ′ ). Proof. Assume first that v ∈ GuardedVars(q). Then there exists u ∈ GuardVars(q) such that u → v ∈ Kc (q). By Lemma 109 we obtain u ∈ GuardVars(q ′ ), and by Lemma 108 we obtain u → v ∈ Kc (q ′ ). Hence v ∈ GuardedVars(q ′ ). Conversely, assume v ∈ GuardedVars(q ′ ). Then there exists u ∈ GuardVars(q ′ ) such that u → v ∈ Kc (q ′ ). Again, by Lemmas 108 and 109 we obtain u ∈ GuardVars(q) and u → v ∈ Kc (q), hence v ∈ GuardedVars(q). ◀ ▶ Lemma 115. Let q ∈ sjfBCQU,A be a saturated and normal. Let S ∈ q be eliminable. If (db′ , q ′ ) = InconsEdgeElimS (db, q) ∈ / {true, false}, then (a) q ′ ∈ sjfBCQU,A ; (b) q ′ is saturated; (c) q ′ is normal. Proof. Let R(x, y, ⃗u), S(y, ⃗z) ∈ q i be the atoms witnessing that S is eliminable. Let us write Z = NonKeyVars(I). For F ∈ q, let F ′ be the corresponding atom in q ′ . In the case of (i) F ′ = F if F ∈ / {R, S}, R′ is as in Item (i), and S ′ is not defined. We define F ′ analogously in the case of (ii). Since S ′ is undefined, we obtain F ̸= S = ̸ G. Furthermore, we have Key(F ) = Key(F ′ ) for all F ∈ q.

72

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

(Item (a)) By Lemma 107, it suffices to prove that q ′ has an acyclic attack graph. For this, q′

q

we show that if F ′ ⇝ G′ , then F ⇝ G. Toward contradiction, suppose this is not the case, q

q′

i.e., F ′ ⇝ G′ and F ̸⇝ G, for some F, G ∈ q. q′

Now, F ′ ⇝ G′ implies Gaifman(q ′ ) contains an (undirected) path U = x1 , . . . , xℓ

(ℓ ≥ 1)

between some x1 ∈ NonKeyVars(F ′ ) and xn ∈ Vars(G′ ) such that U is not separated by +,q ′ (F ′ ) . Now, U is a path between NonKeyVars(F ) and Vars(G), unless, for some z ∈ Z, we have that z occurs as an endpoint of U without belonging to NonKeyVars(F ) ∪ Vars(G), or U contains an edge {w, z}, where w is a variable occurring in (x, ⃗u). We proceed in cases for each occurrence of such z ∈ Z in U . Item (i): Replace the edge {w, z} with the two edges {w, y} and {y, z}, or extend the endpoint z with the edge {y, z} Item (ii): Replace the edge {w, z} with the three edges {w, y}, {y, y ′ }{y ′ , z}, or extend the endpoint z with the two edges {y, y ′ }, {y ′ , z}. Denote by U ′ the undirected path obtained from U in this way. q

Since F ̸⇝ G, it holds that xi ∈ F +,q for some i ∈ [ℓ]. In the case that we have extended U to U ′ , we may have y ∈ F +,q (or, additionally, y ′ ∈ F +,q . However, in this case we obtain z ∈ F +,q , where the variable z appears in U , by y → z ∈ K(q \ {F }) (using S ̸= F , and, in the second case, also y → y ′ ∈ Kc (q)). Note that Key(F ) ̸= xi , because otherwise by Key(F ) = Key(F ′ ) we obtain xi ∈ (F ′ ) contradiction.

+,q ′

,a

Hence K(q \ {F }) contains a non-empty path D = t, . . . , xi , where t ∈ {⊥, Key(F )}. Suppose D is shortest among all paths witnessing xi ∈ F +,q . In particular, it is a simple path. Moreover, we observe K(q \ {F }) ⊆ K(q ′ \ {F ′ }) ∪ K(S).

(21)

+,q ′

Hence, xi ∈ / (F ′ ) implies D contains an edge of the form y → z ∈ K(S). Moreover, Z ⊆ NotKeyVars(q) implies z is the last node in D. Thus, D can be written as D = t, . . . , y, z, where z = xi and possibly t = y. By simplicity of D, no atom generates more than one edge in D. In particular, no edge in the prefix D[t, y] belongs to K(S). Hence, (21) entails D[t, y] is a path in K(q ′ \ {F ′ }). We now prove the following claim. ▷ Claim 116. t ̸= y.

M. Hannula

73

Proof. Assume toward contradiction that t = y. That is, D consists of the single edge y → z. Since y = ̸ ⊥, we obtain Key(F ) = y, and consequently, Key(F ′ ) = y. On the other ⇝ hand, RootOf (y) = ⊥, and thus by y ∈ ReachK⇝ (q) (x) we obtain RootOf ⇝ (x) = ⊥. Hence, K⇝ (q) has a path of the form D′ = ⊥, . . . , x, y, z, where possibly x = ⊥. We may assume that D′ is simple by Lemma 65. Hence D′ [⊥, x] is a path in K(q \ {F }). By (21), and since D′ [⊥, x] does not contain any edge from K(S) (by simplicity of D′ ), we conclude that D′ [⊥, x] is a path in K(q ′ \ {F ′ }). Moreover, since R′ ̸= F ′ by Key(R′ ) = x = ̸ y = Key(F ′ ) (which follows by Lemma 65), we have that x → z +,q ′ belongs to K(q ′ \ {F ′ }). Therefore, xi ∈ (F ′ ) , a contradiction. ◁ Given the claim above, we can write D = t, . . . , x′ , y, z, where z = xi , and possibly x′ = t. We claim that x ̸= x′ . Toward contradiction, suppose x′ = x. Since x → y belongs to Ki (q) and is uniquely generated by R, this entails R = ̸ F . In particular, we then have R′ ̸= F ′ , ′ ′ ′ and x → z belongs to K(q \ {F }). Again, using simplicity of D and (21) it is possible to +,q ′ argue that D[t, x′ ] is a path in K(q ′ \ {F ′ }). Therefore, xi ∈ (F ′ ) , a contradiction. Hence ′ the claim that x ̸= x holds. Lemma 69 then implies that x′ → y ∈ / K⇝ (q). In particular, this also entails x′ → y ∈ Kc (q). Lemma 67 states that if u → v ∈ K(q), v → y ∈ Kc (q) \ K⇝ (q), and v = ̸ y, then u → y ∈ Kc (q). Additionally, in this case, x → y ∈ Ki (q) entails u ̸= x, and Lemma 69 entails u → y ∈ / K⇝ (q). Thus, by simplicity of D, we obtain by backward induction along this path that t → y ∈ Kc (q) \ K⇝ (q). Since q is normal, t is a variable v. In particular, then, v → y belongs to K(q \ {F }) and v = Key(F ). We have now established a path of the form D0 = v, y, z, to witness xi ∈ F +,q . Here, v → y ∈ Kc (q) \ K⇝ (q), y → z ∈ K(S), and z = xi . On the other hand, by Item 1, we have y ∈ ReachK⇝ (q) (⊥). Since y → z ∈ Ki (q), we obtain that K⇝ (q) contains a path of the form D′ = ⊥, . . . , x, y, z. Again, D′ is simple as K⇝ (q) is acyclic. Note that v = ̸ x, as v → y ∈ / K⇝ (q). Hence, c by Lemma 66 and v → y ∈ K (q), we obtain that v does not appear in D′ [⊥, x]. Since v = Key(F ), we obtain that D′ [⊥, x] is a path in K(q \ {F }). Since D′ [⊥, x] does not contain any edge from K(S) (by simplicity of D′ ), we conclude that D′ [⊥, x] is a path in K(q ′ \ {F ′ }). Moreover, as R = ̸ F (by Key(R) = x = ̸ v = Key(F )), we obtain R′ ̸= F ′ and thus x → z +,q ′ belongs to K(q ′ \ {F ′ }). We conclude that xi ∈ (F ′ ) , a contradiction. q′

q

We conclude by contradiction that F ′ ⇝ G′ implies F ⇝ G. (Item (b)) Suppose that for some H ′ ∈ q ′ , we have u → v ∈ K(H ′ ), v → w ∈ Kc (q ′ ), and u → w ∈ K∗ (q ′ \ {H ′ }). We need to show that u → w ∈ Kc (q ′ ).

74

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

We consider first the case where H ′ = R′ . Then u = x and v appears in (y, ⃗u, ⃗z). Note that v → w ∈ Kc (q) by Lemma 108. Moreover, we have u → w ∈ K∗ (q \ {R}) due to q ′ \ {R′ } = q \ {R, S}. If v appears in (⃗y , u), then u → v ∈ K(R). Thus, by saturation of q it follows that u → w ∈ Kc (q). Hence also u → w ∈ Kc (q ′ ) by Lemma 108. Suppose then that v appears in ⃗z. We show that this case is not possible, considering the two constructions of q ′ side by side. First, we prove that in both cases y → w ∈ / Kc (q). Item (i): If y → w ∈ Kc (q), we obtain by u → y ∈ K(R), u → w ∈ K∗ (q \ {R}), and by saturation of q that u → w ∈ Kc (q), hence u → w ∈ Kc (q ′ ) by Lemma 108. Thus, we may assume y → w ∈ / Kc (q) in which case y ̸= w. Item (ii): If y → w ∈ Kc (q), we obtain by u → y ′ ∈ K(R), y ′ → y ∈ Kc (q), u → w ∈ K∗ (q \ {R}), and saturation of q that u → w ∈ Kc (q), hence u → w ∈ Kc (q ′ ) by Lemma 108. Thus, we may assume y → w ∈ / Kc (q) in which case y ̸= w. From y → w ∈ / Kc (q), y → v ∈ K(S), and v → w ∈ Kc (q), we obtain by saturation of q that ∗ y→w∈ / K (q \ {S}). Now, we recall that u → w ∈ K∗ (q ′ \ {R′ }). From q ′ \ {R′ } = q \ {R, S}, we obtain u → w ∈ K∗ (q \ {S}). Let D = t, . . . , w be some path from t to w in K(q \ {S}), where t ∈ {u, ⊥}. Then, for each element x′ in D, y → x′ ∈ / K∗ (q \ {S}), because otherwise we obtain a contradiction with y → w ∈ / K∗ (q \ {S}). ∗ Furthermore, y → w ∈ / K (q \ {S}) entails t ̸= ⊥, i.e., t = u. Recall also that u = x. Hence, U = x, . . . , w, v, obtained by appending D with the undirected edge {w, v}, is a path in Gaifman(q) that is not separated by S +,q (as v → w ∈ Kc (q) ⊆ K∗ (q \ {S})). Since this path connects q q NonKeyVars(S) and Vars(R), it follows S ⇝ R. Since R ⇝ S by Lemma 15 or Lemma 21 (depending on the case), this contradicts the assumption that the attack graph of q is acyclic. Hence, the case where v is mentioned in ⃗z is not possible. This concludes the case where H ′ = R. Suppose then that H ′ ̸= R′ . Then, we have H ′ ∈ q, and, by Lemma 108, v → w ∈ Kc (q). Consequently, to establish u → w ∈ Kc (q ′ ), by saturation of q we only need to show that u → w ∈ K∗ (q \ {H ′ }). We observe that the path from u to w in K(q ′ \ {H ′ }), provided by assumption, is readily in K(q \ {H ′ }), except that we may need to replace an edge induced by R′ with two edges induced by R, S in Item (i), or three edges induced by R, T, S in Item (ii). Note that this is possible as S ̸= H ′ ; additionally, in Item (ii), the edge generated by T belongs to Kc (q) ⊆ K(q \ {H ′ }). Hence u → w ∈ K∗ (q \ {H ′ }), which concludes the case H ′ ̸= R′ . Thus the case that v is mentioned in ⃗z is not possible. This concludes the proof of this item. (Item (c)) In what follows we consider an atom F ′ ∈ q ′ . (Item 1) Suppose toward contradiction that |NonKeyVars(F ′ )| > 1, and p → u ∈ Kc (q ′ ), for p = Key(F ′ ) and some u ∈ NonKeyVars(F ′ ). Then p → u ∈ K(F ′ ), and there exists G′ ∈ q ′ \ {F ′ } such that p → u ∈ K∗ (G′ ).

M. Hannula

75

Case 1: F ′ ̸= R′ . Then F = F ′ and hence |NonKeyVars(F )| > 1 and p → u ∈ K(F ). By normality of q, it holds p → u ∈ Ki (q). If p → u ∈ K∗ (G), then p → u ∈ Kc (q), a contradiction. Thus p → u ∈ / K∗ (G). This implies i G = R and u ∈ Z. Then by y → u, p → u ∈ K (q) and Lemma 59, we obtain p = y, hence y → u ∈ K(F ). But then F = S, and F ′ is undefined, a contradiction. Case 2: F ′ = R′ . Since G′ ̸= F ′ , we obtain G = G′ and hence p → u ∈ K∗ (G). Thus, if p→u∈ / K(F ), we obtain a contradiction with the normality of q. Hence p → u ∈ / K(F ). Since p → u ∈ K(F ′ ), this entails p = x and u ∈ Z. Now, x → u ∈ K∗ (G) entails x → u ∈ K(G) or ⊥ → u ∈ K(G). Since x → u ∈ / K(q) by Lemma 66, we obtain ⊥ → u ∈ K(q). By normality of q, in particular, this means ⊥ → u ∈ Ki (q). By Lemma 59, this leads to ⊥ = y, a contradiction with Item 1, i.e., y ∈ NotRootVars⇝ (q). (Item 2) Suppose toward contradiction that u → v ∈ Kc (q ′ ), for some distinct u, v ∈ NonKeyVars(F ′ ). By Lemma 108, we have u → v ∈ Kc (q). This means that there exist G′ ∈ q ′ and H ′ ∈ q ′ \ {G′ } such that u → v ∈ K(G′ ) and u → v ∈ K∗ (H ′ ). Additionally, by Z ⊆ NotKeyVars(q) we obtain u ∈ / Z. Case 1: u, v ∈ NonKeyVars(F ). Since u → v ∈ Kc (q), this violates the normality of q, a contradiction. Case 2: u, v ∈ / NonKeyVars(F ). Then F = R and F ′ = R′ . Note that we have u ∈ / Z. We proceed by case distinction. Item (i): the case where both u, v belong to (y, ⃗u) leads to a F witnessing a violation of normality. Hence, u belongs to (y, ⃗u) and v belongs to Z. Suppose first that u = y. Then u → v ∈ Kc (q), u = Key(S), and v ∈ NonKeyVars(S) contradict the assumption that S ∈ q i . Suppose then that u belongs to ⃗u. Now, we have y = ̸ u, since q is variable-repetition-free, i and y → v ∈ K (q). Hence, by Lemma 69, we obtain u → v ∈ Kc (q) \ K⇝ (q). Since x → u ∈ Ki (q) and u ̸= v, this leads to x → v ∈ Kc (q) by Lemma 67. However, this raises a contradiction with Lemma 66. Item (ii): the case where both u, v belong to (y ′ , ⃗u) leads to a F witnessing a violation of normality. Hence, u belongs to (y ′ , ⃗u) and v belongs to Z. Suppose first that u = y ′ . Then u → v ∈ Kc (q) and u ̸= v imply u → v ∈ K(q), which contradicts Lemma 66, as y ′ , y, v is a path in K⇝ (q). Suppose then that u belongs to ⃗u. It follows that y ′ ̸= u since q is variable-repetition-free. Then, arguing as in the previous case, we obtain a contradiction. We conclude by contradiction that this item holds. (Item 3) Suppose, toward contradiction that u → v, v → u ∈ Kc (q ′ ), for some distinct u, v ∈ Vars(q ′ ). Thus, by Lemma 108, we obtain u → v, v → u ∈ Kc (q), a contradiction with the normality of q. (Item 4) This item follows readily from Lemma 108 and the normality of q.

◀

▶ Lemma 117 (Inconsistent Edge Elimination). Let C consist of all (db, q) ∈ DB × sjfBCQU,A , where q is a saturated and normal query and db is a q-saturated database. For each

76

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

(db, q) ∈ C and extendable F ∈ q i , (db, q) 7→ InconsEdgeElimS (db, q) is a strict, guarded, equivalence-preserving, and polynomial-time reduction from C to C ∪ {true, false}. Proof. Let R(x, y, ⃗u), S(y, ⃗z) ∈ q i be the atoms witnessing that S is eliminable. Let us also write Z = NonKeyVars(S). Recall that both Z is non-empty by Item 3. The reduction InconsEdgeElimS is clearly strict and computable in polynomial time. It is into C ∪ {true, false} by Lemmas 9 and 115. It thus suffices to prove that it is guarded and equivalence-preserving. (Guardedness) Items 5 and 6 of guardedness follow by Lemmas 109 and 114. Items 2–3, 7, and 8 are clear by construction. We prove Items 1 and 4. To see why Item 4 holds, assume that H ∈ q c , and either Key(H) ∈ GuardVars(q) or Vars(H) = ∅. Toward contradiction, suppose first that H ∈ / q ′ . Then, in both cases (i) and ⇝ (ii) of the construction of q ′ , it follows that RootOf (Key(H)) = ⊥ and NonKeyVars(H) ̸= ∅, contradicting the assumption. This proves that H ∈ q ′ . We claim that furthermore c i H ∈ (q ′ ) . Suppose, toward contradiction, that H ∈ (q ′ ) . Then there exists an edge i ′ u → v ∈ K (q ) ∩ K(H). By Lemma 108, since u → v ∈ K(q), this implies u → v ∈ Ki (q), contradicting H ∈ q c . Hence, the claim is true, and therefore Item 4 holds. To prove Item 1, Assume that for each T ∈ q, |T db ↾V | ≤ N. Now, Lemma 114 and the fact that Vars(q) = Vars(q ′ ) imply NotGuardedVars(q ′ ) = NotGuardedVars(q). For any U ∈ q ′ \ {R′ }, we have U db = U db0 , and thus, using Lemma 9, ′

|U db ↾V ′ | ≤ |U db0 ↾V ′ | ≤ |U db ↾V | ≤ N, where V ′ := Vars(U ) ∩ NotGuardedVars(q ′ ) and V := Vars(U ) ∩ NotGuardedVars(q). Consider then the atom R′ . Since NonKeyVars(S) ⊆ GuardedVars(q), letting V ′ := Vars(R′ ) ∩ NotGuardedVars(q ′ ) and V := Vars(R) ∩ NotGuardedVars(q), we have that V ′ = V . Hence, by the construction and Lemma 9, ′

|(R′ )db ↾V ′ | ≤ |(R′ )db0 ↾V ′ | = |Rdb ↾V ′ | ≤ |Rdb ↾V | ≤ N. Thus, Item 1 holds as well. We conclude that the stated reduction is guarded. (Equivalence-preservation) By Lemma 9, it suffices to prove that (db, q) ∈ CERTAINTY if and only if (db0 , q ′ ) ∈ CERTAINTY, where q ′ and db0 are as in (19) and ((i)). We consider case (i) of the construction of q ′ and assume that x is a variable; the remaining cases are then analogous. Now, since RootOf ⇝ (y) = ⊥ (by Item 1) and x → y ∈ K⇝ (q), the graph K⇝ (q) contains a path of the form D = ⊥, . . . , x, y, z. (Note that if x is a constant, then in case (i) this path takes the form D = ⊥, y, z.) This path corresponds to a sequence of of atoms R1 (f , x1 , −), R2 (x1 , x2 , −), . . . , Rn+1 (xn , x, −), R(x, y, ⃗u), S(y, ⃗z) ∈ q

M. Hannula

77

where f is a constant, and x1 , . . . , xn is a (possibly empty) sequence of variables. For every repair r of db, there exists a unique sequence of constants f1 , . . . , fn , a, b, ⃗c, d⃗ such that ⃗ S(b, ⃗c) ∈ r. R1 (f , f1 , −), R2 (f1 , f2 , −), . . . , Rn+1 (fn , a, −), R(a, b, d), ⃗ is determined by r. For a repair r0 of db0 , by We say that the mapping (x, y, ⃗z, ⃗u) 7→ (a, b, ⃗c, d) ′ ⃗ S(b, ⃗c) with replacing the atoms R(x, y, ⃗u), S(y, ⃗z) with R (x, y, ⃗z, ⃗u) and the facts R(a, b, d), ′ ⃗ R (a, b, ⃗c, d) in the above sequences, we can similarly describe how the mapping (x, y, ⃗z, ⃗u) 7→ ⃗ is determined by r0 . (a, b, ⃗c, d) Clearly, if θ(q) ⊆ r, for a valuation θ, then (x, y, ⃗u, ⃗z) 7→ (θ(x), θ(y), θ(⃗u), θ(⃗z)) is the mapping that is determined by r, and similarly for r0 . In particular, whenever the repairs r and r0 agree on R1 , . . . , Rn , then they determine the same mapping (x, y, ⃗u, ⃗z) 7→ (θ(x), θ(y), θ(⃗u), θ(⃗z)). (⇒) Suppose (db, q) ∈ CERTAINTY, and let r0 be an arbitrary repair of db0 . Let ⃗ be determined by r0 . In particular, R′ (a, b, ⃗c, d) ⃗ ∈ r0 . We let r (x, y, ⃗z, ⃗u) 7→ (a, b, ⃗c, d) extend r0 ↾q\{R,S} as follows: ⃗ to r, and from the remaining R-blocks of db add an arbitrary fact to r. Add R(a, b, d) Add S(b, ⃗c) to r, and from the remaining S-blocks of db add an arbitrary fact to r. Clearly, r is a repair of db. Furthermore, r and r0 determine the same mapping (x, y, ⃗z, ⃗u) 7→ ⃗ By assumption the exists a valuation θ on Vars(q) such that θ(q) ⊆ r. Thus θ maps (a, b, ⃗c, d). ⃗ By construction we obtain θ(q ′ ) ⊆ r0 . Thus (db0 , q ′ ) ∈ CERTAINTY. (x, y, ⃗z, ⃗u) to (a, b, ⃗c, d). (⇐) Suppose (db0 , q ′ ) ∈ CERTAINTY, and let r be an arbitrary repair of db. Let (x, y, ⃗z, ⃗u) 7→ ⃗ be the mapping that is determined by r. In particular, R(a, b, d), ⃗ S(b, ⃗c) ∈ r. We (a, b, ⃗c, d) let r0 extend r↾q\{R,S} as follows: ⃗ ⃗c) to r0 , and from the remaining R′ -blocks of db0 add an arbitrary fact to Add R′ (a, b, d, r0 . Analogously to the first direction, r0 is a repair of db0 . Furthermore, r and r0 determine the ⃗ By assumption the exists a valuation θ on Vars(q ′ ) same mapping (x, y, ⃗z, ⃗u) 7→ (a, b, ⃗c, d). ⃗ By construction we obtain such that θ(q ′ ) ⊆ r0 . Thus θ maps (x, y, ⃗z, ⃗u) to (a, b, ⃗c, d). θ(q) ⊆ r. Thus (db, q) ∈ CERTAINTY. ◀

E.7

Pruning Step

Fix c ∈ N, and let C be a class of pairs (db, q) such that db is a q-saturated database, q is a saturated and normal query from sjfBCQU,A , and |GuardVars(q)| ≤ c. Let Prune be the reduction described in Algorithm 5. This reduction takes as an input a query q ∈ C and a q-saturated database db, and returns false or (db′ , q ′ ), where db′ is a q ′ -saturated database, q ′ is a saturated query from sjfBCQU,A . Moreover, as we show next, the returned query has the property that OutK⇝ (q) (⊥) ⊆ GuardedVars(q) ∩ LeafVars⇝ (q) ∩ NotKeyVars(q). ▶ Lemma 22. Let c ∈ N. Let C be a class of pairs (db, q) such that db is a q-saturated database, q is a saturated and normal query from sjfBCQU,A , and |GuardVars(q)| ≤ c. Then, Prune is a guarded, equivalence-preserving, and polynomial-time reduction from C to C ∪ {true, false}. Additionally, assuming (db′ , q ′ ) = Prune(db, q) ∈ / {true, false}, it holds that OutK⇝ (q) (⊥) ⊆ GuardedVars(q) ∩ LeafVars⇝ (q) ∩ NotKeyVars(q).

(5)

78

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Algorithm 5 Prune(db, q)

Input : A saturated and normal query q ∈ sjfBCQU,A and a q-saturated database db Output : false or (db′ , q ′ ), where q ′ is a saturated query from sjfBCQU,A , db′ is a q ′ -saturated database, and OutK⇝ (q′ ) (⊥) ⊆ GuardedVars(q ′ ) ∩ LeafVars⇝ (q ′ ) ∩ NotKeyVars(q) repeat 2 while exists prunable y ∈ Vars(q) do 3 choose the ≺-least prunable y; 4 (db, q) ← Try(LeafPruney (db, q));

1

// Lemma 86; y is prunable if y ∈ LeafVars⇝ (q) ∩ KeyVars(q) 5 6 7

while exists eliminable y ∈ Vars(q) do choose the ≺-least eliminable y; (db, q) ← Try(LeafElimy (db, q)); // Lemma 91; y is eliminable if y ∈ LeafVars⇝ (q) ∩ NotKeyVars(q) ∩ NotGuardedVars(q)

8 9 10

11 12 13

while exists extendable R ∈ q i do choose the ≺-least extendable R; (db, q) ← Try(ConsEdgeElimR (db, q)); // Lemma 104; F is extendable if, given Y := NonKeyVars(F ), OutKi (q) (Y ) = ∅ and ∅ ̸= OutK⇝ (q) (Y ) ⊆ LeafVars⇝ (q) ∩ NotKeyVars(q) ∩ GuardedVars(q); while exists eliminable S ∈ q i do choose the ≺-least eliminable S; (db, q) ← Try(InconsEdgeElimS (db, q)); // Lemma 117; G is eliminable if, given Y := NonKeyVars(G), ∅ ̸= Y ⊆ LeafVars⇝ (q) ∩ NotKeyVars(q) ∩ GuardedVars(q) and Key(G) ∈ ReachK⇝ (q) (⊥) ∩ NotRootVars⇝ (q).

until until none of the while-loops is entered; 15 return (db, q); 14

Proof. Prune is guarded and equivalence-preserving by Proposition 81 and Lemmas 86, 91, 104, and 117. By the same token, Prune is a mapping into C. It remains to prove (5) and the polynomial-time computability. Time complexity. Each iteration strictly reduces ||q||, as stated in Lemmas 86, 91, 104, and 117. Hence the number of iterations is polynomial. Also, each step can be carried out in polynomial time in the temporary input (db′ , q ′ ) by the same lemmas. In particular, checking the conditions of the while-clauses, including the construction of the graphs K(q ′ ), Kc (q ′ ), Ki (q ′ ), K⇝ (q ′ ), can be done in polynomial time in ||q ′ ||. It holds that (db, q) is N -unguarded-bounded, for N := ||db||. By guardedness (Definition 79), then, db′ is N -unguarded-bounded, |adom(db′ )| ≤ N , and |GuardVars(q)| = |GuardVars(q ′ )|. Hence, by Lemmas 74 and 77, for each R ∈ q ′ , ′

′

′

|Rdb | ≤ |Rdb ↾V | · |adom(db′ )||GuardVars(q )| ≤ N c+1 ,

M. Hannula

79

where V := Vars(R) ∩ NotGuardedVars(q ′ ). Furthermore, by guardedness, it holds that ||q ′ || ≤ ||q||. Therefore, ||db′ || ≤ ||q ′ || · N c+1 ≤ ||q|| · ||db||c+1 , meaning that each step is computable in polynomial time in the initial input (db, q). We conclude that each step can be carried out in polynomial time in the initial input. Since each reduction inside the while-loop is strict, it is correct to conclude that the algorithm runs in polynomial time. Equation (5). Let us consider the increasing effect each while-loop has. Once the while-loop 1 does not apply, LeafVars⇝ (q) ⊆ NotKeyVars(q). Once the while-loops 1-2 do not apply, LeafVars⇝ (q) ⊆ NotKeyVars(q) ∩ GuardedVars(q).

(22)

Once the while-loops 1-3 do not apply, given F ∈ q i , Y := NonKeyVars(F ), such that OutKi (q) (Y ) = ∅, if OutK⇝ (q) (Y ) ⊆ LeafVars⇝ (q), then Y ⊆ LeafVars⇝ (q) (i.e., OutK⇝ (q) (Y ) = ∅). (23) Once the while-loops 1-4 do not apply, OutK⇝ (q) (⊥) ⊆ LeafVars⇝ (q) ∩ NotKeyVars(q) ∩ GuardedVars(q).

(24)

The first three items are straightforward to verify. For the last item, assume toward contradiction that none of the while-loops 1-4 applies, while (24) is false. Since (22) holds but (24) does not, we have OutK⇝ (q) (⊥) ̸⊆ LeafVars⇝ (q). By normality of q, we find an atom F ∈ q i such that Key(F ) = ⊥ and Y ̸⊆ LeafVars⇝ (q), where Y := NonKeyVars(F ). Note that vacuously Y ⊆ ReachK⇝ (q) (⊥) ∩ NotRootVars⇝ (q). We consider two possible cases. Suppose first that OutKi (q) (Y ) ̸= ∅. Then, we can pick an atom G ∈ q i such that Key(G) ∈ Y and NonKeyVars(G) ̸= ∅. Consequently, Key(G) ∈ ReachK⇝ (q) (⊥) ∩ NotRootVars⇝ (q). Suppose then that OutKi (q) (Y ) = ∅. By (23), since Y ̸⊆ LeafVars⇝ (q), we obtain OutK⇝ (q) (Y ) ̸⊆ LeafVars⇝ (q). We can now pick y such that OutK⇝ (q) (y) ̸⊆ LeafVars⇝ (q). Hence, and due to OutKi (q) (y) = ∅, there exist two edges of the form y → y ′ ∈ Kc (q)∩K⇝ (q) and y ′ → v ∈ Ki (q); for this, recall that by Lemma 64 K⇝ (q) does not have two consecutive edges from Kc (q). Hence, there exists an atom G ∈ q i , where Key(G) = y ′ ∈ ReachK⇝ (q) (⊥) ∩ NotRootVars⇝ (q) and NonKeyVars(G) ̸= ∅. We conclude that there exists an atom G ∈ q i such that Key(G) ∈ ReachK⇝ (q) (⊥) ∩ NotRootVars⇝ (q) and Z ̸= ∅, where Z := NonKeyVars(G). We may assume that Key(G) has a maximal distance from ⊥ in K⇝ (q) among all such G. The reasoning above establishes that Z ⊆ LeafVars⇝ (q); otherwise, due to acyclicity of K⇝ (q) (Lemma 65), one would find an atom H ∈ q i such that Key(H) has a greater distance to ⊥ than Key(G). However, then G is eliminable, contradicting the assumption that none of the while-loops 1-4 applies. Hence, by contradiction, the last item follows. ◀

80

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

F

Definitions and Lemmas for Section 7

In this section we provide auxiliary definitions, lemmas, and missing proofs for Section 7. First, we present what we call substitution-guarded-reductions, which are similar to the guarded reductions given earlier in Definition 79. ▶ Definition 118 (Substitution-Guarded reduction). A many-one reduction f : DB×sjfBCQU,A → DB × sjfBCQU,A ∪ {true, false} is substitution-guarded if for every (db, q) ∈ DB × sjfBCQU,A , assuming (db′ , q ′ ) = f (db, q) ∈ / {true, false}, the conditions of guardedness hold, except that Items 4–6 are replaced by the following conditions: 4∗ If F ∈ q c , and either Key(F ) ∈ GuardVars(q) or Vars(F ) = ∅, the following statements hold. c

If Vars(F ) = ∅, then F ∈ (q ′ ) . If Key(F ) ∈ GuardVars(q) and F = R(x, y, ⃗c), where y is a variable and ⃗c is a sequence c of constants, then, for some constants a and b, one of F, R(x, b, ⃗c), R(a, b, ⃗c) is in (q ′ ) . If Key(F ) ∈ GuardVars(q) and F = R(x, ⃗c), where ⃗c is a sequence of constants, then, c for some constant a, F or R(a, ⃗c) is in (q ′ ) . 5∗ GuardedVars(q ′ ) = GuardedVars(q) ∩ Vars(q ′ ). 6∗ GuardVars(q ′ ) = GuardVars(q) ∩ Vars(q ′ ). A substitution-guarded reduction is always strict, i.e., ||q ′ || < ||q||. Note that if F ∈ q c and Key(F ) ∈ GuardVars(q), then F by normality is either of the form R(x, y, ⃗c) or R(x, ⃗c), where y is a variable and ⃗c a sequence of constants. One may now observe that the following propositions hold. The first one is clear by definition. ▶ Proposition 119. Guarded reductions are substitution-guarded. ▶ Proposition 120. Substitution-guarded reductions are closed under composition, provided that newly introduced relation names are fresh. Proof. The proof is analogous to that of Proposition 81. Here, additionally, Items 5∗ and 6∗ rely on Item 7. ◀

F.1

Substitution Step

Next, we consider the substitution step, showing that it is substitution-guarded. Again, we start with preparatory lemmas. Recall the notion of a substitutable set from Definition 52. ▶ Lemma 121. Let q ∈ sjfBCQU,A be saturated and normal. Let Y ⊆ Vars(q) be substitutable. Let f : Y → Const be a function. Define q ′ := qf . Then GuardVars(q) \ Y = GuardVars(q ′ ). Proof. We need to prove (RootVars⇝ (q) ∩ SrcVars→ (q)) \ Y = RootVars⇝ (q ′ ) ∩ SrcVars→ (q ′ ). We divide this to several claims. For a variable x ∈ Vars(q), let us define x′ := ⊥ if x ∈ Y , and otherwise x′ := x. ▷ Claim 122. RootVars⇝ (q) \ Y ⊆ RootVars⇝ (q ′ ).

M. Hannula

81

Proof. Toward contradiction, suppose the claim is false. Let u ∈ RootVars⇝ (q) \ (Y ∪ RootVars⇝ (q ′ )). Then there exists an edge of the form p → u ∈ K⇝ (q ′ ). Clearly, there exists w → u ∈ K(q) where w′ := p. Since q is variable-repetition-free, it holds that w = ̸ u. Since u ∈ RootVars⇝ (q), we also have w → u ∈ / Ki (q). We consider two possible cases. Suppose first that p → u ∈ Ki (q ′ ). Now, w → u ∈ Kc (q) implies p → u ∈ Kc (q ′ ) by Lemma 51, which contradicts the assumption. Hence, we obtain w → u ∈ / K(q), a contradiction. Suppose then that p → u ∈ Kc (q ′ ). Then we find another edge r → p ∈ Ki (q ′ ) such that r→u∈ / Kc (q ′ ). This entails p = w ∈ / Y (as p is a variable), i.e., we have r → w ∈ Ki (q ′ ), c ′ c ′ w → u ∈ K (q ), and r → u ∈ / K (q ). Again, there exists s → w ∈ K(q) such that s′ = r. By Lemma 51, we have w → u ∈ Kc (q) and s → u ∈ / Kc (q). Note that w → u ∈ K(q) i due to w ̸= u. Thus, if s → w ∈ K (q), then w → u ∈ K⇝ (u), contradicting the fact that u ∈ RootVars⇝ (q). Moreover, if s → w ∈ Kc (q), then by Lemma 14 we obtain s → u ∈ Kc (q), again a contradiction. We conclude by contradiction that RootVars⇝ (q) ⊆ RootVars⇝ (q ′ ).

◁

▷ Claim 123. RootVars⇝ (q ′ ) ⊆ RootVars⇝ (q) \ Y . Proof. Since RootVars⇝ (q ′ ) does not intersect Y , it suffices to prove RootVars⇝ (q ′ ) ⊆ RootVars⇝ (q). Assume toward contradiction that this is false. Let u ∈ RootVars⇝ (q ′ ) \ RootVars⇝ (q). In particular, u ∈ / Y . By assumption there exists an edge of the form ⇝ w → u ∈ K (q). If w → u ∈ Ki (q), then w′ → u ∈ Ki (q ′ ) by Lemma 51, i.e., u∈ / RootVars⇝ (q ′ ), a contradiction. Thus, suppose w → u ∈ Kc (q). Then we find another edge p → w ∈ Ki (q) such that p → u ∈ / Kc (q). Since OutKc (q) (Y ) ⊆ Y and u ∈ / Y , we obtain w∈ / Y , hence w = w′ . Consequently, Lemma 51 implies p′ → w ∈ Ki (q ′ ), w → u ∈ Kc (q ′ ), and p′ → u ∈ / Kc (q ′ ), which is tantamount to p′ → u ∈ K⇝ (q ′ ), i.e., u ∈ / RootVars⇝ (q ′ ). This ⇝ ′ ⇝ contradicts our assumption, so we obtain RootVars (q ) ⊆ RootVars (q) \ Y . ◁ ▷ Claim 124. SrcVars→ (q) ∩ RootVars⇝ (q) ⊆ SrcVars→ (q ′ ). Proof. Assume toward contradiction that u ∈ (SrcVars→ (q) ∩ RootVars⇝ (q)) \ SrcVars→ (q ′ ). Then, there exists an edge of the form u0 → u ∈ K(q ′ ) such that u0 ∈ / ReachK(q′ ) (u). In ′ particular, u ∈ Vars(q ). We claim that u0 → u ∈ K(q). Assume toward contradiction that u0 → u ∈ / K(q). This is only possible when ⊥ → u ∈ K(q ′ ) and y → u ∈ K(q), for some y ∈ Y . However, assuming y ∈ Y , y → u ∈ Ki (q) contradicts u ∈ RootVars⇝ (q) and y → u ∈ Kc (q) contradicts u ∈ / Y . Therefore, the claim that u0 → u ∈ K(q) holds. Now, from u ∈ SrcVars→ (q) we obtain u0 ∈ ReachK(q) (u). In particular, there exists a directed path D from u to u0 in K(q). We may assume that D is shortest among all such paths. Since no such path exists in K(q ′ ), we obtain that D contains a vertex y ∈ Y . Moreover, y = ̸ u as y does not belong to Vars(q ′ ) while u does. We may select y so that, beside it, no other vertex in the path D[y, u] belongs to Y . Since OutKc (q) (Y ) ⊆ Y (due to the substitability of Y ), it follows that the first edge in D[y, u] belongs to Ki (q). Since D[y, u] is also a shortest path from y to u, Lemma 61 implies u ∈ ReachK⇝ (q) (y), contradicting u ∈ RootVars⇝ (q). We conclude by contradiction that SrcVars→ (q) ∩ RootVars⇝ (q) ⊆ SrcVars→ (q ′ ).

◁

▷ Claim 125. SrcVars→ (q ′ ) ⊆ SrcVars→ (q). Proof. Assume toward contradiction that u ∈ SrcVars→ (q ′ ) \ SrcVars→ (q). In particular, we have u ∈ / Y . Then we find an edge u0 → u ∈ K(q) such that u0 ∈ / ReachK(q) (u).

82

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

Suppose first that u0 → u ∈ K(q ′ ), in which case by assumption we have u0 ∈ ReachK(q′ ) (u). Since u ∈ SrcVars→ (q ′ ) (as opposed to being ⊥), it can be seen that any path from u to u0 in K(q ′ ) belongs also to K(q). Hence, u0 ∈ ReachK(q) (u), contradicting the assumption. Suppose then that u0 → u ∈ / K(q ′ ). This entails u0 ∈ Y . Now, u0 → u ∈ Ki (q) implies by Lemma 51 that ⊥ → u ∈ Ki (q ′ ), contradicting the assumption that u ∈ SrcVars→ (q ′ ). Furthermore, u0 → u ∈ Kc (q) implies u ∈ Y by the fact that OutKc (q) (Y ) ⊆ Y , again a contradiction. Therefore, by contradiction we obtain SrcVars→ (q ′ ) ⊆ SrcVars→ (q). ◁ ◀

This concludes the proof.

▶ Lemma 126. Let q ∈ sjfBCQU,A be saturated and normal. Let Y ⊆ Vars(q) be substitutable. Let f : Y → Const be a function. Define q ′ := qf . Then GuardedVars(q)\Y = GuardedVars(q ′ ). Proof. Assume first that v ∈ GuardedVars(q) \ Y . Then there exists u ∈ GuardVars(q) such that u → v ∈ Kc (q). Note that we have u ∈ / Y by v ∈ / Y and OutKc (q) (Y ) ⊆ Y . Hence, by Lemma 121 we obtain u ∈ GuardVars(q ′ ), and by Lemma 51 we have u → v ∈ Kc (q ′ ). Therefore, v ∈ GuardedVars(q ′ ). Assume then that v ∈ GuardedVars(q ′ ). Then there exists u ∈ GuardVars(q ′ ) such that u → v ∈ Kc (q ′ ). It follows that u, v ∈ / Y . Hence, by Lemma 121 we obtain u ∈ GuardVars(q), and by Lemma 51 we have u → v ∈ Kc (q). Therefore, v ∈ GuardedVars(q). ◀ We can then prove the following lemma. Recall that the reduction Substitutef is given in (8). ▶ Lemma 25 (Substitution Lemma). Let C consist of all (db, q) ∈ DB × sjfBCQU,A , where q is a saturated and normal query and db is a q-saturated database. Then, for each (db, q) ∈ C, substitutable Y ⊆ Vars(q), and function f : Y → Const, (db, q) 7→ Substitutef (db, q) is a strict, substitution-guarded, and polynomial-time reduction from C to C ∪ {true, false}. Proof. The reduction is strict, polynomial-time, and into C ∪ {true, false} by Lemma 54. It remains to show that the reduction is substitution-guarded. Items 2, 3, and 7 are immediate, and Items 5∗ and 6∗ follow by Lemmas 121 and 126. It remains to prove Items 4∗ and Item 1. We start with the former. Let q be a saturated and normal query from sjfBCQU,A . Let Y ⊆ Vars(q) be substitutable. Let f : Y → adom(db). Let F ∈ q c , and suppose that either Key(F ) ∈ GuardVars(q) or Vars(F ) = ∅. We consider the three staments of Item 4∗ in the following. c

If Vars(F ) = ∅, then clearly F ∈ (q ′ ) . Suppose Key(F ) ∈ GuardVars(q) and F = R(x, y, ⃗c), where y is a variable and ⃗c is a sequence of constants. In particular, we have that NonKeyVars(F ) = {y} and x → y ∈ Kc (q). If F ∈ q ′ , then x, y ∈ / Y , and hence by Lemma 51, x → y ∈ Kc (q ′ ), yielding c F ∈ q . Thus, suppose F ∈ / q ′ . Then, one of R(f (x), y, ⃗c), R(x, f (y), ⃗c), R(f (x), f (y), ⃗c) ′ belongs to q . We show that only the last atom can belong to q ′ . Toward contradiction, suppose first that R(f (x), f (y), ⃗c) ∈ q ′ . Then x, y ∈ Y , and as q is variable-repetition-free, we moreover have x = ̸ y. In particular, Y is not a singleton, so by Item 3 of substitutability we obtain Y = NonKeyVars(H), for some H ∈ q such

M. Hannula

83

that Key(H) = ⊥. As x → y ∈ Kc (q), we obtain a contradiction with the normality of q. Hence R(f (x), f (y), ⃗c) ∈ / q′ . Furthermore, toward contradiction, suppose that R(f (x), y, ⃗c) ∈ q ′ . Then x ∈ Y , and by Item 2 of substitutability, also y ∈ Y , contradicting the fact that y has not been substituted. Hence, R(f (x), y, ⃗c) ∈ / q′ . c

It follows that R(x, f (y), ⃗c) ∈ q ′ , and by definition this means that R(x, f (y), ⃗c) ∈ (q ′ ) Thus, the second statement follows.

If Key(F ) ∈ GuardVars(q) and F = R(x, ⃗c), where ⃗c is a sequence of constants, then c clearly either F or R(f (x), ⃗c) is in (q ′ ) . This concludes the proof of Item 4∗ . To prove Item 1, assume that (db, q) is N -unguarded-bounded (see Definition 78). In particular, for each T ∈ q, it holds that |T db ↾V | ≤ N, where V := Vars(T ) ∩ NotGuardedVars(q). By Lemma 126, GuardedVars(q ′ ) = GuardedVars(q) \ Y . Since Vars(q ′ ) and Y are disjoint, this leads to NotGuardedVars(q ′ ) ⊆ NotGuardedVars(q). Thus, using Lemma 9 and Item 3, for each T ′ := TY 7→f (Y ) ∈ q ′ , where T ∈ q, we have ′

|T db ↾V ′ | ≤ |T db ↾V ′ | ≤ |T db ↾V | ≤ N, where V ′ := Vars(T ′ ) ∩ NotGuardedVars(q ′ ) and V := Vars(T ) ∩ NotGuardedVars(q). Hence, Item 1 holds as well. We conclude that the stated reduction is substitution-guarded. This concludes the proof. ◀

G

Proof of Main Lemma

In the proof of the main lemma, we use the following result. ▶ Lemma 127 ([19, Lemma 4.4]). Let q be a query from sjfBCQ. Let F ∈ q be an atom that has no incoming attack in the attack graph of q. Then, the following are equivalent for every database db: 1. q is true in every repair of db; 2. for some f : Key(F ) → adom(db), every repair of db satisfies qf . The function Solve is given by Algorithm 6. Recall the meaning of Try from Remark 36 and Substitutef from (8). ▶ Lemma 27 (Main Lemma). Let c ∈ N. Let C be a class of pairs (db, q) such that db is a q-saturated database, q is a saturated and normal query from sjfBCQU,A , and #srcSCC(K(q)) ≤ c. Then Solve is an equivalence-preserving, polynomial-time reduction from C to {true, false}. Proof. We claim that, given (db, q) ∈ C, Solve(db, q) runs in polynomial time, and Solve(db, q) = true ⇐⇒ (db, q) ∈ CERTAINTY.

(25)

We first consider (A) correctness of the algorithm Solve, and then (B) its running time. (A) Correctness. By Lemmas 9 and 22, every reduction involved in the algorithm is equivalence-preserving, except for the substitution steps in lines 5 and 14. Thus, it suffices

84

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

to focus on these variable substitutions. We start with the case where the condition of the if-statement holds, and then proceed to the case where it does not hold. Case: Vars(q) ̸= ∅ and OutK⇝ (q) (⊥) = ∅. By Lemma 127, (db, q) ∈ CERTAINTY ⇐⇒ (db, qx7→a ) ∈ CERTAINTY for some a ∈ adom(db) Moreover, by Lemma 9, either DBSaturate(db, qx7→a ) = false, in which case (db, qx7→a ) ∈ / CERTAINTY, or, defining db′ := DBSaturate(db, qx7→a ), we have (db, qx7→a ) ∈ CERTAINTY ⇐⇒ (db′ , qx7→a ) ∈ CERTAINTY. Suppose that the algorithm continues from the reduced instance (db′ , qx7→a ). By Lemma 70 and the normality of q, it can be seen that the singleton set {x} is substitutable. Hence, Lemma 54 implies that (db′ , qx7→a ) remains in C, as is required for the recursive call of Solve. Thus, it can be seen that the first part of the algorithm is correct. Case: Vars(q) ̸= ∅ and OutK⇝ (q) (⊥) ̸= ∅. By Lemma 22 pruning is equivalence-preserving and stays within C. It is possible that after pruning we have OutK⇝ (q) (⊥) = ∅. This can happen if before pruning ⊥ is only connected to non-guarded variables in K⇝ (q); in this case, these variables are simply pruned away and the algorithm continues the while-loop. Suppose that after pruning OutK⇝ (q) (⊥) ̸= ∅. Then there exists a variable y ∈ Vars(q) such that ⊥ → y ∈ K⇝ (q). In particular, there exists an atom F ∈ q i such that Key(F ) = ⊥ and y ∈ Y := NonKeyVars(F ). It is clear that (db, q) ∈ CERTAINTY ⇐⇒ (db, qf ) ∈ CERTAINTY for all f : Y → adom(db) such that Ff ∈ db. Therefore, by Lemma 9, either Saturate(db, qf ) = false, in which case (db, qf ) ∈ / CERTAINTY, or, defining db′ := Saturate(db, qf ), we have (db, qf ) ∈ CERTAINTY ⇐⇒ (db′ , qf ) ∈ CERTAINTY. Suppose that the algorithm continues from the reduced instance (db′ , qf ). It holds that Y ⊆ OutK⇝ (q) (⊥), and by Lemma 22 we obtain that OutK⇝ (q) (⊥) ⊆ NotKeyVars(q). Thus, by Y ⊆ NotKeyVars(q) we obtain OutKc (q) (Y ) ⊆ Y . Furthermore, OutKc (q) (⊥) ⊆ Y since q is normal, meaning that Item 2 of substitutability obtains for Y . As Item 1 and Item 3(ii) are clear, we conclude that Y is substitutable. Again, Lemma 54 implies that (db′ , qf ) remains in C. It can now be seen that the second part of the algorithm is correct. Case: Vars(q) = ∅. Since db is q-saturated, the query q is simply a set of facts. In particular, we have that db = q. Hence (db, q) ∈ CERTAINTY. It can be verified that between every recursive call there is at least one strict reduction. If Vars(q) = ∅, then clearly the first reduction involved in the sequel, i.e., (db, q) → (db, qx7→a ), is strict. Suppose Vars(q) ̸= ∅. If the pruning step is vacuous, i.e., (db, q) is already at a

M. Hannula

85

pruned state, then the condition of the if-statement is triggered, leading to a strict reduction; otherwise, a non-vacuous pruning step involves at least one strict reduction. Therefore, we may conclude that the computation terminates. We conclude by these considerations that (25) holds. This concludes step (A). (B) Running time. We being by noting the following property. A state of the computation is a pair (db′ , q ′ ) ∈ / {true, false} arising during an execution of the algorithm. ▷ Claim 128. For every state (db′ , q ′ ) of the computation, the reduction from (db, q) to (db′ , q ′ ) is substitution-guarded and into C. Proof. The reduction from (db, q) to (db′ , q ′ ) is composed from those in lines 5, 10, 14. Since the component reductions are guarded (Lemma 22) or substitution-guarded (Lemma 25), the claim follows by Propositions 119 and 120. The same lemmas guarantee that (db′ , q ′ ) remains in C. ◁ Let N := ||db|| be the size of the initial input database db. Specifically, db is N -unguardedbounded. Moreover, by Lemma 74, we have |GuardVars(q)| ≤ #srcSCC(K(q)) ≤ c.

(26)

In the following, we first consider (B1) the running time of each computation branch, and then (B2) the number of such computation branches. By establishing a polynomial upper bound for both, it follows that the total running time of the algorithm is polynomial. (B1) Branch running time. Let us first consider the size of an arbitrary intermediate input. For this, let (db′ , q ′ ) be an arbitrary state of the algorithm. By Claim 128, we have that (db′ , q ′ ) ∈ C, db′ is N -unguarded-bounded, GuardedVars(q ′ ) ⊆ GuardedVars(q), adom(db′ ) ⊆ adom(db), and ||q ′ || ≤ ||q||. Thus, by Lemma 77 and (26), we obtain, for each R ∈ q ′ , that ′

′

′

|Rdb | ≤ |Rdb ↾V | · |adom(db′ )||GuardVars(q )| ≤ N · |adom(db)||GuardVars(q)| ≤ N c+1 , where V := Vars(R) ∩ NotGuardedVars(q ′ ). Hence, ||db′ || ≤ ||q ′ || · N c+1 ≤ ||q|| · N c+1 ≤ ||q|| · ||db||c+1 .

(27)

Consequently, there exists a polynomial p such that ||db′ || + ||q ′ || ≤ p(||db||, ||q||), for any state (db′ , q ′ ). By Lemmas 22 and 54, every reduction in the algorithm runs in polynomial time in its local input (db′ , q ′ ). Hence, every reduction runs in polynomial time in the initial input (db, q). Since the recursion depth is bounded by ||q||, following the argument in step (A), we may conclude that each computation branch runs in polynomial time in the input (db, q). This concludes step (B1). (B2) Number of branches. Fix db as the initial database, and q as the initial query. The computation can be viewed to maintain a partial function f : Vars(q) → adom(db), corresponding to the substitution of constants for variables. Let F denote the set of all such substitutions f , including the empty function, that arise during the computation. Any two surviving states with the same substitution domain have the same query structure, up to the substituted constants: database saturation may terminate a branch with false, but otherwise leaves the query unchanged, while the subsequent transformations depend only on

86

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

its structure. Hence the next substitution domain is the same in all such states, and since substitutions only extend their domains, the sets Dom(f ), for f ∈ F, form a chain under inclusion. In particular, writing Dom(f ) for the domain of a function f , for any f, g ∈ F it holds that Dom(f ) ⊆ Dom(g) or Dom(g) ⊆ Dom(f ). For every non-empty f ∈ F, we write Pred(f ) for the immediate predecessor of f , defined as the unique inclusion-maximal f ′ ∈ F such that f ′ ⊊ f . Moreover, f ′ is a predecessor of f if Predi (f ) = f ′ , for some i ≥ 0, where Predi+1 (f ) := Pred(Predi (f )) and Pred0 is the identity. Let g ∈ F. A state (db′ , q ′ ) is called g-consistent if it arises from the initial input (db, q) via the substitutions specified by g. Note that q ′ may be distinct from the simple substitution qg due to the changes made to the atoms during the pruning step. We say that g is saturated if the computation reaches a state (db′ , q ′ ) where q ′ is g-consistent and db′ is q ′ -saturated. Here, we assume that Substitutef (defined in (8) and employed in lines 5 and 14) is a composite step: (db, q) 7→ (db, qf ) 7→ (DBSaturate(db, qf ), qf ). Thus, the computation may reach a state (db, qf ) but not a state (DBSaturate(db, qf ), qf ) if database saturation produces false. Informally, g is saturated if database saturation does not output false immediately after having made all the substitutions according to f . ▷ Claim 129. For every f ∈ F , Dom(f ) ⊆ GuardedVars(q). Proof. Let x ∈ Dom(f ). Let g be the ⊆-maximal predecessor of f such that x ∈ Dom(g). Then, the substitution x 7→ f (x) arises when line 5 or 14 is applied to some g-consistent state (db′ , q ′ ). By Claim 128, q ′ is saturated and normal. Consider first the case where x is replaced with a constant according to line 5 of the algorithm. Then x ∈ RootVars⇝ (q ′ ), and by Lemma 75 we have RootVars⇝ (q ′ ) ⊆ GuardedVars(q ′ ). By substitution-guardedness, GuardedVars(q ′ ) ⊆ GuardedVars(q). In particular, RootVars⇝ (q ′ ) ⊆ GuardedVars(q), hence x ∈ GuardedVars(q). Consider then the case where x is replaced with a constant according to line 14 of the algorithm. This substitution is relative to some F ∈ q ′ such that Key(F ) = ⊥ and x ∈ NonKeyVars(F ). Since q ′ is normal, ⊥ → x ∈ Ki (q ′ ). Consequently, as q ′ is pruned, we obtain x ∈ OutK⇝ (q′ ) (⊥) ⊆ GuardedVars(q ′ ). By substitution-guardedness, this leads to x ∈ GuardedVars(q). ◁ A function f ∈ F is called maximal if it is ⊆-maximal among all functions of F; it is saturated-maximal if it is ⊆-maximal among all saturated functions of F. We denote by M the set of all maximal functions, and by SM the set of all saturated-maximal functions. Each function in M corresponds to one computation branch. Our aim is to construct a polynomial upper bound for |M|. If f ∈ M is not saturated, then Pred(f ) is saturated, extending to a function f ′ ∈ SM (where possibly Pred(f ) = f ′ ). Therefore, we can define a function G : M → SM such that Pred(f ) ⊆ G(f ). We claim that |M| is polynomial in (db, q) if |SM| is polynomial in (db, q). ▷ Claim 130. Let (db, q) be the initial input. There exists a polynomial p such that |M| ≤ |SM| · p(||db||, ||q||).

(28)

Proof. It suffices to construct p such that |G−1 [{f }]| ≤ p(||db||, ||q||), for each f ∈ SM. Fix f ∈ SM. The function f has at most ||q|| predecessors in F. Moreover, each predecessor f ′

M. Hannula

87

has at most ||db′ || extensions f ∗ ∈ M such that G(f ∗ ) = f , for some intermediate database db′ satisfying (27). The claim follows from this.

◁

Next, we prove that |SM| is polynomial in (db, q). We begin with the following claim. ▷ Claim 131. Let (db, q) be the initial input. Let f ∈ F, and let (db′ , q ′ ) be an f -consistent c state. Let F := S(x, y, ⃗c) ∈ q c be such that x ∈ GuardVars(q) and x → y ∈ Kc (q). Then (q ′ ) contains one of F, S(x, f (y), ⃗c), S(f (x), f (y), ⃗c). c

Proof. The query (q ′ ) contains an atom of the form S(a, b, ⃗c), S(x, b, ⃗c), or S(x, y, ⃗c). This is an immediate consequence of Claim 128 and Item 4∗ of substitution-guardedness (Definition 118). Since (db′ , q ′ ) is an f -consistent state, it must be the case that b = f (y) and a = f (x). ◁ Let f ∈ SM. By definition, there exists a state (db′ , q ′ ) where q ′ is f -consistent and db′ is q ′ -saturated. For a variable x ∈ Vars(q ′ ), choose G ∈ q ′ such that x ∈ Vars(G). Then, since db′ is q ′ -saturated, we can choose a valuation θ over Vars(G) such that θ(G) ∈ db′ . Let us extend f by setting x 7→ θ(x). Let f ∗ denote the extension of f obtained by repeating this procedure for any x ∈ Vars(G). As adom(db′ ) ⊆ adom(db) by substitution-guardedness, we note that f ∗ remains a partial function Vars(q) to adom(db). Moreover, it can be seen that GuardVars(q) ⊆ Dom(f ∗ ); informally, at substitution any guard over q is either itself substituted or remains a guard over q ′ (by Item 6∗ of substitution-guardedness), and at pruning any guard remains a guard (by Item 6 of guardedness). ▷ Claim 132. Let (db, q) be the initial input. Let f, g ∈ SM. Then f ∗ ↾GuardVars(q) = g ∗ ↾GuardVars(q) implies f = g. Proof. Suppose that f = ̸ g. By symmetry, we may assume that Dom(f ) ⊆ Dom(g). Since both functions are saturated-maximal, it holds that f ̸⊆ g. In particular, there exists y ∈ Dom(f ) such that f (y) ̸= g(y). If y ∈ GuardVars(q), we are done. Thus, suppose y∈ / GuardVars(q). By Claim 129, it holds that y ∈ GuardedVars(q). Then, there exists an edge x → y ∈ Kc (q) with x ∈ GuardVars(q). Since x ̸= y and q is normal, this is witnessed by an atom F = S(x, y, ⃗c) ∈ q c , where ⃗c is a sequence of constants. Consider the state (dbf , q f ) such that q f is f -consistent and dbf is q f -saturated. By Claim 131, q f contains one of F , S(x, f (y), ⃗c), S(f (x), f (y), ⃗c). Since y ∈ Dom(f ), it follows that y ∈ / Vars(q f ), and consequently it is the case that q f contains either S(x, f (y), ⃗c) or S(f (x), f (y), ⃗c). Consider also the state (dbg , q g ) such that q g is g-consistent and dbg is q g -saturated. Similarly, we obtain that q g contains either S(x, g(y), ⃗c) or S(g(x), g(y), ⃗c). Assume first that qf contains S(f (x), f (y), ⃗c). Since Dom(f ) ⊆ Dom(g), we obtain that qg contains S(g(x), g(y), ⃗c). Since dbf is q f -saturated and dbg is q g -saturated, we have that S(f (x), f (y), ⃗c) ∈ dbf and S(g(x), g(y), ⃗c) ∈ dbg . By Item 3 of substitution-guardedness, we have dbf ↾S ⊆ db↾S and dbg ↾S ⊆ db↾S . As db is q-saturated and x → y ∈ Kc (q), it follows from f (y) ̸= g(y) that f (x) ̸= g(x). Specifically, this means that f ∗ (x) ̸= g ∗ (x). Assume then that q f contains S(x, f (y), ⃗c). By construction, there exists an atom G ∈ q f and a valuation θ over Vars(G) such that θ(G) ∈ dbf and θ(x) = f ∗ (x). Since dbf is q f -saturated,

88

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

we can extend θ to a valuation θ∗ such that S(θ∗ (x), f (y), ⃗c) ∈ dbf . In particular, this means that S(f ∗ (x), f (y), ⃗c) ∈ dbf . Furthermore, qg contains S(x, g(y), ⃗c) or S(g(x), g(y), ⃗c), and analogously we obtain, in both cases, that S(g ∗ (x), g(y), ⃗c) ∈ dbg . Then, as in the previous paragraph, we obtain from f (y) ̸= g(y) that f ∗ (x) ̸= g ∗ (x). Hence we have established that f ∗ ↾GuardVars(q) ̸= g ∗ ↾GuardVars(q) .

◁

By the previous claim and Lemma 74, we now obtain the following sequence of inequalities: |SM| ≤ |adom(db)||GuardVars(q)| ≤ |adom(db)|#srcSCC(K(q)) ≤ |adom(db)|c . This, together with Claim 130, establishes the existence of a polynomial p′ such that |M| ≤ p′ (||db||, ||q||), concluding thereby step (B2). The combination of (B1) and (B2) proves that Solve(db, q) runs in polynomial time in the input, concluding step (B). ◀

H

Hardness without Source SCC Bound

We here provide the proof for the theorem appearing in the conclusion. ▶ Theorem 28. CERTAINTY(sjfBCQU,A ) is ΠP2 -complete. Proof. The upper bound is simple and well-known. We prove the lower bound. We use the following well-known ΠP2 -complete problem. An instance of ∀∃3SAT consists of a quantified Boolean formula ψ = ∀x1 . . . ∀xm ∃xm+1 . . . ∃xm+n φ, where φ = C1 ∧ · · · ∧ Cℓ is a 3-CNF formula over the variables x1 , . . . , xm+n . The question is whether the formula is true. It is well known that ∀∃3SAT is ΠP2 -complete. For a clause Ci , let Ci,j denote its jth literal, and for a literal l ∈ {x, ¬x}, let v(l) = x denote the underlying variable. Given (b1 , b2 , b3 ) ∈ {0, 1}3 , we write (b1 , b2 , b3 ) |= Ci if assigning bj to the variable v(Ci,j ) satisfies Ci . We define q := {Ri (c, xi ) | i ∈ [m]} ∪ {S(yi , v(Ci,1 ), v(Ci,2 ), v(Ci,3 )) | S ∈ {Ti , Ui }, i ∈ [ℓ], } and db :={Ri (c, b) | i ∈ [m], b ∈ {0, 1}} ∪ {S((b1 , b2 , b3 ), b1 , b2 , b3 ) | S ∈ {Ti , Ui }, i ∈ [ℓ], (b1 , b2 , b3 ) |= Ci }, where c is a constant. Clearly, (db, q) can be constructed from ψ in polynomial time. It is straightforward to verify that q belongs to sjfBCQU,A . In particular, the atoms Ti , Ui do not attack any atom, and the atoms Ri do not attack any atoms Rj where j = ̸ i. Furthermore, we observe that the relations Tidb , Uidb are consistent, while the relations Ridb are inconsistent.

M. Hannula

Algorithm 6 Solve(db, q)

Input : A saturated database db and a saturated and normal query q ∈ sjfBCQU,A . Output : true iff (db, q) ∈ CERTAINTY. 1 while Vars(q) ̸= ∅ do 2 if OutK⇝ (q) (⊥) = ∅ then 3

4 5

6 7 8

9 10

11 12

13 14

15 16 17

18

choose the ≺-least non-attacked variable x ∈ RootVars⇝ (q) with OutKc (q) (x) = {x}; // Lemma 70; {x} is substitutable, case (i) foreach f : {x} → adom(db) do s ← Substitutef (db, q); // Lemma 25 if s ̸= false and Solve(s) = true then return true; return false; // Lemma 127 else (db, q) ← Try(Prune(db, q)); // Lemma 22 if OutK⇝ (q) (⊥) ̸= ∅ then Select ≺-least F ∈ q with Key(F ) = ⊥ and NonKeyVars(F ) ̸= ∅; // Pruning implies that Y is substitutable, case (ii) foreach f : Y → adom(db) such that Ff ∈ db do s ← Substitutef (db, q); // Lemma 25 if s = false or Solve(s) = false then return false; return true; return true; // Saturation of db guarantees that q ⊆ db and db is consistent.

We claim that ψ is true if and only if (db, q) ∈ CERTAINTY(sjfBCQU,A ). (⇒) Let r be a repair of db. Let θ be the valuation over x1 , . . . , xn such that Ri (c, θ(xi )) ∈ r, for i ∈ [m]. Assuming φ is satisfiable, we can extend θ to a valuation θ′ over x1 , . . . , xm+n such that θ′ |= φ. In particular, for each clause Ci , it holds that θ′ (v(Ci,1 ), v(Ci,2 ), v(Ci,3 )) |= Ci . Hence, S(θ′ (v(Ci,1 ), v(Ci,2 ), v(Ci,3 )), θ′ (v(Ci,1 )), θ′ (v(Ci,2 )), θ′ (v(Ci,3 ))) ∈ db, for S ∈ {Ti , Ui }. By consistency of Tidb , Uidb , it follows that θ′ (q) ⊆ r. (⇐) Let θ be an arbitrary valuation over x1 , . . . , xn . Choose a repair r such that Ri (c, θ(xi )) ∈ r, for i ∈ [m]. Assuming (db, q) ∈ CERTAINTY(sjfBCQU,A ), there exists a valuation ξ over x1 , . . . , xm+n such that ξ(q) ⊆ r. Clearly, ξ must agree with θ on the variables x1 , . . . , xn , so it is an extension of θ to the variables xm+1 , . . . , xm+n . Now, for S ∈ {Ti , Ui }, it holds that S(ξ(yi ), ξ(v(Ci,1 )), ξ(v(Ci,2 )), ξ(v(Ci,3 ))) ∈ r,

89

90

Getting to the Root: A Combined Complexity Perspective on Consistent Query Answering

which entails ξ(v(Ci,1 ), v(Ci,2 ), v(Ci,3 )) |= Ci . Thus ξ |= φ, hence ψ is true.

◀

Related documents

Record · ID 429467 · SHA-256 ef5f790a67e4f076
Retrieved via Conceptio: every document is proof-bundled with source, license, and retrieval metadata.
Bring this data into your agent: Connect via MCP or API · 20 free credits to start · no card required
Read the Docs → · View CLI source on GitHub · Conceptio Open Knowledge Archive