A Broad Class of First-Order Rewritable Tuple

A Broad Class of First-Order Rewritable
Tuple-Generating Dependencies
Datalog 2.0 Workshop 2012
C. Civili and R. Rosati
Department of Computer, Control,
and Management Engineering Antonio Ruberti,
Sapienza University of Rome, Italy
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Outline
1
Introduction
2
Preliminaries
3
Weakly Recursive simple TGDs
4
Query Rewriting
5
Conclusions
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Introduction
• Interesting recent works on Datalog extensions are based on the idea
of extending Datalog rules with existential variables in rule heads.
• This kind of rules correspond to tuple-generating dependencies
(TGDs), a well-known form of database dependencies in database
theory.
• The problem of reasoning over Datalog programs with existential
variables in rule heads corresponds to the problem of reasoning over a
database with TGDs under an open-world assumption.
• Almost all the recent approaches to this problem focus on
conjunctive query answering under TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The Problem
• We are interested in first-order rewritable TGDs, i.e., classes of
TGDs for which conjunctive query answering can be reduced to the
evaluation of a first-order query over the database.
• Very important both from the theoretical and the practical viewpoint.
• Such classes of TGDs could be used for building efficient query
answering systems that delegate data management to standard
relational database technology, like in ontology-based data access
(OBDA) systems.
• Our aim is to identify a broader class of TGDs that comprises all
known FOL-rewritable classes of TGDs, and in particular acyclic
TGDs, multi-linear TGDs, and sticky-join TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Our Contributions
1
We define the class of weakly recursive TGDs.
2
We prove that weakly recursive TGDs are first-order rewritable,
by defining an algorithm that is able to compute the first-order
rewriting of conjunctive queries over weakly recursive TGDs and
proving termination of this algorithm over weakly recursive TGDs.
3
We prove that, under the restriction to simple TGDs, weakly
recursive TGDs comprise and generalize every previously known
FOL-rewritable class of TGDs, in particular, acyclic TGDs, linear
TGDs, multi-linear TGDs, sticky TGDs, sticky-join TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Our Contributions
1
We define the class of weakly recursive TGDs.
2
We prove that weakly recursive TGDs are first-order rewritable,
by defining an algorithm that is able to compute the first-order
rewriting of conjunctive queries over weakly recursive TGDs and
proving termination of this algorithm over weakly recursive TGDs.
3
We prove that, under the restriction to simple TGDs, weakly
recursive TGDs comprise and generalize every previously known
FOL-rewritable class of TGDs, in particular, acyclic TGDs, linear
TGDs, multi-linear TGDs, sticky TGDs, sticky-join TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Our Contributions
1
We define the class of weakly recursive TGDs.
2
We prove that weakly recursive TGDs are first-order rewritable,
by defining an algorithm that is able to compute the first-order
rewriting of conjunctive queries over weakly recursive TGDs and
proving termination of this algorithm over weakly recursive TGDs.
3
We prove that, under the restriction to simple TGDs, weakly
recursive TGDs comprise and generalize every previously known
FOL-rewritable class of TGDs, in particular, acyclic TGDs, linear
TGDs, multi-linear TGDs, sticky TGDs, sticky-join TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Our Contributions
1
We define the class of weakly recursive TGDs.
2
We prove that weakly recursive TGDs are first-order rewritable,
by defining an algorithm that is able to compute the first-order
rewriting of conjunctive queries over weakly recursive TGDs and
proving termination of this algorithm over weakly recursive TGDs.
3
We prove that, under the restriction to simple TGDs, weakly
recursive TGDs comprise and generalize every previously known
FOL-rewritable class of TGDs, in particular, acyclic TGDs, linear
TGDs, multi-linear TGDs, sticky TGDs, sticky-join TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Outline
1
Introduction
2
Preliminaries
3
Weakly Recursive simple TGDs
4
Query Rewriting
5
Conclusions
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Syntax
• A tuple-generating dependency (TGD) R is an expression of the
•
•
•
•
•
form β1 , . . . , βn → α1 , . . . , αm , where α1 , . . . , αm , β1 , . . . , βn are
atoms and m ≥ 1, n ≥ 1.
Given an atom γ, we denote by Rel(γ) the relation symbol of γ.
We call distinguished variables of R the variables occurring in the
head and in the body of R, existential body variables of R the ones
occurring only in the body of R, and existential head variables of R
the ones occurring only in the head of R.
We focus on simple TGDs, i.e., TGDs in which every atom does not
contain occurrences of constants and does not contain repeated
occurrences of variables.
A CQ q is an expression of the form q(x) :- α1 , . . . , αn , where
α1 , . . . , αn (body) is a sequence of atoms.
A UCQ is a set of CQs of the same arity.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Syntax
• A tuple-generating dependency (TGD) R is an expression of the
•
•
•
•
•
form β1 , . . . , βn → α1 , . . . , αm , where α1 , . . . , αm , β1 , . . . , βn are
atoms and m ≥ 1, n ≥ 1.
Given an atom γ, we denote by Rel(γ) the relation symbol of γ.
We call distinguished variables of R the variables occurring in the
head and in the body of R, existential body variables of R the ones
occurring only in the body of R, and existential head variables of R
the ones occurring only in the head of R.
We focus on simple TGDs, i.e., TGDs in which every atom does not
contain occurrences of constants and does not contain repeated
occurrences of variables.
A CQ q is an expression of the form q(x) :- α1 , . . . , αn , where
α1 , . . . , αn (body) is a sequence of atoms.
A UCQ is a set of CQs of the same arity.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Syntax
• A tuple-generating dependency (TGD) R is an expression of the
•
•
•
•
•
form β1 , . . . , βn → α1 , . . . , αm , where α1 , . . . , αm , β1 , . . . , βn are
atoms and m ≥ 1, n ≥ 1.
Given an atom γ, we denote by Rel(γ) the relation symbol of γ.
We call distinguished variables of R the variables occurring in the
head and in the body of R, existential body variables of R the ones
occurring only in the body of R, and existential head variables of R
the ones occurring only in the head of R.
We focus on simple TGDs, i.e., TGDs in which every atom does not
contain occurrences of constants and does not contain repeated
occurrences of variables.
A CQ q is an expression of the form q(x) :- α1 , . . . , αn , where
α1 , . . . , αn (body) is a sequence of atoms.
A UCQ is a set of CQs of the same arity.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Syntax
• A tuple-generating dependency (TGD) R is an expression of the
•
•
•
•
•
form β1 , . . . , βn → α1 , . . . , αm , where α1 , . . . , αm , β1 , . . . , βn are
atoms and m ≥ 1, n ≥ 1.
Given an atom γ, we denote by Rel(γ) the relation symbol of γ.
We call distinguished variables of R the variables occurring in the
head and in the body of R, existential body variables of R the ones
occurring only in the body of R, and existential head variables of R
the ones occurring only in the head of R.
We focus on simple TGDs, i.e., TGDs in which every atom does not
contain occurrences of constants and does not contain repeated
occurrences of variables.
A CQ q is an expression of the form q(x) :- α1 , . . . , αn , where
α1 , . . . , αn (body) is a sequence of atoms.
A UCQ is a set of CQs of the same arity.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Syntax
• A tuple-generating dependency (TGD) R is an expression of the
•
•
•
•
•
form β1 , . . . , βn → α1 , . . . , αm , where α1 , . . . , αm , β1 , . . . , βn are
atoms and m ≥ 1, n ≥ 1.
Given an atom γ, we denote by Rel(γ) the relation symbol of γ.
We call distinguished variables of R the variables occurring in the
head and in the body of R, existential body variables of R the ones
occurring only in the body of R, and existential head variables of R
the ones occurring only in the head of R.
We focus on simple TGDs, i.e., TGDs in which every atom does not
contain occurrences of constants and does not contain repeated
occurrences of variables.
A CQ q is an expression of the form q(x) :- α1 , . . . , αn , where
α1 , . . . , αn (body) is a sequence of atoms.
A UCQ is a set of CQs of the same arity.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Syntax
• A tuple-generating dependency (TGD) R is an expression of the
•
•
•
•
•
form β1 , . . . , βn → α1 , . . . , αm , where α1 , . . . , αm , β1 , . . . , βn are
atoms and m ≥ 1, n ≥ 1.
Given an atom γ, we denote by Rel(γ) the relation symbol of γ.
We call distinguished variables of R the variables occurring in the
head and in the body of R, existential body variables of R the ones
occurring only in the body of R, and existential head variables of R
the ones occurring only in the head of R.
We focus on simple TGDs, i.e., TGDs in which every atom does not
contain occurrences of constants and does not contain repeated
occurrences of variables.
A CQ q is an expression of the form q(x) :- α1 , . . . , αn , where
α1 , . . . , αn (body) is a sequence of atoms.
A UCQ is a set of CQs of the same arity.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Semantics
Let P be a set of TGDs, let q be a UCQ and let D or B be databases.
• Given a TGD R of the form β1 , . . . , βn → α1 , . . . , αm and a database
B, we say that B satisfies R if the first-order interpretation I B
satisfies the first-order sentence ∀~x .β1 ∧ . . . ∧ βn → ∃~y .α1 ∧ . . . ∧ αm .
• sem(P, D) = set of all models of P ∪ D.
• ans(q, B) = set of tuples of constants c such that I B satisfies q(c).
• cert(q, P, D) = set of tuples c such that c ∈
T
B∈sem(P,D) ans(q, B).
• P is FOL-rewritable if, for every UCQ q, there exists a FOL query q 0
such that, for every database D, cert(q, P, D) = ans(q 0 , D).
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Semantics
Let P be a set of TGDs, let q be a UCQ and let D or B be databases.
• Given a TGD R of the form β1 , . . . , βn → α1 , . . . , αm and a database
B, we say that B satisfies R if the first-order interpretation I B
satisfies the first-order sentence ∀~x .β1 ∧ . . . ∧ βn → ∃~y .α1 ∧ . . . ∧ αm .
• sem(P, D) = set of all models of P ∪ D.
• ans(q, B) = set of tuples of constants c such that I B satisfies q(c).
• cert(q, P, D) = set of tuples c such that c ∈
T
B∈sem(P,D) ans(q, B).
• P is FOL-rewritable if, for every UCQ q, there exists a FOL query q 0
such that, for every database D, cert(q, P, D) = ans(q 0 , D).
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Semantics
Let P be a set of TGDs, let q be a UCQ and let D or B be databases.
• Given a TGD R of the form β1 , . . . , βn → α1 , . . . , αm and a database
B, we say that B satisfies R if the first-order interpretation I B
satisfies the first-order sentence ∀~x .β1 ∧ . . . ∧ βn → ∃~y .α1 ∧ . . . ∧ αm .
• sem(P, D) = set of all models of P ∪ D.
• ans(q, B) = set of tuples of constants c such that I B satisfies q(c).
• cert(q, P, D) = set of tuples c such that c ∈
T
B∈sem(P,D) ans(q, B).
• P is FOL-rewritable if, for every UCQ q, there exists a FOL query q 0
such that, for every database D, cert(q, P, D) = ans(q 0 , D).
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Semantics
Let P be a set of TGDs, let q be a UCQ and let D or B be databases.
• Given a TGD R of the form β1 , . . . , βn → α1 , . . . , αm and a database
B, we say that B satisfies R if the first-order interpretation I B
satisfies the first-order sentence ∀~x .β1 ∧ . . . ∧ βn → ∃~y .α1 ∧ . . . ∧ αm .
• sem(P, D) = set of all models of P ∪ D.
• ans(q, B) = set of tuples of constants c such that I B satisfies q(c).
• cert(q, P, D) = set of tuples c such that c ∈
T
B∈sem(P,D) ans(q, B).
• P is FOL-rewritable if, for every UCQ q, there exists a FOL query q 0
such that, for every database D, cert(q, P, D) = ans(q 0 , D).
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Semantics
Let P be a set of TGDs, let q be a UCQ and let D or B be databases.
• Given a TGD R of the form β1 , . . . , βn → α1 , . . . , αm and a database
B, we say that B satisfies R if the first-order interpretation I B
satisfies the first-order sentence ∀~x .β1 ∧ . . . ∧ βn → ∃~y .α1 ∧ . . . ∧ αm .
• sem(P, D) = set of all models of P ∪ D.
• ans(q, B) = set of tuples of constants c such that I B satisfies q(c).
• cert(q, P, D) = set of tuples c such that c ∈
T
B∈sem(P,D) ans(q, B).
• P is FOL-rewritable if, for every UCQ q, there exists a FOL query q 0
such that, for every database D, cert(q, P, D) = ans(q 0 , D).
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Semantics
Let P be a set of TGDs, let q be a UCQ and let D or B be databases.
• Given a TGD R of the form β1 , . . . , βn → α1 , . . . , αm and a database
B, we say that B satisfies R if the first-order interpretation I B
satisfies the first-order sentence ∀~x .β1 ∧ . . . ∧ βn → ∃~y .α1 ∧ . . . ∧ αm .
• sem(P, D) = set of all models of P ∪ D.
• ans(q, B) = set of tuples of constants c such that I B satisfies q(c).
• cert(q, P, D) = set of tuples c such that c ∈
T
B∈sem(P,D) ans(q, B).
• P is FOL-rewritable if, for every UCQ q, there exists a FOL query q 0
such that, for every database D, cert(q, P, D) = ans(q 0 , D).
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Outline
1
Introduction
2
Preliminaries
3
Weakly Recursive simple TGDs
4
Query Rewriting
5
Conclusions
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Some Definitions
• A position σ is either an expression of the form r [i] or an expression
of the form r [ ], where r is a relation symbol and i is an integer such
that 1 ≤ i ≤ k, where k is the arity of r .
• Let R be a TGD of the form β1 , . . . , βn → α1 , . . . , αm , and let α be
an atom of head(R). Then:
i given a position r [ ], we say that α is R-compatible with r [ ] if
Rel(α) = r ;
ii given a position r [i], we say that α is R-compatible with r [i] if
Rel(α) = r and α[i] is a distinguished variable of R.
• Given an atom β of the body and a variable x occurring in β in
position i, we denote by Pos(x, β) the position r [i].
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Some Definitions
• A position σ is either an expression of the form r [i] or an expression
of the form r [ ], where r is a relation symbol and i is an integer such
that 1 ≤ i ≤ k, where k is the arity of r .
• Let R be a TGD of the form β1 , . . . , βn → α1 , . . . , αm , and let α be
an atom of head(R). Then:
i given a position r [ ], we say that α is R-compatible with r [ ] if
Rel(α) = r ;
ii given a position r [i], we say that α is R-compatible with r [i] if
Rel(α) = r and α[i] is a distinguished variable of R.
• Given an atom β of the body and a variable x occurring in β in
position i, we denote by Pos(x, β) the position r [i].
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Some Definitions
• A position σ is either an expression of the form r [i] or an expression
of the form r [ ], where r is a relation symbol and i is an integer such
that 1 ≤ i ≤ k, where k is the arity of r .
• Let R be a TGD of the form β1 , . . . , βn → α1 , . . . , αm , and let α be
an atom of head(R). Then:
i given a position r [ ], we say that α is R-compatible with r [ ] if
Rel(α) = r ;
ii given a position r [i], we say that α is R-compatible with r [i] if
Rel(α) = r and α[i] is a distinguished variable of R.
• Given an atom β of the body and a variable x occurring in β in
position i, we denote by Pos(x, β) the position r [i].
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Some Definitions
• A position σ is either an expression of the form r [i] or an expression
of the form r [ ], where r is a relation symbol and i is an integer such
that 1 ≤ i ≤ k, where k is the arity of r .
• Let R be a TGD of the form β1 , . . . , βn → α1 , . . . , αm , and let α be
an atom of head(R). Then:
i given a position r [ ], we say that α is R-compatible with r [ ] if
Rel(α) = r ;
ii given a position r [i], we say that α is R-compatible with r [i] if
Rel(α) = r and α[i] is a distinguished variable of R.
• Given an atom β of the body and a variable x occurring in β in
position i, we denote by Pos(x, β) the position r [i].
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Some Definitions
• A position σ is either an expression of the form r [i] or an expression
of the form r [ ], where r is a relation symbol and i is an integer such
that 1 ≤ i ≤ k, where k is the arity of r .
• Let R be a TGD of the form β1 , . . . , βn → α1 , . . . , αm , and let α be
an atom of head(R). Then:
i given a position r [ ], we say that α is R-compatible with r [ ] if
Rel(α) = r ;
ii given a position r [i], we say that α is R-compatible with r [i] if
Rel(α) = r and α[i] is a distinguished variable of R.
• Given an atom β of the body and a variable x occurring in β in
position i, we denote by Pos(x, β) the position r [i].
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The Notion of Position Graph
A position graph is a graph that encodes the structure of a program P:
• nodes are positions;
• edges reflect the structure of program rules (from head to body);
• can be used to determine whether P is FOL-rewritable;
• graph edges are classified (m-edges, s-edges) so as to distinguish
dangerous and harmless cycles in the graph.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The Notion of Position Graph
A position graph is a graph that encodes the structure of a program P:
• nodes are positions;
• edges reflect the structure of program rules (from head to body);
• can be used to determine whether P is FOL-rewritable;
• graph edges are classified (m-edges, s-edges) so as to distinguish
dangerous and harmless cycles in the graph.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The Notion of Position Graph
A position graph is a graph that encodes the structure of a program P:
• nodes are positions;
• edges reflect the structure of program rules (from head to body);
• can be used to determine whether P is FOL-rewritable;
• graph edges are classified (m-edges, s-edges) so as to distinguish
dangerous and harmless cycles in the graph.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The Notion of Position Graph
A position graph is a graph that encodes the structure of a program P:
• nodes are positions;
• edges reflect the structure of program rules (from head to body);
• can be used to determine whether P is FOL-rewritable;
• graph edges are classified (m-edges, s-edges) so as to distinguish
dangerous and harmless cycles in the graph.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The Position Graph #1
Definition
Given a set P of TGDs, the position graph of P, PG (P), is a triple
hV , E , Li where V (the set of nodes of PG (P)) is a set of positions, E is a
set of edges (pairs of nodes), and L is an edge labeling function
L : E → 2{m,s} . PG (P) is inductively defined as follows:
• for every TGD R ∈ P of the form β1 , . . . , βn → α1 , . . . , αm and for
every i such that 1 ≤ i ≤ m, r [ ] ∈ V where r = Rel(αi );
• if σ ∈ V , then for every TGD R ∈ P and for every atom α of
head(R) that is R-compatible with σ:
1. for every atom β ∈ body (R):
(a) hσ, s[ ]i ∈ E , where s = Rel(β);
(b) for each existential body variable z of R occurring in β, hσ, σ 0 i ∈ E ,
where σ 0 = Pos(z, β);
(continue)
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The Position Graph #2
Definition
(continued)
(c) if σ is of the form r [i], then hσ, σ 00 i ∈ E , where σ 00 = Pos(y , β) and y
is the variable occurring in α at position i;
(d) if there exists a distinguished variable of R that does not occur in β,
then, for every edge e added to E at points (a), (b), (c), m ∈ L(e);
2. if there exists an existential body variable x of R occurring in at least
two atoms of body (R), then for every edge e added to E at point 1,
s ∈ L(e);
3. if σ is of the form r [i], y is the variable occurring in α at position i,
and y occurs in at least two atoms of body (R), then, for every edge e
added to E at point 1, s ∈ L(e).
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Weakly Recursive Simple TGDs
We call m-edge an edge e such that m ∈ L(e), and call s-edge an edge e
such that s ∈ L(e).
Definition
A set of simple TGDs P is weakly recursive (WR) if in PG (P) there exists
no cycle that contains both an m-edge and an s-edge.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Weakly Recursive Simple TGDs
We call m-edge an edge e such that m ∈ L(e), and call s-edge an edge e
such that s ∈ L(e).
Definition
A set of simple TGDs P is weakly recursive (WR) if in PG (P) there exists
no cycle that contains both an m-edge and an s-edge.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
An Example #1
Example
Let P be the following set of TGDs:
R1 : s(x, w , y ), t(z) → r (x, y ), p(y , z)
R2 : v (x, y ), q(y ) → s(x, z, y )
R3 : r (x, y ) → v (x, y )
Since there are no s-edges in PG (P), it immediately follows that P is a
weakly recursive set of TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
An Example #1
Example
Let P be the following set of TGDs:
R1 : s(x, w , y ), t(z) → r (x, y ), p(y , z)
R2 : v (x, y ), q(y ) → s(x, z, y )
R3 : r (x, y ) → v (x, y )
Since there are no s-edges in PG (P), it immediately follows that P is a
weakly recursive set of TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
An Example #2
Example
Let P be the following set of
TGDs:
R1 : s(x, w ), t(y , z) → r (x, y , z)
R2 : p(x, y ), v (y ) → s(x, y )
R3 : r (x, y , z) → p(x, y ), t(y , z)
This graph contains a cycle that has both an m-edge and an s-edge.
Consequently, P is not a weakly recursive set of TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
An Example #2
Example
Let P be the following set of
TGDs:
R1 : s(x, w ), t(y , z) → r (x, y , z)
R2 : p(x, y ), v (y ) → s(x, y )
R3 : r (x, y , z) → p(x, y ), t(y , z)
This graph contains a cycle that has both an m-edge and an s-edge.
Consequently, P is not a weakly recursive set of TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Outline
1
Introduction
2
Preliminaries
3
Weakly Recursive simple TGDs
4
Query Rewriting
5
Conclusions
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Query Rewriting for Weakly Recursive TGDs
• We present an algorithm that, given a UCQ Q and a set P of TGDs,
computes a FOL perfect rewriting of Q under P.
• The only purpose of the version presented here is to show that weakly
recursive TGDs are FOL-rewritable.
• The algorithm assumes that TGDs are single-head TGDs, i.e., TGDs
of the form β1 , . . . , βn → α, in which only one atom occurs in the
head of every TGD.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Query Rewriting for Weakly Recursive TGDs
• We present an algorithm that, given a UCQ Q and a set P of TGDs,
computes a FOL perfect rewriting of Q under P.
• The only purpose of the version presented here is to show that weakly
recursive TGDs are FOL-rewritable.
• The algorithm assumes that TGDs are single-head TGDs, i.e., TGDs
of the form β1 , . . . , βn → α, in which only one atom occurs in the
head of every TGD.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Query Rewriting for Weakly Recursive TGDs
• We present an algorithm that, given a UCQ Q and a set P of TGDs,
computes a FOL perfect rewriting of Q under P.
• The only purpose of the version presented here is to show that weakly
recursive TGDs are FOL-rewritable.
• The algorithm assumes that TGDs are single-head TGDs, i.e., TGDs
of the form β1 , . . . , βn → α, in which only one atom occurs in the
head of every TGD.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The algorithm WRQueryRewrite #1
Input: set of simple, single-head TGDs P, UCQ Q
Output: UCQ Q 0
begin
P 0 := P; Q 0 := Normalize(Q); Qnew := Q 0 ;
repeat
Qaux := Q 0 ; QP := Qnew ; Qnew := ∅;
for each q ∈ QP do
for each g 1, g 2 ∈ body (q) do
if g 1 and g 2 unify and belong to the same join-conn. comp. of q
then Qnew := Qnew ∪ {reduce(q, g 1, g 2)};
for each g ∈ body (q) do
for each R ∈ P 0 do
if R is applicable to g
then Qnew := Qnew ∪ {atom-rewrite(q, g , R)};
Qnew := Normalize(Qnew );
for each q ∈ Qnew do
if q is not equal to any query of Q 0 up to variable renaming
then Q 0 := Q 0 ∪ {q};
until Q 0 = Qaux ;
return Q 0 ;
end
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The algorithm WRQueryRewrite #2
The three main steps of the algorithm are the following:
1
Query Normalization: redundant atoms are removed from each
query.
2
Reduction: unifiable atoms of each query are substituted with the
atom obtained by applying to them their MGU.
Differently from previous techniques, the algorithm only considers
pairs of atoms that belong to the same join-connected component of
the CQ.
3
Atom Rewrite: if we find a rule R which is R-applicable to an atom
of the query, we substitute such atom with the atoms obtained by
applying to them the MGU between the atom and the head of the
rule.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The algorithm WRQueryRewrite #2
The three main steps of the algorithm are the following:
1
Query Normalization: redundant atoms are removed from each
query.
2
Reduction: unifiable atoms of each query are substituted with the
atom obtained by applying to them their MGU.
Differently from previous techniques, the algorithm only considers
pairs of atoms that belong to the same join-connected component of
the CQ.
3
Atom Rewrite: if we find a rule R which is R-applicable to an atom
of the query, we substitute such atom with the atoms obtained by
applying to them the MGU between the atom and the head of the
rule.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The algorithm WRQueryRewrite #2
The three main steps of the algorithm are the following:
1
Query Normalization: redundant atoms are removed from each
query.
2
Reduction: unifiable atoms of each query are substituted with the
atom obtained by applying to them their MGU.
Differently from previous techniques, the algorithm only considers
pairs of atoms that belong to the same join-connected component of
the CQ.
3
Atom Rewrite: if we find a rule R which is R-applicable to an atom
of the query, we substitute such atom with the atoms obtained by
applying to them the MGU between the atom and the head of the
rule.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The algorithm WRQueryRewrite #2
The three main steps of the algorithm are the following:
1
Query Normalization: redundant atoms are removed from each
query.
2
Reduction: unifiable atoms of each query are substituted with the
atom obtained by applying to them their MGU.
Differently from previous techniques, the algorithm only considers
pairs of atoms that belong to the same join-connected component of
the CQ.
3
Atom Rewrite: if we find a rule R which is R-applicable to an atom
of the query, we substitute such atom with the atoms obtained by
applying to them the MGU between the atom and the head of the
rule.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The algorithm WRQueryRewrite #4
The WRQueryRewrite algorithm enjoys the folloqing important property:
Theorem
Let P be a set of single-head TGDs and let Q be a UCQ such that
WRQueryRewrite(Q, P) terminates. Let Q 0 be the UCQ returned by
WRQueryRewrite(Q, P). Then, Q 0 is a perfect rewriting of Q with respect
to P.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
The algorithm WRQueryRewrite #4
The WRQueryRewrite algorithm enjoys the folloqing important property:
Theorem
Let P be a set of single-head TGDs and let Q be a UCQ such that
WRQueryRewrite(Q, P) terminates. Let Q 0 be the UCQ returned by
WRQueryRewrite(Q, P). Then, Q 0 is a perfect rewriting of Q with respect
to P.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
FOL-rewritability of weakly recursive TGDs #1
1
We prove that the class of weakly recursive TGDs is FOL-rewritable
by showing that the algorithm WRQueryRewrite(q, P) always
terminates if P is a weakly recursive set of single-head TGDs.
Lemma
Let P be a set of simple TGDs and let Q be a UCQ. If
WRQueryRewrite(Q, P) does not terminate, then for every integer n there
exists a CQ q returned by WRQueryRewrite(Q, P) such that q has at least
one join-connected component with more than n ebj-variables.
2
We prove that, if P is a weakly recursive set of TGDs, then for every
UCQ Q the number of ebj-variables in every join-connected
component of a CQ returned by WRQueryRewrite(Q, P) is actually
bounded, and therefore, by the above lemma, the algorithm
terminates.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
FOL-rewritability of weakly recursive TGDs #1
1
We prove that the class of weakly recursive TGDs is FOL-rewritable
by showing that the algorithm WRQueryRewrite(q, P) always
terminates if P is a weakly recursive set of single-head TGDs.
Lemma
Let P be a set of simple TGDs and let Q be a UCQ. If
WRQueryRewrite(Q, P) does not terminate, then for every integer n there
exists a CQ q returned by WRQueryRewrite(Q, P) such that q has at least
one join-connected component with more than n ebj-variables.
2
We prove that, if P is a weakly recursive set of TGDs, then for every
UCQ Q the number of ebj-variables in every join-connected
component of a CQ returned by WRQueryRewrite(Q, P) is actually
bounded, and therefore, by the above lemma, the algorithm
terminates.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
FOL-rewritability of weakly recursive TGDs #1
1
We prove that the class of weakly recursive TGDs is FOL-rewritable
by showing that the algorithm WRQueryRewrite(q, P) always
terminates if P is a weakly recursive set of single-head TGDs.
Lemma
Let P be a set of simple TGDs and let Q be a UCQ. If
WRQueryRewrite(Q, P) does not terminate, then for every integer n there
exists a CQ q returned by WRQueryRewrite(Q, P) such that q has at least
one join-connected component with more than n ebj-variables.
2
We prove that, if P is a weakly recursive set of TGDs, then for every
UCQ Q the number of ebj-variables in every join-connected
component of a CQ returned by WRQueryRewrite(Q, P) is actually
bounded, and therefore, by the above lemma, the algorithm
terminates.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
FOL-rewritability of weakly recursive TGDs #2
3
This in turn implies, by the previous theorem, that weakly recursive
TGDs are a FOL-rewritable class of TGDs.
Theorem
Let P be a set of TGDs and let Q be a UCQ. If the execution of
WRQueryRewrite(Q, P) does not terminate, then there exists a cycle in
PG (P) containing both an m-edge and an s-edge.
4
As a corollary, we get that the execution of WRQueryRewrite(Q, P)
always terminates over weakly recursive TGDs. Therefore, we obtain
the following theorem.
Theorem
Every weakly recursive set of TGDs is FOL-rewritable.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
FOL-rewritability of weakly recursive TGDs #2
3
This in turn implies, by the previous theorem, that weakly recursive
TGDs are a FOL-rewritable class of TGDs.
Theorem
Let P be a set of TGDs and let Q be a UCQ. If the execution of
WRQueryRewrite(Q, P) does not terminate, then there exists a cycle in
PG (P) containing both an m-edge and an s-edge.
4
As a corollary, we get that the execution of WRQueryRewrite(Q, P)
always terminates over weakly recursive TGDs. Therefore, we obtain
the following theorem.
Theorem
Every weakly recursive set of TGDs is FOL-rewritable.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
FOL-rewritability of weakly recursive TGDs #2
3
This in turn implies, by the previous theorem, that weakly recursive
TGDs are a FOL-rewritable class of TGDs.
Theorem
Let P be a set of TGDs and let Q be a UCQ. If the execution of
WRQueryRewrite(Q, P) does not terminate, then there exists a cycle in
PG (P) containing both an m-edge and an s-edge.
4
As a corollary, we get that the execution of WRQueryRewrite(Q, P)
always terminates over weakly recursive TGDs. Therefore, we obtain
the following theorem.
Theorem
Every weakly recursive set of TGDs is FOL-rewritable.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
FOL-rewritability of weakly recursive TGDs #2
3
This in turn implies, by the previous theorem, that weakly recursive
TGDs are a FOL-rewritable class of TGDs.
Theorem
Let P be a set of TGDs and let Q be a UCQ. If the execution of
WRQueryRewrite(Q, P) does not terminate, then there exists a cycle in
PG (P) containing both an m-edge and an s-edge.
4
As a corollary, we get that the execution of WRQueryRewrite(Q, P)
always terminates over weakly recursive TGDs. Therefore, we obtain
the following theorem.
Theorem
Every weakly recursive set of TGDs is FOL-rewritable.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Outline
1
Introduction
2
Preliminaries
3
Weakly Recursive simple TGDs
4
Query Rewriting
5
Conclusions
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Comparison
• We show that the weakly recursive class comprises and generalizes
every previously known FOL-rewritable class of TGDs.
Theorem
The class of weakly recursive simple TGDs strictly contains the class of
multi-linear simple TGDs.
Theorem
The class of weakly recursive simple TGDs strictly contains the class of
sticky-join simple TGDs.
• Moreover, acyclic TGDs are trivially FOL-rewritable
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Comparison
• We show that the weakly recursive class comprises and generalizes
every previously known FOL-rewritable class of TGDs.
Theorem
The class of weakly recursive simple TGDs strictly contains the class of
multi-linear simple TGDs.
Theorem
The class of weakly recursive simple TGDs strictly contains the class of
sticky-join simple TGDs.
• Moreover, acyclic TGDs are trivially FOL-rewritable
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Comparison
• We show that the weakly recursive class comprises and generalizes
every previously known FOL-rewritable class of TGDs.
Theorem
The class of weakly recursive simple TGDs strictly contains the class of
multi-linear simple TGDs.
Theorem
The class of weakly recursive simple TGDs strictly contains the class of
sticky-join simple TGDs.
• Moreover, acyclic TGDs are trivially FOL-rewritable
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Comparison
• We show that the weakly recursive class comprises and generalizes
every previously known FOL-rewritable class of TGDs.
Theorem
The class of weakly recursive simple TGDs strictly contains the class of
multi-linear simple TGDs.
Theorem
The class of weakly recursive simple TGDs strictly contains the class of
sticky-join simple TGDs.
• Moreover, acyclic TGDs are trivially FOL-rewritable
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Comparison
This is true under the restriction to simple TGDs.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Future Work
This work is a further step towards the definition of a maximal class of
TGDs supporting efficient query answering.
Open challenges:
1
extending these results to non-simple TGDs, i.e., TGDs with repeated
variables within the same atom and with constants;
2
generalizing the class of weakly recursive TGDs to other decidable,
and possibly tractable, classes;
3
identifying new classes of TGDs for which query answering is in
PTIME with respect to data complexity;
4
optimizing the WRQueryRewrite algorithm for the usage of weakly
recursive TGDs in real applications.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Future Work
This work is a further step towards the definition of a maximal class of
TGDs supporting efficient query answering.
Open challenges:
1
extending these results to non-simple TGDs, i.e., TGDs with repeated
variables within the same atom and with constants;
2
generalizing the class of weakly recursive TGDs to other decidable,
and possibly tractable, classes;
3
identifying new classes of TGDs for which query answering is in
PTIME with respect to data complexity;
4
optimizing the WRQueryRewrite algorithm for the usage of weakly
recursive TGDs in real applications.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Future Work
This work is a further step towards the definition of a maximal class of
TGDs supporting efficient query answering.
Open challenges:
1
extending these results to non-simple TGDs, i.e., TGDs with repeated
variables within the same atom and with constants;
2
generalizing the class of weakly recursive TGDs to other decidable,
and possibly tractable, classes;
3
identifying new classes of TGDs for which query answering is in
PTIME with respect to data complexity;
4
optimizing the WRQueryRewrite algorithm for the usage of weakly
recursive TGDs in real applications.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati
Introduction
Preliminaries
Weakly Recursive simple TGDs
Query Rewriting
Conclusions
Future Work
This work is a further step towards the definition of a maximal class of
TGDs supporting efficient query answering.
Open challenges:
1
extending these results to non-simple TGDs, i.e., TGDs with repeated
variables within the same atom and with constants;
2
generalizing the class of weakly recursive TGDs to other decidable,
and possibly tractable, classes;
3
identifying new classes of TGDs for which query answering is in
PTIME with respect to data complexity;
4
optimizing the WRQueryRewrite algorithm for the usage of weakly
recursive TGDs in real applications.
A Broad Class of First-Order Rewritable Tuple-Generating Dependencies
C. Civili and R. Rosati