<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Tractable Query Answering and Optimization for Extensions of Weakly-Sticky Datalog±</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Mostafa Milani</string-name>
          <email>mmilani@scs.carleton.ca</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Leopoldo Bertossi</string-name>
          <email>bertossi@scs.carleton.ca</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Carleton University, School of Computer Science</institution>
          ,
          <addr-line>Ottawa</addr-line>
          ,
          <country country="CA">Canada</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Summary. We consider a semantic class, weakly-chase-sticky (WChS), and a syntactic subclass, jointly-weakly-sticky (JWS), of Datalog± programs. Both extend that of weakly-sticky (WS) programs, which appear in our applications to data quality. For WChS programs we propose a practical, polynomial-time query answering algorithm (QAA). We establish that the two classes are closed under magic-sets rewritings. As a consequence, QAA can be applied to the optimized programs. QAA takes as inputs the program (including the query) and semantic information about the “finiteness” of predicate positions. For the syntactic subclasses JWS and WS of WChS, this additional information is computable. Datalog± . Datalog, a rule-based language for query and view-definition in relational databases [5], is not expressive enough to logically represent interesting and useful ontologies, at least of the kind needed to specify conceptual data models. Datalog± extends Datalog by allowing existentially quantified variables in rule heads (∃-variables), equality atoms in rule heads, and program constraints [2]. Hence the “+” in Datalog± , while the “−” reflects syntactic restrictions on programs, for better computational properties. A typical Datalog± program, P , is a finite set of rules, Σ ∪ E ∪ N , and an extensional database (finite set of facts), D. The rules in Σ are tuple-generatingdependencies (tgds) of the form ∃x¯P (x¯, x¯′) ← P1(x¯1), . . . , Pn(x¯n), where x¯′ ⊆ S x¯i, and x¯ can be empty. E is a set of equality-generating-dependencies (egds) of the form x = x′ ← P1(x¯1), . . . , Pn(x¯n), with {x, x′} ⊆ S x¯i. Finally, N contains negative constraints of the form ⊥ ← P1(x¯1), . . . , Pn(x¯n), where ⊥ is false. Example 1. The following Datalog± program shows a tgd, an egd, and a negative constraint, in this order: ∃x Assist (y, x) ← Doctor (y); x = x′ ← Assist (y, x), Assist (y, x′); ⊥ ← Specialist (y, x, z), Nurse(y, z).</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        Below, when we refer to a class of Datalog± programs, we consider only Σ, the
tgds. Due to different syntactic restrictions, Datalog± can be seen as a class
of sublanguages of Datalog∃ , which is the extension of Datalog with tgds with
∃-variables [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ].
      </p>
      <p>
        The rules of a Datalog± program can be seen as an ontology O on top of
D, which can be incomplete. O plays the role of: (a) a “query layer” for D,
providing ontology-based data access (OBDA) [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], and (b) the specification of a
completion of D, usually carried out through the chase mechanism that, starting
from D, iteratively enforces the rules in Σ, generating new tuples. This leads to
a possibly infinite instance extending D, denoted with chase (Σ, D).
      </p>
      <p>
        The answers to a conjunctive query Q(x¯) from D wrt. Σ is a sequence of
constants a¯, such that Σ ∪D |= Q(a¯) (or yes or no in case Q is boolean). The answers
can be obtained by querying as usual the universal instance chase(Σ, D). The
chase may be infinite, which leads, in some cases, to undecidability of query
answering [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]. However, in some cases where the chase is infinite, query answering
(QA) is still computable (decidable), and even tractable in the size of D.
Syntactic classes of Datalog± programs with tractable QA have been identified and
investigated, among them: sticky [
        <xref ref-type="bibr" rid="ref4 ref7">4, 7</xref>
        ], and weakly-sticky [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] Datalog± programs.
Our Need for QA Optimization. In our work, we concentrate on the
stickiness and weak-stickiness properties, because these programs appear in our
applications to quality data specification and extraction [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ], with the latter task
accomplished through QA, which becomes crucial.
      </p>
      <p>
        Sticky programs [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] satisfy a syntactic restriction on the multiple occurrences
