<!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>Second-Order Specifications and Quantifier Elimination for Consistent Query Answering in Databases</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Universidad Adolfo Iba ́n ̃ez Faculty of Engineering and Sciences and Millennium Institute for Foundational Research on Data (IMFD) Santiago</institution>
          ,
          <country country="CL">Chile</country>
        </aff>
      </contrib-group>
      <fpage>28</fpage>
      <lpage>36</lpage>
      <abstract>
        <p>Consistent answers to a query from a possibly inconsistent database are answers that are simultaneously retrieved from every possible repair of the database. Repairs are consistent instances that minimally differ from the original inconsistent instance. It has been shown before that database repairs can be specified as the stable models of a disjunctive logic program. We show how to use the repair programs to transform the problem of consistent query answering into a problem of reasoning w.r.t. a theory written in second-order predicate logic. We show how a first-order theory can be obtained instead by applying second-order quantifier elimination techniques.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Integrity constraints (ICs) on databases are expected to be satisfied by the instances of
the given schema S . If an instance does not satisfy the ICs, it is said to be inconsistent,
and becomes only partially semantically correct. Consistent query answering (CQA)
attempts to characterize and compute answers to a query that are consistent with
respect to (w.r.t.) a given set of ICs [
        <xref ref-type="bibr" rid="ref11 ref15 ref5 ref8">5, 8, 15, 11</xref>
        ]. Informally, a tuple of constants t¯ is a
consistent answer from an instance D to a query Q(x¯) w.r.t. a set of ICs IC if t¯ can be
obtained as a usual answer to Q from every repair of D. Here, a repair is a consistent
instance for the schema S that differs from D by a minimal set of database atoms under
set inclusion [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ].
      </p>
      <p>
        It has been shown [
        <xref ref-type="bibr" rid="ref13 ref6">6, 13</xref>
        ] that repairs can be specified as the stable models of a
disjunctive logic program [
        <xref ref-type="bibr" rid="ref22">22</xref>
        ] Π , by a so-called repair program. In this way, CQA
becomes a problem of reasoning with program Π . Logic programs with stable model
semantics are also called answer-set programs [
        <xref ref-type="bibr" rid="ref22">22</xref>
        ], and their stable models are also
called answer sets. Answer-set programming has become a powerful paradigm and tool
for the specification and solution of hard combinatorial problems [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ].
      </p>
      <p>Copyright © 2021 for this paper by its authors. Use permitted under Creative Commons
License Attribution 4.0 International (CC BY 4.0).</p>
      <p>
        Ideally, consistent answers to a query Q from a database instance D should be
obtained by posing a new query Q0 to D, as an ordinary query that is, hopefully, easy
to evaluate against D. This is the case, for example, when Q0 is a query expressed in
the first-order (FO) languageL(S). Some classes of queries and ICs with this property
have been already identified [
        <xref ref-type="bibr" rid="ref14 ref21 ref5">5, 14, 21</xref>
        ]; and many more by Wijsen in a series of papers
