First-Order Rewritability of Rule-Based Ontology Mediated Queries with Negation
Abstract
The idea of using an ontology to enrich user queries with domain knowledge has attracted considerable attention from the database and KR communities during the last fifteen years or so. The ontology and the user query can be conveniently seen as two components of one composite query, called ontology-mediated query (omq), while an omq language collects all such omqs where the ontology is expressed using the ontology language and the user query comes from the query language . The evaluation problem for rule-based omq languages of the form , where is a rule-based ontology language, i.e., it collects ontologies modelled using tuple-generating dependencies (a.k.a. existential rules), and is the language of conjunctive queries, has been extensively studied in the literature. In particular, the notion of first-order rewritability of such languages, i.e., the property of being able to rewrite every omq from the language in question to an equivalent first-order query, has been studied in depth. This research effort led an algorithmic characterization of when a rule-based omq language is first-order rewritable. More precisely, there is a uniform algorithm such that, for every rule-based ontology language , the omq language is first-order rewritable iff for every omq from , the algorithm on input terminates and constructs a first-order rewriting of . The question that we are interested in is whether the above algorithmic characterization can be extended to rule-based omq languages of the form , where is the language of conjunctive queries with the useful feature of negation. The goal of this work is to initiate effort towards the settlement of the above highly non-trivial question. To this end, we provide a new algorithm, which is a non-trivial extension of the algorithm for positive omqs, and show the following: under the Skolem semantics, a well-established approach for defining the answer to a rule-based omq when the user query can use negation, the proposed algorithm is a first-order rewriter for , where is the language of linear or acyclic tuple-generating dependencies, two central rule-based ontology languages that ensure first-order rewritability for positive omqs. We strongly believe that the new algorithm can serve as a good starting point towards the full settlement of our main question.
Keywords and phrases:
ontology-mediated queries, tuple-generating dependencies, conjunctive queries with negation, first-order rewritabilityCopyright and License:
2012 ACM Subject Classification:
Theory of computation LogicFunding:
This work was supported by the University of Cyprus, NextGenerationEU through the project FAIR (CUP H23C22000860006), Italian Ministry of University and Research through the project PRODE (CUP H53D23003420006), Italian Ministry of Enterprises and Made in Italy through the projects ASVIN (CUP B29J24000200005) and PreDiCI (CUP B29J24000300005), and Calabrian Region through the project NextGenGuides (CUP J39I24002040005).Editors:
Balder ten Cate and Maurice FunkSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Ontology-mediates Queries.
Rule-based languages lie at the core of numerous areas of central importance to databases and artificial intelligence. It is widely accepted that tuple-generating dependencies (tgds) form a prominent rule-based language, originally introduced as a unifying framework for database constraints [1]. Tgds are first-order sentences of the form , where (the body) and (the head) are conjunctions of relational atoms, and they essentially state that certain tuples in a database imply the presence of some other tuples in the database. The last fifteen years or so, they have been employed for knowledge representation purposes, in particular, as an alternative way to model ontologies that are used to enrich user queries, typically conjunctive queries, with domain knowledge. The marriage of ontologies with user queries has been originally proposed in the context of ontology-based data integration in order to facilitate access to data that is heterogeneous and incomplete [14]. The ontology and the user query can be conveniently seen as two components of one composite query, called ontology-mediated query (omq) [6]. In this context, the main problem of interest is to compute the answer to such an omq over a database. In particular, given a database and an omq , where is a finite set of tgds (the ontology) and a conjunctive query (the user query), the goal is compute the certain answers to over , denoted , which are all the tuples of database elements that are answers to no matter on which model of and it is evaluated, i.e., the answers to derived by every model of and .
Answering Omqs via Query Rewriting.
Building ontology-aware database systems from scratch, with sophisticated optimization techniques, is a highly non-trivial task that requires a great effort. An alternative approach towards practical implementations of evaluating an omq over a database is to use conventional database systems. However, such systems are unaware of ontologies. This obstacle can be addressed by query rewriting: the omq is rewritten into a new query , the so-called rewriting, which has the same answer as the omq over all input databases, i.e., for every database , coincides with the answer to over . It is of course essential that the query is expressed in a query language that can be handled by standard database systems. The typical target query language that is considered in this setting is that of first-order queries. The problem of rewriting omqs into first-order queries, when the ontology is a set of tgds and the user query a conjunctive query, has been extensively studied. This research effort led to several syntactic classes of tgds that give rise to first-order rewritable classes of omqs , i.e., every omq of , where is a set of tgds from and a query from the class of conjunctive queries , admits a first-order rewriting, together with prototype systems illustrating the effectiveness of this approach; see, e.g., [7, 8, 10, 12]. What is even more remarkable is the fact that every first-order rewritable tgd-based class of omqs, no matter how the class of tgds is defined, can be handled via one uniform rewriting algorithm. More precisely, there is a resolution-based algorithm such that, for every class of tgds, the omq class is first-order rewritable iff for every omq from , on input terminates and returns a first-order rewriting of [12]. This provides an algorithmic characterization of when an omq class , where is a class of tgds, is first-order rewritable.
Adding Negation.
Although conjunctive queries form a key tool for querying data, they are not able to express negation, a very useful construct that allows us to express non-monotonic queries that naturally appear in real-life scenarios. It is thus very natural to consider classes of tgd-based omqs , where the user query comes from the class of conjunctive queries with negation, denoted . The problem of evaluating such non-positive omqs has also attracted attention in the literature; see, e.g., [3, 4, 7, 9, 11]. Having said that, answering non-positive omqs of this kind via first-order rewritability, unlike the case of positive omqs discussed above, is largely unexplored. An interesting question is whether the algorithmic characterization discussed above concerning the first-order rewritability of positive omqs can be extended to non-positive omqs. More precisely, we are asking whether there exists one uniform algorithm, which does not depend on any class of tgds, that acts as a first-order rewriter for every class of tgd-based omqs that is first-order rewritable. The goal of this work is to initiate effort towards the settlement of this highly non-trivial question. But first we need to discuss how the answer to such omqs should be defined, and, in fact, whether the standard certain answers semantics is conceptually meaningful in this case.
Consider the database and the omq , where consists of the tgd and is the Boolean query . The answer to over is empty (i.e., the query is false) since there exists at least one model of and that does not entail ; e.g., the model does not entail due to the atom since the only way to match the positive part of to is by mapping both variables and to , whereas belongs to . On the other hand, is not supported by and . Indeed, there is no reason to derive the atom since the instance is also a model of and . Hence, the model should not be a valid reason for the non-entailment of by and . The above example can be generalized and show that for a database and an omq , where is set of tgds and a conjunctive query with at least one negated atom, there is always a model of and such that the answer to over is empty – is simply the model that collects all the atoms that can be formed using the predicates of the schema and the constants in and .
The above discussion leads to the natural idea that has been adopted in the literature of considering only models without redundant information that may distort the expected answer to the given omq, i.e., considering only minimal models. Coming back to the above example, it is easy to see that is entailed by every minimal model of and . Hence, the main problem of interest in this context is as follows: given a database and an omq , where is a set of tgds and a conjunctive query with negation, compute all the tuples of database elements that are answers to derived by every minimal model of and .
Once we adopt the minimal model semantics, there is one more aspect that we need to carefully consider, which has to do with the existentially quantified variables in tgd-heads, that greatly affects the obtained semantics: either keep those existentially quantified variables, or eliminate them via the standard technique of Skolemization. Both approaches are quite relevant and have been considered in the literature; see, e.g., [2, 9]. In this work, we focus on the latter, which we call Skolem semantics. Let us clarify that for positive tgd-based omqs, considering all the models or only the minimal models, and keeping or eliminating the existentially quantified variables in tgd-heads, lead to the exact same semantics.
Our Contribution.
This work makes a first non-trivial step towards an algorithmic characterization of when an omq class , where is a class of tgds, is first-order rewritable. In particular, we establish the existence of an algorithm that, no matter which class of tgds we consider among linear or acyclic tgds – two central classes of tgds that ensure first-order rewritability for positive omqs – is a first-order rewriter for under the Skolem semantics. This new algorithm is significantly more sophisticated than the one for positive omqs as it needs to carefully treat the negative part of the user query. We strongly believe that it can serve as a good starting point towards an algorithmic characterization of first-order rewritability for non-positive classes of tgd-based omqs under the Skolem semantics. Interestingly, the proposed algorithm produces rewritings that fall in a novel fragment of first-order queries, which is strictly less expressive than the full language of first-order queries. We also show that unions of conjunctive queries with equality and negation are not powerful enough for our purposes as one might think, influenced by the fact that unions of conjunctive queries with equality are enough for positive tgd-based omqs.
2 Preliminaries
We proceed to introduce the basic notions about relational instances and databases, relational queries, and tuple-generating dependencies that will be used throughout the paper. For brevity, given an integer , we may write for the set of integers .
Basic Vocabularies.
Let , and be disjoint countably infinite sets of constants, (marked) nulls and variables, respectively. We further consider the countably infinite set of function symbols (each of them associated with a positive arity), which is disjoint from , and . We assume that different constants represent different objects and different function symbols represent different functions (unique name assumption). Functional terms are inductively defined as follows: (i) variables are functional terms, and (ii) , where , is an -ary function symbol of , and are functional terms, is a functional term. Ground functional terms are defined similarly: (i) constants of are ground functional terms, and (ii) , where , is an -ary function symbol of , and are ground functional terms, is a ground functional term. We refer to constants, nulls, variables, functional terms, and ground functional terms as terms.
Relational Atoms and Homomorphisms.
A schema is a finite set of relation names (or predicates) with associated positive arity. We write to say that has arity ; we may write for the integer . A (relational) atom over is an expression of the form , where and is an -tuple of terms; note that we may treat a tuple as the set of its elements. For a set of atoms, we write and for the set of terms and variables, respectively, mentioned in the atoms of .
A central notion is that of homomorphism that allows us to embed a set of atoms into another set of atoms while preserving its structure. Formally, a homomorphism from a set of atoms to a set of atoms is a function that is the identity on with for every ; for a term , . We write to denote that there is a homomorphism from to .
Relational Instances and Databases.
We make the distinction between instances that mention only constants and nulls and instances that mention only ground functional terms. A null instance over a schema is a (possibly infinite) set of atoms over that mention only constants and nulls. A functional instance over is a (possibly infinite) set of atoms over that mention only ground functional terms. A database over is a non-empty finite set of atoms over that mention only constants. Clearly, a database over is trivially a null and a functional instance over . We write for the set of terms occurring in an instance .
First-order Queries.
We assume the reader is familiar with the syntax and semantics of first-order logic. We consider only function-free first-order formulas, i.e., formulas that mention variables and constants of , but no function symbols. For such a formula , we write and for the set of its free variables and the set of constants occurring in it, respectively. We use the standard symbol for the notion of satisfaction of sentences. A first-order query over a schema is an expression , for , where is a first-order formula over and is a tuple over such that each variable of occurs in at least once, i.e., . Note that a first-order query is always a finite object, i.e., the first-order formula above is finite. For a tuple of constants , we write for the sentence obtained from after replacing each occurrence of with , for each . Given a database over , the answer to over is the set .
Conjunctive Queries with Negation.
A restricted class of first-order queries that is crucial for our work is that of conjunctive queries with negation. Formally, a conjunctive query with negation (ncq) over a schema is a first-order query over with being a formula of the form for and , where (i) and are atoms with and being tuples of constants and variables mentioned in and , for each and , and (ii) for each , each variable in is mentioned in for some ; the latter condition means that the negation in is safe. Note that if , i.e., there are no negated atoms, then is simply a conjunctive query (cq). We write for the non-empty set of atoms and for the (possibly empty) set of atoms . Let be the set of all ncqs and the set of all cqs. It is well-known that the semantics of ncqs can be conveniently defined via homomorphisms. Given a null or functional instance , the answer to over , denoted , is the set of all tuples such that (i) there is a homomorphism from to with , and (ii) for each , . Note that, unlike arbitrary first-order queries, the answer to ncqs is defined over arbitrary instances, and not only over databases, since this is needed for our technical development.
Tuple-generating Dependencies.
A tuple-generating dependency (tgd) over a schema is a first-order sentence where and are (non-empty) conjunctions of atoms over that mention only variables. For brevity, we write as and use comma instead of for joining atoms. We call and the body and head of , denoted and , respectively. Note that we may treat a conjunction of atoms as the set of its atoms, which means that and can be treated as sets of atoms. We denote by the so-called frontier variables of , i.e., the universally quantified variables of that appear in . Let be the family of all finite sets of tgds; in the rest of the paper, a set of tgds is always finite. A class of tgds is simply a subset of . A null instance over satisfies , written , if, whenever via , then via that agrees with on . The null instance satisfies a set of tgds, written , if for each . Given a database over , a model of and is a (possibly infinite) null instance such that .
From Tuple-generating Dependencies to Logic Programs.
We now discuss how a set of tgds can be transformed into a logic program by eliminating the existentially quantified variables via Skolemization. This is needed for defining the semantics of ontology-mediated queries below. The Skolemization of a tgd of the form , denoted , is the logic programming rule (or simply LP-rule), where is a vector of function symbols , one for each variable . For example, the Skolemization of the tgd is the LP-rule . The Skolemization of a set of tgds, denoted , is the set of LP-rules . A functional instance satisfies , where is a tgd as above, written , if, whenever via a homomorphism , then via . The instance satisfies for a set of tgds, written , if for each . Given a database , a model of and is a (possibly infinite) functional instance such that . A model of and is minimal if there is no that is a model of and . In fact, it is easy to show that there is a unique minimal model of and , and thus, we can refer to the minimal model of and , denoted .
Ontology-mediated Queries.
An ontology-mediated query (omq) over a schema is a pair , where is a set of tgds over (the ontology) and is an ncq over (the user query). For a class of tgds, let be the class of omqs , where and . The class of omqs is defined analogously. One of the standard ways for defining the answer to an omq is to first convert into the logic program and then evaluate the user query over the unique minimal model of the input database and . Formally, given a database and an omq , the answer to over , denoted , is defined as . At this point, let us stress that this semantics extends the well-established certain answers semantics for positive omqs, where the user query is a cq without negation. More precisely, for an omq over , where is a cq without negation, the certain answers of over a database , denoted , is defined as , where collects all the models of and . It is then not difficult to show that .
Querying the Unique Minimal Model and the Chase Procedure.
Given a database and an omq , we can use the chase procedure, a useful tool when reasoning with tgds, to construct a model of and that is isomorphic to the unique minimal model of and , which in turn can be used for computing . This allows us to directly work with the original set of tgds, instead of its Skolemized version, which is technically more convenient. We assume the reader is familiar with the oblivious version of the chase procedure; see, e.g., [5]. Given a chase derivation of a database w.r.t. a set of tgds, which is essentially a sequence of instances where and, for each , is obtained from by applying a tgd of , we write for the result of , that is, the instance . It is not difficult to show that there is a bijection from the constants and nulls in to the ground functional terms in , which is the identity on , such that and . Thus, we get the following result that allows us to use the chase procedure for our purposes:
Proposition 1.
Consider a database and an omq . For every chase derivation of w.r.t. , it holds that .
3 Ontology-mediated Queries and First-order Rewritability
Our main objective is to study the central concept of first-order rewritability for omqs, which essentially states that we can compute the answer to an omq by relying on first-order query evaluation. The formal definition of first-order rewritability for omqs follows:
Definition 2 (First-order Rewritability).
Consider an omq over a schema . A first-order rewriting of is a first-order query over such that, for every database over , . A class of omqs, where , is first-order rewritable if every omq from has a first-order rewriting. A first-order rewriter for a first-order rewritable class of omqs is a deterministic algorithm that takes as input an omq and constructs a first-order rewriting of . The notions of first-order rewritability and first-order rewriter for a class of omqs are defined analogously.
The notion of first-order rewritability for positive classes of omqs, i.e., classes of omqs , where , has been extensively studied in the database and KR literature. As discussed in Section 1, this research effort led to an algorithmic characterization:
Theorem 3 ([12]).
There exists a deterministic algorithm such that, for every class of tgds, is first-order rewritable iff is a first-order rewriter for .
We are still far from an analogous characterization for non-positive omqs. However, we can establish the existence of an algorithm that, no matter which class of tgds we consider among linear or acyclic tgds, it is a first-order rewriter for . The syntactic notions of linearity [7] and acyclicity [13], which we recall below, give rise to central classes of tgds that ensure first-order rewritability for positive omqs:
- Linearity.
-
A tgd is called linear if it has exactly one atom in its body, i.e., . We write for the class of linear tgds, i.e., the family of all finite sets of linear tgds.
- Acyclicity.
-
The notion of acyclicity essentially forbids recursive statements. This is typically formalized via the acyclictiy of the predicate graph of a set of tgds. The predicate graph of , denoted , is a directed graph , where (the set of nodes) consists of all the predicates occurring in , and (the set of edges) contains an edge iff there is a tgd that mentions in its body and in its head. Essentially, an edge encodes the fact that depends on . We say that is acyclic if is acyclic. We write for the family of all finite sets of tgds that are acyclic.
The main result of our work, which can be seen as a first non-trivial step towards an algorithmic characterization of first-order rewritability for non-positive omqs, follows:
Theorem 4.
There exists a deterministic algorithm that is a first-order rewriter for and .
The rest of the paper is devoted to discussing the proof of the above result.
Target Query Language
Before we present the algorithm in Section 4, and show that is indeed a first-order rewriter for , where , let us conclude this section by discussing its target query language. In the case of positive omq classes , we know that there is no need to go beyond unions of cqs with equality, which forms a strictly less expressive query language than first-order queries; let be the set all unions of cqs with equality. In other words, for every omq from , the algorithm , provided by Theorem 3, on input outputs a first-order rewriting of that falls in . With this in mind, one may be tempted to think that the algorithm should target a query that falls in the language of unions of cqs with equality and negation, denoted . However, we can show that the latter language is not expressive enough for our purposes.
Proposition 5.
There exists an omq , where and , that admits a first-order rewriting but, for every query from , there exists a database such that .
As we shall see, whenever terminates, the obtained query falls in a restricted class of first-order queries, which we call unions of conditional conjunctive queries with equalities, that forms a query language that is strictly less expressive than arbitrary first-order queries. Roughly, a conditional conjunctive query with equality is a cq with equality with additional conditions that can be expressed via inequalities and the negation of conjunctions of atoms (hence the name conditional cq with equality). For instance, ncqs form a special case of conditional cqs with equality. Formally, a conditional conjunctive query with equality (ccq=) over a schema is a first-order query over with being a formula of the form
for and (if , then the negated disjunction is not present), where
-
is a non-empty conjunction of atoms and equalities that mention constants and variables of , which means that is a cq with equality; for brevity, we write for the set of relational atoms and for the set of equalities in ,
-
is a (possibly empty) conjunction of inequalities over and , and
-
, for each , is a non-empty conjunction of atoms that mention constants and variables of with and .
Let be the set of all ccqs with equality. The semantics of ccqs with equality can be defined via homomorphisms. Formally, given a null instance , the answer to over , denoted , is the set of all tuples of constants such that (i) there is a homomorphism from to with , (ii) for each in , , (iii) for each in , , and (iv) for each , there is no homomorphism from to . A union of ccqs with equality (uccq=) over is a first-order query over with being a formula of the form , for , and being a ccq=, for every . Let be the set of all uccqs with equality. Given a null instance , the answer to over , denoted , is . Let us stress that uccqs with equality are indeed strictly less expressive than first-order queries. For instance, we can show that the first-order query cannot be equivalently expressed as a uccq=, which implies the following result:
Proposition 6.
There exists a first-order query such that, for every query from , there exists a database with .
In our analysis, we will also consider unions of ccqs with equality that have infinitely many disjuncts. Formally, an infinitary union of ccqs with equality over is an expression , for , where is a formula , the set of free variables of is , and is a ccq=, for every . The answer to over a null instance , denoted , is . Note that, strictly speaking, is not a first-order query since it is an infinite object, whereas first-order queries are always finite.
4 A Uniform First-order Rewriter
We now establish the existence of the algorithm claimed in Theorem 4. To this end, we are going to show the following, which is the main technical result of our work:
Proposition 7.
There exists a nondeterministic algorithm such that:
-
1.
For every with being first-order rewritable and every omq , the following holds: every execution of leads to an infinitary uccq= such that, for every database , .
-
2.
For every and every omq , it holds that every execution of terminates.
As we shall discuss later, the assumption in item (1) that is first-order rewritable is crucial for guaranteeing that a possibly non-terminating execution of on input converges into an infinitary uccq= such that, for every database , . Since the properties stated in items (1) and (2) of Proposition 7 hold for every execution of , we get that every branch of the computation tree of corresponds to the computation of a deterministic algorithm that is a first-order rewriter for , where , as needed. The rest of the section is devoted to discussing the proof of Proposition 7. We start by presenting the nondeterministic algorithm .
4.1 The Nondeterministic Algorithm NRewrite¬
As for positive omqs, the high-level idea of the rewriting algorithm is to start from the positive part of the given ncq and mimic backwards the chase steps that lead to its image in the result of the chase via resolution steps that use the tgds as rewriting rules until we reach the input database; the latter is implemented using the notion of chunk unifier that has been used for rewriting positive omqs. This rewriting process should lead to a union of ccqs with equality that can be directly evaluated over the input database. Unlike the positive case, however, we need to carefully treat the negative part of the query, which makes our task significantly more challenging compared to the positive case. We start by recalling the notion of chunk unifier from [5], which is the building block of our algorithm, explain how it operates on ccqs with equality, and then discuss the rewriting algorithm itself.
Chunk Unifiers
Let and be non-empty sets of atoms with constants and variables. The sets and unify if there is a function , which is the identity over constants, called unifier for and , such that . A most general unifier (mgu) for and is a unifier for and such that, for each unifier for and , for some function . It is known that if two sets of atoms unify, then there is a unique mgu (up to variable renaming). Now, consider a set of atoms with constants and variables and a set . Consider also a tgd that does not share variables with . A (most general) chunk unifier of with that respects is a triple , where , , and is a (most general) unifier for and such that, for each existential variable of occurring in , (i) , and (ii) for every variable with , implies .
We now proceed to define the notion of chunk unifier for formulas that define ccqs with equality. Recall that a ccq= is a first-order query with being a formula of the form
for and , where (i) is a non-empty conjunction of atoms and equalities that mention constants and variables of , (ii) is a (possibly empty) conjunction of inequalities over constants and variable of , and (iii) , for each , is a non-empty conjunction of atoms that mention constants and variables of with and . In what follows, for convenience, we refer to formulas of the above form as formulas in rewrite form. For technical clarity, we will actually focus on certain formulas in rewrite form that we call saturated. Formally, a formula in rewrite form as above is saturated if (i) for every pair of distinct variables in , either the equality occurs in or the inequality belongs to , and (ii) for every variable and constant , either occurs in or belongs to . This can be done w.l.o.g. since every ccq= can be equivalently rewritten as a uccq= that is defined via a disjunction of formulas in rewrite form that are saturated.
Consider now a formula in rewrite form as above that is saturated. Given a subset of (recall that a conjunction of atoms may be treated as a set of atoms), a variable is called shared if it belongs to ; in simple words, is shared if its a free variable of or it also occurs somewhere in other than the atoms of . Consider also a tgd . A (most general) chunk unifier of with is a quadruple , where (i) is a (most general) chunk unifier of with that respects the shared variables of , (ii) is the identity on , and (ii) . Note that, strictly speaking, is not defined on the variables of , and thus, we adopt the convention that is the identity over those variables.
Resolvents
Intuitively, an mgcu of with essentially indicates that the subset of can be satisfied in the result of the chase by applying the tgd . Thus, we can mimic this chase application backwards by resolving using , which is done by simply replacing in with and properly updating the variables according to ; note that specifies how to update the variables of that are not already in , and thus, is a well-defined function. It should not be overlooked, however, that such a resolution step may lead to an unsafe formula, i.e., a formula where the negative part (including the inequalities) has a free variable that does not appear in the positive part, that is also not saturated. Hence, after resolving using , we need to apply a polishing step that converts the obtained formula into a safe formula in rewrite form that is saturated. Of course, the polishing should be carefully performed in order to avoid the generation of undesirable formulas that will lead to a uccq= that either computes wrong answers (it is unsound) or misses to compute correct answers (it is incomplete).
The above intuitive discussion about the resolution and the polishing steps are formalized via the notion of -resolvent. In particular, the -resolvent of is defined as
where
-
, i.e., it collects the variables in other than the free variables of ,
-
is obtained from by (i) removing all the inequalities that mention a variable that does not occur in , and (ii) adding as conjuncts all the inequalities of the form , where and are different variables of , or and , or and , and
-
if ; otherwise,
where , and is the set of all functions of the form , where and , such that the following hold:
-
–
,
-
–
for each existential variable of , if is a constant, or a variable of , or an existential variable of other than , or a variable in , then ,
-
–
is the identity over , and
-
–
, for every variable .
-
–
The crucial polishing step is performed when we convert into and into . The conversion of into is done in the obvious way: item (i) is ensuring safety by removing inequalities, and item (ii) is performing the saturation of the formula by adding inequalities. We now elaborate on the sophisticated conversion of into . The two obvious polishing strategies that one might think of are:
- Polishing Strategy I.
-
For each , simply remove the conjunction of atoms as a whole if mentions a variable that is neither in nor in .
- Polishing Strategy II.
-
For each , remove only the atoms occurring in that mention a variable that is neither in nor in .
Although both strategies ensure safety, it is not difficult to show that they are both problematic. Loosely speaking, the first polishing strategy removes more than necessary from the negative part and this leads to an unsound result, whereas the second strategy removes less than necessary from the negative part, which leads to an incomplete result; this is illustrated via examples in the appendix (Section A). The way that we actually convert into in the definition of -resolvent somehow balances what we need to remove and what we need to keep in order ensure both the soundness and the completeness of the final result. The key idea underlying this conversion can be described as follows. Assume that is a subformula of such that (i) all the variables in occur in or , and (ii) is satisfied by the result of the chase due to some homomorphism that maps to the set of atoms obtained by a applying a trigger of the form during the construction of the chase. We then keep the conjunction consisting of the atoms of after updating their variables in such a way that the part of that we keep cannot be mapped to via the same homomorphism used to map to , which means that as a whole is not satisfied by the result of the chase due to .
The Algorithm NRewrite¬
We now have the key ingredients to discuss the nondeterministic algorithm , claimed in Proposition 7, which is depicted in Algorithm 1. It takes as input an omq from a class of omqs with the assumption that is first-order rewritable, and rewrites by proceeding in two phases: (i) the preparatory phase, where it converts into a set of formulas in rewrite form that are saturated by considering all the specialized versions of and properly rewriting their negative part, and (ii) the rewriting phase, where it exhaustively rewrites the formulas produced during the preparatory phase via resolution steps and constructs formulas in rewrite form that are saturated, which are stored in a set . The final result is , which is, in general, an infinitary uccq=. We proceed to discuss the details of the preparatory phase and the rewriting phase.
Preparatory Phase
Let be some arbitrary lexicographic order over such that (i) the constants are preceding the variables, and (ii) the variables of are preceding the variables of . For a finite set of constants and variables, we write for the term of that precedes all other terms of according to . A partition of the set of terms occurring in , denoted , is called proper if, for each , contains at most one constant, i.e., two different constants occurring in appear in different sets of . Essentially, a proper partition of fixes the way that the variables in should be mapped to the constants of the input database, i.e., two variables should be mapped to the same constant iff they occur in the same set of . Furthermore, if a variable occurs in a set of that has a constant , then should be mapped to . To implement this intuitive idea, we further define the function in such a way that, for each , implies . Now, for a proper partition of , the algorithm builds the formula defined as
where are the variables occurring in , other than the variables of , and are the variables occurring in but not in . The procedure (see Algorithm 2) with input essentially rewrites the atom , via resolution steps that use the tgds of , into a disjunction of conjunctions of atoms. Crucially, the rewriting should not remove any of the variables in since, by definition, they also occur in the positive part of the formula . Moreover, it should not unify any of those variables with a constant or some other variable since the inequalities in state that, for , the variables and cannot be unified. In other words, should treat the variables occurring in as constants, and thus, the final result would be a disjunction of conjunctions of atoms where each disjunct contains all the terms . The above intuition is implemented by
-
1.
renaming all the variables in into new constants via a bijective function (i.e., if is a constant, otherwise is a new constant),
-
2.
exhaustively applying resolution steps (using the basic notion of mgcu of a set of atoms that respects a set of variables) in the expected way starting from , and
-
3.
finally, converting the constructed collection of sets of atoms into a disjunction of conjunctions of atoms after replacing each constant with by applying .
Note that during a resolution step the procedure considers the tgd obtained from by renaming each variable in to . This is a mechanism that allows us to avoid undesirable clatter among variables during a resolution step. Moreover, at each resolution step, the produced set of atoms is added to the collection only if there is no set of atoms such that can be homomorphically mapped to , i.e., is added to if there is no that is more general than since in this case will be redundant. The following lemma, which relies on the assumption that the input omq belongs to a class of omqs such that is first-order rewritable, is crucial in our development:
Lemma 8.
For every proper partition of , is a ccq=.
Now, the formula (in fact, the pair – this will be clarified in the discussion of the rewriting phase) is kept in the set if the query is satisfiable, i.e., if there is a database such that . By Lemma 8, is a ccq=. Hence, to be able to perform the above satisfiability check, we need a procedure that allows us to decide whether a query from is satisfiable. We can show the following result:
Lemma 9.
Deciding whether a query from is satisfiable is coNP-complete.
Note that the satisfiability procedure for ccqs with equality is also used in the rewriting phase of the algorithm. Now, if none of the queries , where is a proper partition of , is satisfiable (i.e., ), then we can show that for every database . Hence, it suffices to return a simple unsatisfiable ncq over the underlying schema. In case is not empty, then the algorithm proceeds with the rewriting phase in order to rewrite via resolution the formulas occurring in the pairs of the set .
Rewriting Phase
In this phase, the algorithm exhaustively rewrites the positive part of each formula of via resolution steps. During this process, it is important to keep track of the sequence of resolution steps that lead to a certain formula . This is because, for ensuring the soundness of the algorithm, we need to guarantee that in the sequence of resolution steps that lead to a formula , we use only active resolution steps, i.e., resolution steps that mimic different chase steps. To achieve this, we initially flag each formula of with the empty sequence of resolution steps, denoted , which will be updated accordingly during the rewriting process, and add the pair to . Then, for each pair and for each tgd , the algorithm considers all the valid mgcus of with such that is -active, and constructs the -resolvent of , denoted . Now, providing that is not blocked by some , the pair is added to , where is the sequence of resolution steps that lead to , that is, the sequence of resolution steps that led to plus the resolution step applied on using the tgd and the mgcu of with . We proceed to formalize the three auxiliary notions used above, namely validity, activeness, and blocking. Note that, as in , at each step we consider the tgd obtained from by renaming each variable in to in order to avoid undesirable clatter among variables during a resolution step. Crucially, there is no clutter among the variables introduced during the rewriting phase and those introduced by , since in the rewriting phase we use positive indices to rename variables, whereas in we use negative indices.
Validity.
The reason why we cannot use all the mgcus of with , but only the so-called valid ones, is because invalid mgcus lead to unsound resolution steps. By applying an invalid mgcu, we may produce a formula that gives rise to a satisfiable ccq= from a formula that defines an unsatisfiable ccq=, which is problematic; this is shown in the appendix (Section B). Validity ensures that the resolution of a formula that defines an unsatisfiable ccq= will produce a formula that defines an unsatisfiable ccq=. An mgcu of
produced either during the preparatory phase or the rewriting phase of the algorithm, with is valid if the ccq= , where and is the formula
for , is satisfiable. Note that is in rewrite form, but it might not be saturated. This is not problematic since we do not apply a resolution step on , but we only check whether it gives rise to a satisfiable ccq=; the latter is done using the algorithm from Lemma 9.
Activeness.
We now discuss the notion of activeness. Consider a formula-sequence pair , where , for and , which is produced during the rewriting phase of the algorithm and stored in , and a mgcu of with . As said above, the goal of activeness is to ensure that the resolution step that uses the pair mimics a different chase step than the resolution steps that use a pair occurring in . This is guaranteed by the following condition: we say that is -active if, for every , implies for and .
Blocking.
It is crucial for the termination of the algorithm (see item (2) of Proposition 7) not to add a formula in that gives rise to a ccq= that is redundant in the sense that its answer, no matter the input database, is always contained in the answer of a ccq= defined by a formula that is already in . Having said that, we can show that the containment problem for ccqs with equality is undecidable, which is a fact of independent interest. The latter essentially tells us that we need to isolate a condition over ccqs with equality that is sufficient for containment, can be effectively checked, and it ensures the termination of the algorithm whenever the input omq obeys linearity or acyclicity, despite the fact that some formulas that give rise to redundant queries will be unavoidably added to the set . This is the intention underlying blocking. Consider
and
that are produced during the rewriting phase of the algorithm. We say that blocks , denoted , if the following four conditions hold: (i) via a homomorphism that is the identity over , (ii) for each equality in , where either or and , the equality occurs in , (iii) for each inequality in , the inequality occurs in , and (iv) for each , there exists such that . This completes the description of , which is indeed nondeterministic since, in both of its phases, there is no fixed order in which we apply the resolution steps.
4.2 Correctness and Termination of
Correctness – Item (1) of Proposition 7
We first argue that every execution of the algorithm leads to an infinitary uccq=. Let be an arbitrary execution of . We proceed by considering the two cases where the set computed during the preparatory phase of the algorithm is empty or not. If , then terminates and returns an unsatisfiable ncq, which is trivially an infinitary uccq=. Assume now that . We proceed to argue that it consists of finitely many formulas of finite size. By Lemma 8, we get that, for every partition of , is a ccq=. This implies that is a formula in rewrite form of finite size. Moreover, since is finite, it is clear that there are finitely many different proper partitions of it. Consequently, consists of finitely many formulas (one for each proper partition of ) in rewrite form, each of finite size. With this fact in mind, to conclude that leads to an infinitary uccq= it suffices to observe that, for every pair of the form occurring in the set , and every valid mgcu of with , for some , the -resolvent of is, by construction, a formula in rewrite form of finite size with . Thus, for every pair that occurs in the (possibly infinite) set computed by the rewriting phase of the algorithm, it holds that is a formula in rewrite form of finite size with . This in turn implies that , which we denote by , is indeed an infinitary uccq=, as needed.
We finally need to argue that, for every database , ; recall that . To this end, we establish the following lemma, which, together with Proposition 1, implies the claim. Given a formula in rewrite form with , let .
Lemma 10.
Fix an arbitrary tuple . There exists a chase derivation of w.r.t. such that iff there exists such that .
Termination – Item (2) of Proposition 7
Fix an arbitrary execution of . By linearity and acyclicity, we get a database-independent bound on the number of atoms that can appear in the positive part of a formula produced by . This in turn allows us to show that the formulas produced by share finitely many positive parts (up to renaming of the non-free variables). Note, however, that this is not enough to conclude that the output of is finite since we may have several different formulas with the same positive part but different negative part. Interestingly, we can argue that the way the polishing of formulas is performed (see the discussion above about resolvents), ensures that only finitely many different negative parts (up to renaming of the non-free variables) can be produced, and thus, is finite.
5 Future Work
Although we are still far from an algorithmic characterization of first-order rewritability for non-positive classes of tgd-based omqs, where the user query is a cq with negation, we believe that the algorithm introduced in this work is a good basis towards such a characterization. In particular, since item (1) of Proposition 7 holds for every class of tgds such that is first-order rewritable, the next obvious step is to try to generalize item (2) of Proposition 7 to every class of tgds such that is first-order rewritable. This highly non-trivial task is our next target, which will establish the desired characterization.
References
- [1] Serge Abiteboul, Richard Hull, and Victor Vianu. Foundations of Databases. Addison-Wesley, 1995.
- [2] Mario Alviano, Michael Morak, and Andreas Pieris. Stable model semantics for tuple-generating dependencies revisited. In PODS, pages 377–388, 2017. doi:10.1145/3034786.3034794.
- [3] Mario Alviano and Andreas Pieris. Default negation for non-guarded existential rules. In PODS, pages 79–90, 2015. doi:10.1145/2745754.2745758.
- [4] Jean-François Baget, Fabien Garreau, Marie-Laure Mugnier, and Swan Rocher. Extending acyclicity notions for existential rules. In ECAI, pages 39–44, 2014. doi:10.3233/978-1-61499-419-0-39.
- [5] Gerald Berger, Georg Gottlob, Andreas Pieris, and Emanuel Sallinger. The space-efficient core of vadalog. ACM Trans. Database Syst., 47(1):1:1–1:46, 2022. doi:10.1145/3488720.
- [6] Meghyn Bienvenu, Balder ten Cate, Carsten Lutz, and Frank Wolter. Ontology-based data access: A study through disjunctive datalog, CSP, and MMSNP. ACM Trans. Database Syst., 39(4):33:1–33:44, 2014. doi:10.1145/2661643.
- [7] Andrea Calì, Georg Gottlob, and Thomas Lukasiewicz. A general Datalog-based framework for tractable query answering over ontologies. J. Web Sem., 14:57–83, 2012. doi:10.1016/J.WEBSEM.2012.03.001.
- [8] Andrea Calì, Georg Gottlob, and Andreas Pieris. Towards more expressive ontology languages: The query answering problem. Artif. Intell., 193:87–128, 2012. doi:10.1016/J.ARTINT.2012.08.002.
- [9] Georg Gottlob, André Hernich, Clemens Kupke, and Thomas Lukasiewicz. Stable model semantics for guarded existential rules and description logics: Decidability and complexity. J. ACM, 68(5):35:1–35:87, 2021. doi:10.1145/3447508.
- [10] Georg Gottlob, Giorgio Orsi, and Andreas Pieris. Query rewriting and optimization for ontological databases. ACM Trans. Database Syst., 39(3):25:1–25:46, 2014. doi:10.1145/2638546.
- [11] André Hernich, Clemens Kupke, Thomas Lukasiewicz, and Georg Gottlob. Well-founded semantics for extended datalog and ontological reasoning. In PODS, pages 225–236, 2013. doi:10.1145/2463664.2465229.
- [12] Mélanie König, Michel Leclère, Marie-Laure Mugnier, and Michaël Thomazo. Sound, complete and minimal ucq-rewriting for existential rules. Semantic Web, 6(5):451–475, 2015. doi:10.3233/SW-140153.
- [13] Thomas Lukasiewicz, Enrico Malizia, Maria Vanina Martinez, Cristian Molinaro, Andreas Pieris, and Gerardo I. Simari. Inconsistency-tolerant query answering for existential rules. Artif. Intell., 307:103685, 2022. doi:10.1016/J.ARTINT.2022.103685.
- [14] Antonella Poggi, Domenico Lembo, Diego Calvanese, Giuseppe De Giacomo, Maurizio Lenzerini, and Riccardo Rosati. Linking data to ontologies. J. Data Semantics, 10:133–173, 2008. doi:10.1007/978-3-540-77688-8_5.
Appendix A Resolvents and Polishing Strategies
As discussed in the main body of the paper, the two immediate polishing strategies for the conversion of into a safe formula in rewrite form are:
- Polishing Strategy I.
-
For each , simply remove the conjunction of atoms as a whole if mentions a variable that is neither in nor in .
- Polishing Strategy II.
-
For each , remove only the atoms occurring in that mention a variable that is neither in nor in .
It is clear that both strategies will ensure safety. It is not difficult, however, to illustrate that both strategies are problematic. Let us start with the first polishing strategy.
Example 11.
Consider the sentence in rewrite form (that is saturated) and the tgd
respectively. The only available mgcu of with is
Hence, by resolving using we get the sentence
which needs polishing since the free variable occurs in the negative part but not in the positive part. According to the first strategy, we remove the negative part as a whole and get
It is easy to see that the obtained sentence is unsound in the following sense: there is a database such that the result of the chase of w.r.t. does not satisfy the original sentence , but satisfies the obtained sentence ; in particular, for .
Loosely speaking, the first polishing strategy removes more than necessary from the negative part and this leads to an unsound result. Let us now discuss the second strategy.
Example 12.
Consider the sentence in rewrite form (that is saturated) and the tgd
respectively. The only available mgcu of with is
Hence, by resolving using we get the sentence
which needs polishing since the free variable occurs in the negative part but not in the positive part. According to the second strategy, we remove from the negative part, which is the only atom that mentions , and get the sentence
It is easy to see that the obtained sentence is incomplete in the following sense: there is a database such that the result of the chase of w.r.t. satisfies the original sentence , but does not satisfy the obtained sentence ; in particular, for .
Appendix B Validity
As discussed in the main body of the paper, the reason why we cannot use all the mgcus of with , but only valid ones, is because invalid mgcus lead to unsound resolution steps. More precisely, by applying an invalid mgcu, we may produce a formula that gives rise to a satisfiable ccq= from a formula that defines an unsatisfiable ccq=, which is problematic.
Example 13.
Consider the sentence in rewrite form (that is saturated) and the tgd
respectively. It is clear that, for every null instance that (i) contains an atom , (ii) , and (iii) , it holds that , i.e., the query is unsatisfiable w.r.t. instances with the properties (i) - (iii). Now, observe that the only available mgcu of with is and the -resolvent of is the sentence and thus, the query has a non-empty answer over every null instance that contains an atom . Hence, given the database , the answer to the query over the result of the chase of w.r.t. , which is an instance that enjoys the properties (i) - (iii), is empty, whereas the answer to over is non-empty. Summing up, the mgcu is not valid since the sentence , which is essentially the conjunction of the head of (after updating its variables according to the functions of ) with , gives rise to an unsatisfiable query.
Appendix C Proof of Lemma 10
The proof of Lemma 10 relies on four useful auxiliary technical lemmas. We proceed to state those lemmas and then we proceed with the final proof.
Four Auxiliary Lemmas
Recall that . Moreover, given a formula in rewrite form with , we write for the query . The first auxiliary lemma shows that the rewriting of the negative atoms, performed by the procedure , is sound.
Lemma 14.
Let be a derivation of w.r.t . The following are equivalent:
-
1.
.
-
2.
There exists such that .
The next lemma is crucial for establishing the completeness of , i.e., the direction of Lemma 10. It states that from a prefix of a chase derivation of w.r.t. , where its last instance is such that with being a formula in rewrite form that is saturated and , we can extract a sequence of resolution steps starting from , and mimicking backwards the chase applications that gave rise to , that leads to a formula in rewrite form that is saturated with such that . This is shown by induction on the length of the prefix .
Lemma 15.
Consider a formula in rewrite form that is saturated with . Let , for , be a prefix of a chase derivation of w.r.t. with , for , such that . There is a sequence of formulas in rewrite form that are saturated with , for each , such that:
-
1.
-
2.
or is a -resolvent of for some valid mgcu of with , for each , and
-
3.
, for each .
The next lemma is also needed for establishing the completeness of , i.e., the direction of Lemma 10. Intuitively, it states that if a formula in rewrite form is blocked by some formula of produced by the algorithm, then all the rewritten formulas obtained via resolution steps from will be blocked by some other formula of .
Lemma 16.
Consider a set of formulas in rewrite form, and a formula in rewrite form such that is -blocked. Let be a chunk unifier of with a tgd such that the -resolvent of is satisfiable. One of the following holds:
-
1.
is -blocked, or
-
2.
is -blocked, where is the -resolvent of some , where is a chunk unifier of with such that , where and .
The last lemma is crucial for the direction of Lemma 10, that is, the soundness of . A rewriting -sequence is a sequence of pairs , for , where , , and, for each , is a -resolvent of , where , for some valid mgcu of with such that is -active, and . The lemma in question essentially states that, for a rewriting -sequence , implies , where is an null instance obtained by some chase derivation of w.r.t. . This is shown by induction on the length of .
Lemma 17.
Consider a rewriting -sequence . There exists a prefix of a chase derivation of w.r.t. such that implies .
The Final Proof
We are now ready to establish Lemma 10.
By hypothesis, there exists a chase derivation of w.r.t. such that . By Lemma 14, there exists such that . Therefore, there exists a prefix , for , of such that . By Lemma 15, there is a sequence , for , with the properties stated in the statement of the lemma. Note that there is no guarantee that all the elements in are produced by the execution of under consideration. This is due on the one hand to the activeness condition of the triggers considered and on the other to the blocking condition that must not be satisfied to maintain a formula produced through a resolution phase. As regards the activeness condition of the triggers, it is easy to prove that the use of inactive triggers cannot be put in one-to-one correspondence with a prefix of a chase derivation, in fact the same trigger cannot be used more than once by definition. For what concerns the blocking condition, by induction on the length of , we show that is -blocked, where is the set that collects all the disjuncts of :
Base Step.
If is of length , then . Therefore, is -blocked, which in turn implies that is -blocked since , and the claim follows.
Inductive Step.
Suppose now that is of length , i.e., . By induction hypothesis, is -blocked. If , then we immediately get that is -blocked. Assume now that is the -resolvent of , where is a valid mgcu of with . By Lemma 16, we get that is -blocked or is -blocked, where is the -resolvent of some . Clearly, is -blocked, and thus, is -blocked.
Since and is -blocked, for some disjunct of .
By hypothesis, there exists such that . This implies that there is a rewriting -sequence , with . By Lemma 17, there exists a prefix of a chase derivation of w.r.t. such that, for , implies . Therefore, since , we get that , and thus, . Since , we can establish the following monotonicity property: for a chase derivation such that for each , it holds that . Thus, there is a chase derivation of w.r.t. such that . Since , and , Lemma 14 implies that , and the claim follows.