of variables (joins) in the body of a tgd. Weakly-sticky (WS) programs form a
class that extends that of sticky programs [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. WS-Datalog± is more expressive
than sticky Datalog± , and results from applying the notion of weak-acyclicity
(WA) as found in data exchange [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], to relax acyclicity conditions on stickiness.
More precisely, in comparison with sticky programs, WS programs require a
milder condition on join variables, which is based on a program’s dependency
graph and the positions in it with finite rank [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ].1
      </p>
      <p>
        For QA, sticky programs enjoy first-order rewritability [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], i.e. a conjunctive
query Q posed to Σ ∪ D can be rewritten into a new first-order (FO) query
Q′, and correctly answered by posing Q′ to D, and answering as usual. For WS
programs, QA is PTIME -complete in data, but the polynomial-time algorithm
provided for the proof in [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] is not a practical one.
      </p>
      <p>
        Stickiness of the Chase. In addition to (syntactic) stickiness, there is a
“semantic” property of programs, which is relative to the chase (and the data,
D), and is called “chase-stickiness” (ChS). Stickiness implies semantic stickiness
(but not necessarily the other way around) [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. For chase-sticky programs, QA
is tractable [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>
        Intuitively, a program has the chase-stickiness property if, due to the
application of a tgd σ: When a value replaces a repeated variable in the body of a
rule, then that value also appears in all the head atoms obtained through the
iterative enforcement of applicable rules that starts with σ. So, that value is
propagated all the way down through all the possible subsequent steps.
a
a
1 A position refers to a predicate attribute, e.g. Nurse[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
ߪ
ߪ
ߪ
ߪ
ߪ
ߪ
Example 2. Consider D = {Assist(a, b), Assist(b, c)}, and the following set,
Σ1, of tgds: Nurse(y, z) ← Assist(x, y), Assist (y, z); ∃z Specialist (x, y, z) ←
Nurse(x, y); D octor(y) ← S pecialist(x, y, z). Σ1 is not ChS, as the chase
on the LHS of Figure1 shows: value b is not propagated all the way down to
Doctor (c). However, program Σ2, which is Σ1 without its third rule, is ChS, as
shown on the RHS of Figure1.
      </p>
      <p>Weak-Stickiness of the Chase. Weak-stickiness also has a semantic version,
called “weak-chase-stickiness” (WChS); which is implied by the former. So as
for chase-stickiness, weak-chase-sticky programs have a tractable QA problem,
even with a possibly infinite chase. This class is one of the two we introduce and
investigate. They appear in double-edged boxes in Figure 2, with dashed edges
indicating a semantic class.</p>
      <p>By definition, weak-chase-stickiness is obtained by relaxing the condition
for ChS: it applies only to values for repeated variables in the body of σ that
appear in so-called infinite positions, which are semantically defined. A position
is infinite if there is an instance D for which an unlimited number of different
values appear in Chase(Σ, D).</p>
      <p>
        Given a program, deciding if a position is infinite is unsolvable, so as
deciding in general if the chase terminates. Consequently, it is also undecidable if
a program is WChS. However, there are syntactic conditions on programs [
        <xref ref-type="bibr" rid="ref12 ref6">6,
12</xref>
        ] that determine some (but not necessarily all) the finite positions. For
example, the notion of position rank, based on the program’s dependency graph, are
used in [
        <xref ref-type="bibr" rid="ref4 ref6">6, 4</xref>
        ] to identify a (sound) set of finite positions, those with finite rank.
Furthermore, finite-rank positions are used in [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] to define weakly-sticky (WS)
programs as a syntactic subclass of WChS.
      </p>
      <p>Finite Positions and Program Classes. In principle, any set-valued function
S that, given a program, returns a subset of the program’s finite positions can
be used to define a subclass WChS(S) of WChS. This is done by applying the
definition of WChS above with “infinite positions” replaced by “non-S-finite
positions”. Every class WChS(S) has a tractable QA problem.</p>
      <p>S could be computable on the basis of the program syntax or not. In the
former case, it would be a “syntactic class”. Class WChS (S) grows
monotonically with S in the sense that if S1 ⊆ S2 (i.e. S1 always returns a subset of the
positions returned by S2), then WChS (S1) ⊆ WChS (S2). In general, the more
finite positions are (correctly) identified (and the consequently, the less finite
positions are treated as infinite), the more general the subclass of WChS that is
identified or characterized.</p>
      <p>
        For example, the function S⊥ that always returns an empty set of finite
positions, WChS (S⊥) is the class of sticky programs, because stickiness must hold
no matter what the (in)finite positions are. At the other extreme, for function
S⊤ that returns all the (semantically) finite positions, WChS (S⊤) becomes the
class WChS. (As mentioned above, S⊤ is in general uncomputable.) Now, if
Srank returns the set of finite-rank positions (for a program P, usually denoted
by ΠF (P) [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]), WChS (Srank ) is the class of WS programs.
      </p>
      <p>
        Joint-Weakly-Stickiness. The joint-weakly-sticky (JWS) programs we
introduce form a syntactic class strictly between WS and WChS. Its definition appeals
to the notions of joint-acyclicity and existential dependency graphs introduced
in [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ]. Figure 2 shows this syntactic class, and the inclusion relationships
between classes of Datalog± programs.2
      </p>
      <p>
        If Sext denotes the function that specifies finite positions on the basis of the
existential dependency graphs (EDG), implicitly defined in [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], the JWS class is,
by definition, the class WChS (Sext ). EDGs provide a finer mechanism for
capturing (in)finite positions in comparison with positions ranks (defined through
dependency graphs): Srank ⊆ Sext . Consequently, the class of JWS programs,
i.e. WChS (Sext ), is a strict superclass of WS programs, i.e. WChS (Srank ).3
QAA for WChS. Our query answering algorithm for WChS programs is
parameterized by a (sound) finite-position function S as above. It is denoted with
ALS, and takes as input Σ, D, query Q, and S(Σ), which is a subset of the
program’s finite positions (the other are treated as infinite by default).
      </p>
      <p>The customized algorithm ALS is guaranteed to be sound and complete only
when applied to programs in WChS (S): ALS(Σ, D, Q) returns all and only the
query answers. (Actually, ALS is still sound for any program in WChS.) ALS
runs in polynomial-time in data; and can be applied to both the WS and the
JWS syntactic classes. For them the finite-position functions are computable.</p>
      <p>
        ALS is based on the concepts of parsimonious chase (pChase) and freezing
nulls, as used for QA with shy Datalog, a fragment of Datalog∃ [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]. At a pChase
step, a new atom is added only if a homomorphic atom is not already in the
chase. Freezing a null is promoting it to a constant (and keeping it as such in
subsequent chase steps). So, it cannot take (other) values under homomorphisms,
which may create new pChase steps. Resumption of the pChase means freezing
all nulls, and continuing pChase until no more pChase steps are applicable.
      </p>
      <p>
        Query answering with shy programs has a first phase where the pChase runs
until termination (which it does). In a second phase, the pChase iteratively
resumes for a number of times that depends on the number of distinct ∃-variables in
the query. This second phase is required to properly deal with joins in the query.
Our QAA for WChS programs (AL) is similar, it has the same two phases, but a
pChase step is modified: after every application of a pChase step that generates
nulls, the latter that appear in S-finite positions are immediately frozen.
Magic-Sets Rewriting. It turns out that JWS, as opposed to WS, is closed
under the quite general magic-set rewriting method [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] introduced in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. As a
2 Rectangles with dotted-edges show semantic classes, and double-edged rectangles
show the classes introduced in this work. Notice that programs in semantic classes
include the instance D, but syntactic classes are data-independent (for any instance
as long as the syntactic conditions apply).
3 The JWS class is different from (and incomparable with) the class of
weakly-stickyjoin programs (WSJ) introduced in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], which extends the one of WS programs with
consideration that are different from those used for JWS programs. WSJ generalizes
WS on the basis of the weakly-sticky-join property of the chase [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
        ] and is related
to repeated variables in single atoms.
      </p>
      <p>non-terminating</p>
      <p>chase
weakly-stickyjoin (WSJ)
joint-weaklysticky (JWS)
weakly-sticky
(WS)
terminating</p>
      <p>chase
joint-acyclic</p>
      <p>(JA)
weakly-acyclic
(WA)
consequence, AL can be applied to both the original JWS program and its magic
rewriting. (Actually, this also holds for the superclass WChS.)</p>
      <p>
        It can be proved that (our modification of) the magic-sets rewriting method
in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] does not change the character of the original finite or infinite positions.
The specification of (in)finiteness character of positions in magic predicates is not
required by AL, because no new nulls appear in them during the AL execution.
As consequence, the MS method rewriting can be perfectly integrated with our
QAA, introducing additional efficiency.
      </p>
      <p>Acknowledgments: We are very grateful to Mario Alviano and the DLV team for
providing us with information and support in relation to existential Datalog. We also
appreciate useful conversations with Andrea Cali and Andreas Pieris on Datalog±, and
important comments from Andrea Cali on an earlier version of this paper.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>M.</given-names>
            <surname>Alviano</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Leone</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Manna</surname>
          </string-name>
          , G. Terracina and
          <string-name>
            <given-names>P.</given-names>
            <surname>Veltri</surname>
          </string-name>
          .
          <article-title>Magic-Sets for Datalog with Existential Quantifiers</article-title>
          .
          <source>Proc. Datalog 2.0</source>
          ,
          <issue>2012</issue>
          , pp.
          <fpage>31</fpage>
          -
          <lpage>43</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>A.</given-names>
            <surname>Cali</surname>
          </string-name>
          , G. Gottlob, and
          <string-name>
            <given-names>T.</given-names>
            <surname>Lukasiewicz</surname>
          </string-name>
          . Datalog±
          <article-title>: A Unified Approach to Ontologies and Integrity Constraints</article-title>
          .
          <source>Proc. ICDT</source>
          ,
          <year>2009</year>
          , pp.
          <fpage>14</fpage>
          -
          <lpage>30</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>A.</given-names>
            <surname>Cali</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G.</given-names>
            <surname>Gottlob</surname>
          </string-name>
          and
          <string-name>
            <given-names>A.</given-names>
            <surname>Pieris</surname>
          </string-name>
          .
          <article-title>Query Answering under Non-Guarded Rules in Datalog+/-</article-title>
          .
          <source>Proc. RR</source>
          ,
          <year>2010</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>17</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>A.</given-names>
            <surname>Cali</surname>
          </string-name>
          ,
          <string-name>
            <surname>G.</surname>
          </string-name>
          <article-title>Gottlob, and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Pieris</surname>
          </string-name>
          .
          <article-title>Towards more Expressive Ontology Languages: The Query Answering Problem</article-title>
          .
          <source>Artificial Intelligence</source>
          ,
          <year>2012</year>
          ,
          <volume>193</volume>
          :
          <fpage>87</fpage>
          -
          <lpage>128</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>S.</given-names>
            <surname>Ceri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G.</given-names>
            <surname>Gottlob</surname>
          </string-name>
          and
          <string-name>
            <given-names>L.</given-names>
            <surname>Tanca</surname>
          </string-name>
          .
          <source>Logic Programming and Databases</source>
          . Springer,
          <year>1990</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>R.</given-names>
            <surname>Fagin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P. G.</given-names>
            <surname>Kolaitis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R. J.</given-names>
            <surname>Miller</surname>
          </string-name>
          , and
          <string-name>
            <given-names>L.</given-names>
            <surname>Popa</surname>
          </string-name>
          . Data Exchange: Semantics and
          <string-name>
            <given-names>Query</given-names>
            <surname>Answering</surname>
          </string-name>
          .
          <source>Theoretical Computer Science</source>
          ,
          <year>2005</year>
          ,
          <volume>336</volume>
          :
          <fpage>89</fpage>
          -
          <lpage>124</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>G.</given-names>
            <surname>Gottlob</surname>
          </string-name>
          ,
          <string-name>
            <surname>G.</surname>
          </string-name>
          <article-title>Orsi, and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Pieris</surname>
          </string-name>
          .
          <article-title>Query Rewriting and Optimization for Ontological Databases</article-title>
          .
          <source>ACM TODS</source>
          ,
          <year>2014</year>
          ,
          <volume>39</volume>
          (
          <issue>3</issue>
          ):
          <fpage>25</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>D. S.</given-names>
            <surname>Johnson</surname>
          </string-name>
          , and
          <string-name>
            <given-names>A.</given-names>
            <surname>Klug</surname>
          </string-name>
          .
          <article-title>Testing Containment of Conjunctive Queries under Functional and Inclusion Dependencies</article-title>
          .
          <source>Proc. PODS</source>
          ,
          <year>1984</year>
          , pp.
          <fpage>164</fpage>
          -
          <lpage>169</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>M.</given-names>
            <surname>Lenzerini</surname>
          </string-name>
          .
          <article-title>Ontology-Based Data Management</article-title>
          .
          <source>Proc. AMW</source>
          <year>2012</year>
          ,
          <source>CEUR Proceedings</source>
          , Vol.
          <volume>866</volume>
          , pp.
          <fpage>12</fpage>
          -
          <lpage>15</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <given-names>N.</given-names>
            <surname>Leone</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Manna</surname>
          </string-name>
          , G. Terracina, and
          <string-name>
            <given-names>P.</given-names>
            <surname>Veltri. Efficiently Computable</surname>
          </string-name>
          <article-title>Datalog∃ Programs</article-title>
          .
          <source>Proc. KR</source>
          ,
          <year>2012</year>
          , pp.
          <fpage>13</fpage>
          -
          <lpage>23</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>M. Milani</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <string-name>
            <surname>Bertossi</surname>
            and
            <given-names>S.</given-names>
          </string-name>
          <string-name>
            <surname>Ariyan</surname>
          </string-name>
          .
          <article-title>Extending Contexts with Ontologies for Multi-dimensional Data Quality Assessment</article-title>
          .
          <source>Proc. DESWeb</source>
          ,
          <year>2014</year>
          , pp.
          <fpage>242</fpage>
          -
          <lpage>247</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <given-names>S.</given-names>
            <surname>Rudolph</surname>
          </string-name>
          , and
          <string-name>
            <surname>M.</surname>
          </string-name>
          <article-title>Kr¨otzsch. Extending Decidable Existential Rules by Joining Acyclicity and Guardedness</article-title>
          .
          <source>Proc. IJCAI</source>
          ,
          <year>2011</year>
          , pp.
          <fpage>963</fpage>
          -
          <lpage>968</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>