on conjunctive queries and key constraints [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. C.f. [
        <xref ref-type="bibr" rid="ref36">36</xref>
        ] and [
        <xref ref-type="bibr" rid="ref37">37</xref>
        ] for excellent surveys,
and [
        <xref ref-type="bibr" rid="ref23">23</xref>
        ] for more recent results and references.
      </p>
      <p>
        The main result for CQA for conjunctive queries (CQs) under key constraints (KCs),
tells us that one can syntactically classify and decide CQs in terms of their data
complexity for CQA.1 A trichotomy appears: a CQ can be FO-rewritable, or in PTIME
(L-complete), or coNP-complete. There are queries for these three classes. For the first
class, the rewriting can be computed, in which case, it is possible to compute the
consistent answers in polynomial time. It is worth emphasizing that there are CQs for which
CQA can be done in polynomial time, but provably not via FO-rewriting [
        <xref ref-type="bibr" rid="ref34 ref35">35, 34</xref>
        ]. This
opens the question about the right logical language for a rewriting, if any.
      </p>
      <p>
        At the other extreme, repair programs provide a general mechanism for
computing consistent answers. Actually, the data complexity of CQA can be as high as the
data complexity of cautious query evaluation from disjunctive logic programs under
the stable model semantics, namely Π2P -complete [
        <xref ref-type="bibr" rid="ref14 ref16">16, 14</xref>
        ]. Apart from providing the
right expressive power and complexity for dealing with repairs and CQA, the
semantics of answer-set programming is a non-monotonic, non-classical logical semantics,
which is particularly suitable for applications in databases, through the implicit use of
the closed-world assumption [
        <xref ref-type="bibr" rid="ref32">32</xref>
        ], and the minimality of models under set inclusion.
This last feature is useful in relation to the minimality of database repairs.
      </p>
      <p>
        In those cases where a FO rewriting for CQA is possible, one can transform the
problem of CQA into one of reasoning in classical predicate logic, because the original
database can be “logically reconstructed” as a FO theory [
        <xref ref-type="bibr" rid="ref32">32</xref>
        ]. In this work we
investigate how repair programs can be used to generate a theory written in classical logic
from which CQA can be captured as logical entailment. This theory can be written in
second-order or first-order predicate logic. We start by trying to achieve the former, by
providing specifications of database repairs in second-order (SO) predicate logic. They
are obtained by applying recent results on the specification in SO logic of the stable
models of a logic program [
        <xref ref-type="bibr" rid="ref19 ref20">19, 20</xref>
        ] -in our case, a repair program- and older results
on their characterization as the models of a circumscriptive theory [
        <xref ref-type="bibr" rid="ref29">29</xref>
        ] for the case of
disjunctive stratified programs [
        <xref ref-type="bibr" rid="ref30 ref31">30, 31</xref>
        ]. This circumscription can be specified in SO
predicate logic [
        <xref ref-type="bibr" rid="ref25 ref33">25, 33</xref>
        ].
      </p>
      <p>
        In order to achieve a FO specification, for some cases related to queries and KCs,
we apply techniques for SO quantifier elimination that have been introduced in [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ].
In this way it is possible to obtain a FO specification of the database repairs. This
transforms CQA into a problem of logical reasoning in FO logic. We illustrate by means
of an example how to obtain a FO rewriting for CQA under a KC. We illustrate the SO
quantifier elimination technique. Generalizing the methodology to more general cases
is left for future investigation. C.f. Section 5), where we also discuss the possibility
1 As usual in databases, all the complexity results in this paper are about data complexity, i.e. in
terms of the size of the database instance.
of obtaining rewritings in fixed-point logic, when it is provably the case that no FO
rewriting exists. This paper is an excerpt from [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. In [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] one can find an extended
and updated version of both the latter and this paper, containing all the details and
much more.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Database Repairs and Repair Programs</title>
      <p>
        Consider a database instance D and a set of integrity constraints (ICs), that is a set
Σ of sentences in the first-order language of predicate logic associated to the database
schema. The database may not satisfy Σ in which case we say that D is inconsistent.
The database can be repaired by inserting or deleting full tuples into/from D, in such
a way that the resulting instance becomes consistent. A (minimal) repair of D is an
instance D0 that satisfiesΣ and minimally differs from D under set inclusion, i.e. DΔD0,
the symmetric set difference, is minimal under set inclusion [
        <xref ref-type="bibr" rid="ref11 ref5">5, 11</xref>
        ]. For monotone ICs
(they are never violated by tuple deletions), like the ones we will consider below, the
repairs are always maximal-subsets (subinstances) of D. The repairs of an inconsistent
database can be specified by means of answer-set programs (c.f. [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ] for details and
references). Those are the repair programs.
      </p>
      <p>
        Repair programs use annotation constants in an extra argument for each of the
database predicates. More precisely, for each n-ary P ∈ S, we make a copy P , which
is (n + 1)-ary [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ]. Here, we need only the following annotations, with its intended
semantics: (a) f in atoms P (a¯, f ), meaning “made false (deleted)”, (b) t?? in atoms
P (a¯, t??), meaning “true in repair”.
      </p>
      <p>Example 1. The relational schema S contains predicate P (X, Y ), and the functional
dependency (FD) X → Y , actually a KC, stating that the first attribute functionally
determines the second. It can be expressed as the first-order (FO) sentence</p>
      <p>FD : ∀x∀y∀z(P (x, y) ∧ P (x, z) → y = z).</p>
      <p>The database instance D = {P (a, b), P (a, c), P (d, e)} is inconsistent since the
first two tuples jointly violate the FD. We have two repairs: D1 = {P (a, b), P (d, e)}
and D2 = {P (a, c), P (d, e)}. The query Q1(y) : ∃xP (x, y) has the consistent answer
(e), whereas the query Q2(x) : ∃yP (x, y) has (a), (d) as consistent answers. They are
standard answers from both repairs. These repairs can be specified as the stable models
of the following repair program Π(D, FD ):
1. Original database facts: P (a, b), P (a, c), P (d, e).
2. The repair rule: P (x, y, f ) ∨ P (x, z, f ) ← P (x, y), P (x, z), y 6= z.</p>
      <p>It specifies that whenever the FD is violated, as captured by the rule body (the RHS),
then one (and only one if possible) of the two tuples involved in the violation has to be
made false (deleted), as captured by the disjunctive rule head (LHS).
3. Annotations constant t?? is used to read off the atoms in a repair, saying that
whichever atom was in the original instance and not deleted stays in the repair:</p>
      <p>P (x¯, t??) ← P (x¯), not P (x¯, f ).</p>
      <p>
        For simplicity, and from now on, we use new predicates Pf ( , ) for P ( , , f ),
P??( , ) for P ( , , t??). The repairs are in one-to-one correspondence with the
restriction of the stable models to the predicates of the form P?? [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ]. In this example, they
are: D1 = {P??(a, b), P??(d, e)} and D2 = {P??(a, c), P??(d, e)}.
      </p>
      <p>In order to obtain the consistent answers to a FO query Q, a query program ΠQ,
containing a query-answer predicate AnsQ, is combined with the repair program Π(D,
FD ). Next, as is common with ASPs, we can use the cautious entailment semantics
from ASP, denoted |=cs , which means that the right-hand side is true in all the stable
models of the program on the left-hand side.</p>
      <p>
        The extension of the answer predicate AnsQ in the intersection of all stable models
of Π := Π(D, FD ) ∪ ΠQ contains exactly the consistent answers. That is, a¯ is a
consistent answer to Q, denoted, D |=c Q(a¯), iff Π(D, FD ) ∪ ΠQ |=cs AnsQ(a¯). In
general, ΠQ will be a (stratified) non-recursive and normal Datalognot query ΠQ with
answer predicate AnsQ(x¯) appearing only in rule heads [
        <xref ref-type="bibr" rid="ref1 ref27">1, 27</xref>
        ].
      </p>
      <p>Example 2. (ex. 1 cont.) A possible query is Q(x, y) : P (x, y), which can be
represented by the simple query program ΠQ: Ans(x, y) ← P??(x, y). This program is
combined with 1.-3. above, and the consistent answers to Q are those tuples a¯, such that
ΠQ ∪ Π(D, FD ) |=cs Ans(a¯), obtaining the only consistent answer is (d, e).
3</p>
    </sec>
    <sec id="sec-3">
      <title>Second-Order Specification of Repairs</title>
      <p>
        In [
        <xref ref-type="bibr" rid="ref19 ref20">19, 20</xref>
        ], the stable model semantics of logic programs introduced in [
        <xref ref-type="bibr" rid="ref22">22</xref>
        ] is
reobtained via an explicit specification in classical SO predicate logic that is based on
circumscription. First, the program Π is transformed into (or seen as) a FO sentence
ψ(Π). Next, the latter is transformed into a SO sentence Φ(Π). Here, ψ(Π) is obtained
from Π as follows: (a) Replace every comma by ∧, and every not by ¬. (b) Turn every
rule Head ← Body into the formula Body → Head . (c) Form the conjunction of the
universal closures of those formulas.
      </p>
      <p>Now, given a FO sentence ψ (e.g. the ψ(Π) above), a SO sentence Φ is defined
as ψ ∧ ¬∃X¯ ((X¯ &lt; P¯) ∧ ψ◦(X¯ )), where P¯ is the list of all predicates P1, ..., Pn in
ψ that are going to be circumscribed,2 and X¯ is a list of distinct predicate variables
XP1 , ..., XPn , with Pi and XPi of the same arity. Here, (X¯ &lt; P¯) means (X¯ ≤ P¯) ∧
(X¯ 6= P¯), i.e. Vin ∀x¯(XPi (x¯) → Pi(x¯)) ∧ Win(XPi 6= Pi). XPi 6= Pi stands for
∃x¯i(Pi(x¯i) ∧ ¬XPi (x¯i)).</p>
      <p>ψ◦(X¯ ) is defined recursively as follows: (a)Pi(t1, ..., tm)◦ := XPi (t1, ..., tm). (b)
(t1 = t2)◦ := (t1 = t2). (c) ⊥◦:=⊥. (d) (F G)◦ := (F ◦ G◦) for ∈ {∧, ∨}. (e)
(F → G)◦ := (F ◦ → G◦) ∧ (F → G). (f) (QxF )◦ := QxF ◦ for Q ∈ {∀, ∃}. Notice
that we assume there is no explicit logical negation in formulas. Instead, a formula of
the form ¬χ is assumed to be represented as (χ → ⊥), with ⊥ standing for an always
false propositional formula.</p>
      <p>
        The Herbrand models of the SO sentence Φ(Π) associated to ψ(Π) correspond to
the stable models of the original program Π [
        <xref ref-type="bibr" rid="ref19">19</xref>
        ]. We can see that Φ(Π) is similar to
a parallel circumscription of the predicates in program Π w.r.t. the FO sentence ψ(Π)
2 In circumscription, some predicate may be minimized, others may stay flexible (or variable)
to accommodate to the minimization of others, and some may stay fixed [
        <xref ref-type="bibr" rid="ref25">25</xref>
        ].
associated to Π [
        <xref ref-type="bibr" rid="ref26 ref29">29, 26</xref>
        ]. In principle, the transformation rule (e) above could make
formula Φ(Π) differ from a circumscription.
      </p>
      <p>
        Now, let D be a relational database, Πr the repair program without the database
facts. From now on Π = D ∪ Πr ∪ ΠQ. Πr depends only on the integrity constraints,
and includes definitions for the annotation predicates. The only predicates shared by
Πr and ΠQ are of the form P??, which appear only in the rule bodies of ΠQ. These
predicates produce a splitting of the combined program [
        <xref ref-type="bibr" rid="ref28">28</xref>
        ], which allows us to analyze
separately Πr and ΠQ. The latter can be translated into classical logic by predicate
completion, or a prioritized circumscription [
        <xref ref-type="bibr" rid="ref30">30</xref>
        ]. If the query is FO, we can use query
itself.
      </p>
      <p>
        Example 3. (ex. 2 cont.) Leaving aside many details that can be found in [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ], we obtain
the following SO formula Φ(Π) that captures the stable models of the original program:
∀xy(P (x, y) ≡ (x = a ∧ y = b) ∨ (x = a ∧ y = c) ∨ (x = d ∧ y = e)) ∧ (1)
∀xy(P??(x, y) ≡ Ans(x, y)) ∧
∀xy((P (x, y) ∧ ¬Pf (x, y)) ≡ P??(x, y)) ∧
∀xyz(P (x, y) ∧ P (x, z) ∧ y 6= z → (Pf (x, y) ∨ Pf (x, z))) ∧
¬∃Uf ((Uf &lt; Pf ) ∧ ∀xyz(P (x, y) ∧ P (x, z) ∧ y 6= z → (Uf (x, y) ∨ Uf (x, z))). (5)
Here, Uf &lt; Pf stands for the formula ∀xy(Uf (x, y) → Pf (x, y)) ∧ ∃xy(Pf (x, y) ∧
¬Uf (x, y)). In this sentence, the minimizations of the predicates P, P?? and Ans are
expressed as their predicate completion. Predicate Pf is minimized via (5).
      </p>
      <p>
        We obtain the SO sentence for program Π as a parallel circumscription of the
predicates in the repair program seen as a FO sentence. The circumscription actually becomes
a prioritized circumscription [
        <xref ref-type="bibr" rid="ref25">25</xref>
        ] given the stratified nature of the repair program: first
the database predicate is minimized, next Pf , next P??, and finallyAns.
      </p>
      <p>
        Generalizations of the result in the previous example can be found in [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]. In the
following we concentrate on the problem of possibly turning this SO reasoning problem
into one at the FO level.
(2)
(3)
(4)
(6)
(7)
4
      </p>
    </sec>
    <sec id="sec-4">
      <title>From Second-Order to First-Order CQA</title>
      <p>
        In this section we discuss the possibility of obtaining a FO rewriting of the original
query as posed to the repair program. We do this through the analysis of the SO sentence
obtained in Example 3, concentrating on the SO sentence (5). In the rest of this section
many details are missing. They can be all found in [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ], the extended version of this
work.
      </p>
      <p>Sentence (5) can be expressed as</p>
      <p>
        ¬∃Uf ((Uf &lt; Pf ) ∧ ∀xyz(κ(x, y, z) → (Uf (x, y) ∨ Uf (x, z))),
where κ(x, y, z) is the formula P (x, y) ∧ P (x, z) ∧ y 6= z. For simplicity, we use U
instead of Uf . We will apply to (6) the SO quantifier elimination techniques in [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ].
The negation of (6) turns out to be -after several steps [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]- logically equivalent to:
∃st∃U ( ∀xyz(¬κ(x, y, z) ∨ U (x, y) ∨ U (x, z)) ∧
      </p>
      <p>∀uv(¬U (u, v) ∨ Pf (u, v)) ∧ (Pf (s, t) ∧ ¬U (s, t))).
The first conjunct in (7), with w = ∨(y, z) standing for (w = y ∨ w = z), can be
equivalently written as
∃f ∀r(∀x1y1z1(¬κ(x1, y1, z1) ∨ f (x1, y1, z1) = ∨(y1, z1)) ∧</p>
      <p>∀xyz(¬κ(x, y, z)∨r 6= f (x, y, z)∨U (x, r))),
where ∃f is a quantification over functions. Formula (7) becomes:
∃st∃f ∃U ∀x∀r((∀x1y1z1(¬κ(x1, y1, z1) ∨ f (x1, y1, z1) = ∨(y1, z1)) ∧
∀yz(¬κ(x, y, z) ∨ r 6= f (x, y, z) ∨ U (x, r))) ∧</p>
      <p>∀uv(¬U (u, v) ∨ Pf (u, v)) ∧ (Pf (s, t) ∧ ¬U (s, t))).</p>
      <p>
        We are ready to apply Ackermann’s Lemma [
        <xref ref-type="bibr" rid="ref2 ref3">2, 3</xref>
        ], with the last formula written as:
U
∃st∃f ∃U ∀x∀r((A(x, r) ∨ U (x, r)) ∧ B(
¬U
where B( ¬UU ) is formula B with predicate U replaced by ¬U ; and formulas A, B are:
A(x, r) : ∀yz(∀yz(¬κ(x, y, z)∨r 6= f (x, y, z)); and B(U ) : ∀x1y1z1(¬κ(x1, y1, z1)∨
f (x1, y1, z1) = ∨(y1, z1)) ∧ ∀uv(U (u, v) ∨ Pf (u, v)) ∧ (Pf (s, t) ∧ U (s, t))).
      </p>
      <p>Formula B is positive in U , then the whole subformula in (8) starting with ∃U can</p>
      <p>U
be equivalently replaced by B( A(x,r) ) [17, lemma 1], getting rid of the SO variable U ,
and obtaining:
∃st∃f ∀xyz((¬κ(x, y, z) ∨ f (x, y, z) = ∨(y, z)) ∧ (¬κ(x, y, z) ∨ Pf (u, f (x, y, z))) ∧
(Pf (s, t) ∧ (x 6= s ∨ ¬κ(x, y, z) ∨ t 6= f (x, y, z)))).</p>
      <p>Unskolemizing, getting rid of function variable f , we obtain
∃st∀xyz∃w((¬κ(x, y, z) ∨ w = ∨(y, z)) ∧ (¬κ(x, y, z) ∨ Pf (u, w))∧
(Pf (s, t) ∧ (x 6= s ∨ ¬κ(x, y, z) ∨ t 6= w))),
which is equivalent to the negation of (6). Negating again, we obtain a formula
equivalent to (6):
∀st(Pf (s, t) → ∃xyz(κ(x, y, z) ∧ ∀w[(w 6= y ∧ w 6= z)∨</p>
      <p>¬Pf (x, w) ∨ (x = s ∧ t = w)]).</p>
      <p>The formula in the square bracket inside can be equivalently replaced by
((w = y ∨ w = z) ∧ Pf (x, w)) → (s = x ∧ t = w).</p>
      <p>So, we obtain ∀st(Pf (s, t) → ∃xyz(κ(x, y, z) ∧ (Pf (x, y) → s = x ∧ t = y) ∧
(Pf (x, z) → s = x ∧ t = z))).</p>
      <p>Due to the definition ofκ(x, y, z), it must hold y 6= z. In consequence, we obtain:
∀st(Pf (s, t) → ∃z(κ(s, t, z) ∧ ¬Pf (s, z))).</p>
      <p>Summing up, the SO sentence for the repair program Π(D, IC ) is logically
equivalent to a FO sentence, ψ, that is the conjunction of (1), (3), (4), and
),
(8)
∀st(Pf (s, t) → ∃z(κ(s, t, z) ∧ ¬Pf (s, z))),
(9)
which says, in particular, that whenever there is a conflict between two tuples, one
of them must be deleted, and for every deleted tuple due to a violation, there must
be a tuple with the same key value that has not been deleted. Thus, not all mutually
conflicting tuples can be deleted.</p>
      <p>
        Coming back to CQA, for consistent answers t¯, we now have classical FO
entailment:
ψ ∧ ∀x¯(AnsQ(x¯)) ≡ χ(x¯)) |= AnsQ(t¯),
(10)
where χ is the FO definition of AnsQ in terms of the P?? predicate. This is not FO
query rewriting in the sense of obtaining a FO query to be posed to the original database.
However, and for example, it is not difficult to show [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] that for the queryQ : P (x, y),
and any consistent answer ht1, t2i, this is equivalent to having:
      </p>
      <p>
        D |= P (t1, t2) ∧ ¬∃z(P (t1, z) ∧ z 6= t2).
(11)
The query rewriting on the RHS of in (11) is one of those obtained in [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] using a
completely different and more general resolution-based rewriting methodology.
5
      </p>
    </sec>
    <sec id="sec-5">
      <title>Towards Fixed-Point Logic</title>
      <p>
        As described in Section 1, there are syntactic classes of CQs for which consistent query
answering can be done in polynomial time in data complexity. For one class, this can be
done via FO query rewriting. For a different class, its queries provably do not admit a
first-order rewriting. Even more, one can decide if a CQ falls in this case or not [
        <xref ref-type="bibr" rid="ref36 ref37">36, 37</xref>
        ].
      </p>
      <p>
        For example, the Boolean conjunctive query Q : ∃x∃y(R(x, y) ∧ S(y, x)), with
the first attributes of R and S as keys for them, is a query in the second class in that
it can be consistently answered in polynomial time, but no FO rewriting for it exists.
Results of this kind are established in [
        <xref ref-type="bibr" rid="ref34 ref35">35, 34</xref>
        ] by means of the notions of Hanf-locality
and Ehrenfeucht-Fra¨ıss e´ games for FO-logic [
        <xref ref-type="bibr" rid="ref24">24</xref>
        ].
      </p>
      <p>
        This opens the ground for investigating two problems:
1. Apply the second-order quantifier elimination technique in [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ], that we applied in
this work, with the purpose of recovering the FO rewritings for the whole class of
queries that admit FO consistent rewritings (as determined by Wijsen [
        <xref ref-type="bibr" rid="ref35">35</xref>
        ]).
2. Identify and obtain logical languages that can be used for rewriting the queries in
the second class, in such a way that query answering for the rewritten query can be
done in polynomial time.
      </p>
      <p>
        For the second problem, it would be interesting to see if second-order quantifier
elimination could be applied to second-order specification of Section 3, in such a way that
the resulting query is expressed, not in FO logic, but in fixed-point logic, which would
lead to a polynomial-time answer [
        <xref ref-type="bibr" rid="ref24">24</xref>
        ]. Actually, in [
        <xref ref-type="bibr" rid="ref18">18</xref>
        ], the authors have been able
to eliminate second-order quantifiers, obtaining fixed-point formulas. It is worth
investigating if this is a way to obtain polynomial-time, logical, but non-FO, rewritings for
CQA. This undertaking is not a priori impossible. The existence of non-FO rewritable
but PTIME-complete queries (in data) already identified [
        <xref ref-type="bibr" rid="ref23 ref35">35, 23</xref>
        ] is in principle
compatible with the PTIME-completeness of fixed-point logic (in data) [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ].
Acknowledgements: Useful comments from anonymous reviewers for a previous and
the submitted version of this paper are much appreciated. Leopoldo Bertossi has been
partially funded by the ANID - Millennium Science Initiative Program - Code
ICN17002.
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>Abiteboul</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Hull</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Vianu</surname>
          </string-name>
          , V. Foundations of Databases. Addison-Wesley,
          <year>1995</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>Ackermann</surname>
            ,
            <given-names>W. Untersuchungen</given-names>
          </string-name>
          <article-title>u¨ber das Eliminationsproblem der mathematischen Logik</article-title>
          .
          <source>Mathematische Annalen</source>
          ,
          <year>1935</year>
          ,
          <volume>110</volume>
          :
          <fpage>390</fpage>
          -
          <lpage>413</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>Ackermann</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          <article-title>Solvable cases of the Decision Problem. North-Holland Pub</article-title>
          . Co.,
          <year>1954</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <surname>Alviano</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Morak</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Pieris</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          <article-title>Stable Model Semantics for Tuple-Generating Dependencies Revisited</article-title>
          .
          <source>Proc. PODS</source>
          ,
          <year>2017</year>
          , pp.
          <fpage>377</fpage>
          -
          <lpage>388</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <surname>Arenas</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Bertossi</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Chomicki</surname>
          </string-name>
          ,
          <source>J. Consistent Query Answers in Inconsistent Databases. Proc. ACM Symposium on Principles of Database Systems</source>
          , ACM Press,
          <year>1999</year>
          , pp.
          <fpage>68</fpage>
          -
          <lpage>79</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>Barcelo</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Bertossi</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <article-title>Logic Programs for Querying Inconsistent Databases</article-title>
          .
          <source>Proc. Practical Aspects of Declarative Languages</source>
          , Springer LNCS 2562,
          <year>2003</year>
          , pp.
          <fpage>208</fpage>
          -
          <lpage>222</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <surname>Bertossi</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Schwind</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          <article-title>Database Repairs and Analytic Tableaux</article-title>
          .
          <source>Annals of Mathematics and Artificial Intelligence</source>
          ,
          <year>2004</year>
          ,
          <volume>40</volume>
          (
          <issue>1-2</issue>
          ):
          <fpage>5</fpage>
          -
          <lpage>35</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <surname>Bertossi</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <article-title>Consistent Query Answering in Databases</article-title>
          .
          <source>In ACM Sigmod Record</source>
          ,
          <year>June 2006</year>
          ,
          <volume>35</volume>
          (
          <issue>2</issue>
          ):
          <fpage>68</fpage>
          -
          <lpage>76</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <surname>Bertossi</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <article-title>From Database Repair Programs to Consistent Query Answering in Classical Logic (extended abstract)</article-title>
          .
          <source>Proc. Alberto Mendelzon International Workshop on Foundations of Data Managemente (AMW)</source>
          ,
          <year>2009</year>
          .
          <source>CEUR Workshop Proceedings</source>
          , Vol.
          <volume>450</volume>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <surname>Bertossi</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <string-name>
            <surname>Second-Order Specifications</surname>
          </string-name>
          and
          <article-title>Quantifier Elimination for Consistent Query Answering in Databases</article-title>
          .
          <source>Posted as Corr arXiv Paper 2108.08423</source>
          ,
          <year>2021</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Bertossi</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <article-title>Database Repairing and Consistent Query Answering</article-title>
          .
          <source>Synthesis Lectures on Data Management</source>
          , Morgan &amp; Claypool Publishers,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>Brewka</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Eiter</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Truszczynski</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <article-title>Answer Set Programming at a Glance</article-title>
          .
          <source>Communications of the ACM</source>
          ,
          <year>2011</year>
          ,
          <volume>54</volume>
          (
          <issue>12</issue>
          ):
          <fpage>92</fpage>
          -
          <lpage>103</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <surname>Caniupan-Marileo</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Bertossi</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <article-title>The Consistency Extractor System: Answer Set Programs for Consistent Query Answering in Databases</article-title>
          .
          <source>Data and Knowledge Engineering</source>
          ,
          <year>2010</year>
          ,
          <volume>69</volume>
          (
          <issue>6</issue>
          ):
          <fpage>545</fpage>
          -
          <lpage>572</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <surname>Chomicki</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Marcinkowski</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <article-title>Minimal-Change Integrity Maintenance using Tuple Deletions</article-title>
          .
          <source>Information and Computation</source>
          ,
          <year>2005</year>
          ,
          <volume>197</volume>
          (
          <issue>1-2</issue>
          ):
          <fpage>90</fpage>
          -
          <lpage>121</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <surname>Chomicki</surname>
            ,
            <given-names>J. Consistent</given-names>
          </string-name>
          <string-name>
            <surname>Query</surname>
          </string-name>
          <article-title>Answering: Five Easy Pieces</article-title>
          .
          <source>Proc. International Conference on Database Theory</source>
          , Springer LNCS 4353,
          <year>2007</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>17</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <surname>Dantsin</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Eiter</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gottlob</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          and
          <article-title>Voronkov, A. Complexity and Expressive Power of Logic Programming</article-title>
          .
          <source>ACM Computing Surveys</source>
          ,
          <year>2001</year>
          ,
          <volume>33</volume>
          (
          <issue>3</issue>
          ):
          <fpage>374</fpage>
          -
          <lpage>425</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <surname>Doherty</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lukaszewicz</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Szalas</surname>
            ,
            <given-names>A. Computing Circumscription</given-names>
          </string-name>
          <string-name>
            <surname>Revisited</surname>
          </string-name>
          .
          <article-title>A Reduction Algorithm</article-title>
          .
          <source>Journal of Automated Reasoning</source>
          ,
          <year>1997</year>
          ,
          <volume>18</volume>
          (
          <issue>3</issue>
          ):
          <fpage>297</fpage>
          -
          <lpage>336</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          [18]
          <string-name>
            <surname>Doherty</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lukaszewicz</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Szalas</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          <article-title>A Reduction Result for Circumscribed SemiHorn Formulas</article-title>
          .
          <source>Fundamenta Informaticae</source>
          ,
          <year>1996</year>
          ,
          <volume>28</volume>
          (
          <issue>3-4</issue>
          ):
          <fpage>261</fpage>
          -
          <lpage>271</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          [19]
          <string-name>
            <surname>Ferraris</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lee</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          <article-title>A New Perspective on Stable Models</article-title>
          .
          <source>In Proc. International Joint Conference on Artificial Intelligence</source>
          ,
          <year>2007</year>
          , pp.
          <fpage>372</fpage>
          -
          <lpage>379</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          [20]
          <string-name>
            <surname>Ferraris</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lee</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Lifschitz</surname>
          </string-name>
          , V.
          <source>Stable Models and Circumscription. Artificial Intelligence</source>
          ,
          <year>2011</year>
          ,
          <volume>175</volume>
          (
          <issue>1</issue>
          ):
          <fpage>236</fpage>
          -
          <lpage>263</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          [21]
          <string-name>
            <surname>Fuxman</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Miller</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          <article-title>First-Order Query Rewriting for Inconsistent Databases</article-title>
          .
          <source>J. Computer and Systems Sciences</source>
          ,
          <year>2007</year>
          ,
          <volume>73</volume>
          (
          <issue>4</issue>
          ):
          <fpage>610</fpage>
          -
          <lpage>635</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          [22]
          <string-name>
            <surname>Gelfond</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          <article-title>Classical Negation in Logic Programs</article-title>
          and
          <string-name>
            <given-names>Disjunctive</given-names>
            <surname>Databases</surname>
          </string-name>
          . New Generation Computing,
          <year>1991</year>
          ,
          <volume>9</volume>
          (
          <issue>3</issue>
          /4):
          <fpage>365</fpage>
          -
          <lpage>385</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref23">
        <mixed-citation>
          [23]
          <string-name>
            <surname>Koutris</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Wijsen</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <article-title>First-Order Rewritability in Consistent Query Answering with Respect to Multiple Keys</article-title>
          .
          <source>Proc. PODS</source>
          <year>2020</year>
          , pp.
          <fpage>113</fpage>
          -
          <lpage>129</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref24">
        <mixed-citation>
          [24]
          <string-name>
            <surname>Libkin</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <article-title>Elements of Finite Model Theory</article-title>
          . Springer,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref25">
        <mixed-citation>
          [25]
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V. Computing</given-names>
          </string-name>
          <string-name>
            <surname>Circumscription</surname>
          </string-name>
          .
          <source>Proc. International Joint Conference on Artificial Intelligence</source>
          , Morgan Kaufmann,
          <year>1985</year>
          , pp.
          <fpage>121</fpage>
          -
          <lpage>127</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref26">
        <mixed-citation>
          [26]
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          <string-name>
            <surname>Circumscription</surname>
          </string-name>
          .
          <source>In Handbook of Logic in Artificial Intelligence and Logic Programming</source>
          , Vol.
          <volume>3</volume>
          . Oxford University Press,
          <year>1994</year>
          , pp.
          <fpage>297</fpage>
          -
          <lpage>352</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref27">
        <mixed-citation>
          [27]
          <string-name>
            <surname>Lloyd</surname>
            ,
            <given-names>J.W.</given-names>
          </string-name>
          <article-title>Foundations of Logic Programming</article-title>
          . Springer Verlag,
          <year>1987</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref28">
        <mixed-citation>
          [28]
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Turner</surname>
            ,
            <given-names>H. Splitting</given-names>
          </string-name>
          <article-title>a Logic Program</article-title>
          .
          <source>Proc. International Conference on Logic Programming</source>
          , MIT Press,
          <year>1994</year>
          , pp.
          <fpage>23</fpage>
          -
          <lpage>37</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref29">
        <mixed-citation>
          [29]
          <string-name>
            <surname>McCarthy</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <article-title>Circumscription - A Form of Non-Monotonic Reasoning</article-title>
          .
          <source>Artificial Intelligence</source>
          ,
          <year>1980</year>
          ,
          <volume>13</volume>
          (
          <issue>1-2</issue>
          ):
          <fpage>27</fpage>
          -
          <lpage>39</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref30">
        <mixed-citation>
          [30]
          <string-name>
            <surname>Przymusinski</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          <article-title>On the Declarative Semantics of Deductive Databases and Logic Programs</article-title>
          . In Foundations of Deductive Databases and
          <string-name>
            <given-names>Logic</given-names>
            <surname>Programming</surname>
          </string-name>
          , J. Minker (ed.), Morgan Kaufmann Publishers Inc.,
          <year>1988</year>
          , pp.
          <fpage>193</fpage>
          -
          <lpage>216</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref31">
        <mixed-citation>
          [31]
          <string-name>
            <surname>Przymusinski</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          <article-title>Stable Semantics for Disjunctive Programs</article-title>
          . New Generation Computing,
          <year>1991</year>
          ,
          <volume>9</volume>
          (
          <issue>3</issue>
          /4):
          <fpage>401</fpage>
          -
          <lpage>424</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref32">
        <mixed-citation>
          [32]
          <string-name>
            <surname>Reiter</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          <string-name>
            <surname>Towards</surname>
          </string-name>
          <article-title>a Logical Reconstruction of Relational Database Theory</article-title>
          . In On Conceptual Modelling,
          <string-name>
            <given-names>M.L.</given-names>
            <surname>Brodie</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Mylopoulos</surname>
          </string-name>
          and
          <string-name>
            <surname>J.W.</surname>
          </string-name>
          Schmidt (eds.), Springer,
          <year>1984</year>
          , pp.
          <fpage>191</fpage>
          -
          <lpage>233</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref33">
        <mixed-citation>
          [33]
          <string-name>
            <surname>Van Hermelen</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Porter</surname>
            ,
            <given-names>B</given-names>
          </string-name>
          . (eds.)
          <source>Handbook of Knowledge Representation. Elsevier</source>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref34">
        <mixed-citation>
          [34]
          <string-name>
            <surname>Wijsen</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <article-title>A Remark on the Complexity of Consistent Conjunctive Query Answering under Primary Key Violations</article-title>
          .
          <source>Information Processing Letters</source>
          ,
          <year>2010</year>
          ,
          <volume>110</volume>
          :
          <fpage>950</fpage>
          -
          <lpage>955</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref35">
        <mixed-citation>
          [35]
          <string-name>
            <surname>Wijsen</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <article-title>On the Consistent Rewriting Of Conjunctive Queries under Primary Key Constraints</article-title>
          .
          <source>Information Systems</source>
          ,
          <year>2009</year>
          ,
          <volume>34</volume>
          :
          <fpage>578</fpage>
          -
          <lpage>601</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref36">
        <mixed-citation>
          [36]
          <string-name>
            <surname>Wijsen</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <article-title>A Survey of the Data Complexity of Consistent Query Answering under Key Constraints</article-title>
          .
          <source>Proc. FoIKS</source>
          <year>2014</year>
          , LNCS 8367, pp.
          <fpage>62</fpage>
          -
          <lpage>78</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref37">
        <mixed-citation>
          [37]
          <string-name>
            <surname>Wijsen</surname>
            ,
            <given-names>J</given-names>
          </string-name>
          .
          <source>Foundations of Query Answering on Inconsistent Databases. SIGMOD Record</source>
          ,
          <year>2019</year>
          ,
          <volume>48</volume>
          (
          <issue>3</issue>
          ):
          <fpage>6</fpage>
          -
          <lpage>16</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>