Академический Документы
Профессиональный Документы
Культура Документы
DATABASE SYSTEM
● Raguman K- 16BCE0917
COURSE CODE:CSE2004
DATABASE MANAGMENT SYSTEMS
SLOT NO : A11+A12
PROFESSOR NAME : Vijayarajan V
ABSTRACT
The convergence of relational database , logic and
artificial intelligence gave birth to deductive
database. A deductive database consists of rules and
facts through a language in which we specify what to
achieve rather than how to achieve . Facts are
specified in a manner similar to the way relations
are specified but it does not include attribute names
rather rules are virtual relations that are not actually
stored but can be implied using implying
mechanism. In deductive database there are two
components: database storage and logic to derive
information . This implies that a database can
conclude additional facts based on rules and facts
stored in the database itself. Deductive database
uses Datalog as its database query language .
Deductive databases are considered to be more
expressive than relational database. Datalog allows
us to write queries as normal logic operations and
are ensured to terminating upon some conditions.
We will be using Datalog Educational System for
highlighting its features and importance over SQL.
What is Datalog?
Datalog is a nonprocedural query language based on
the logic-programming language Prolog. A user
describes the information desired without giving a
specific procedure for obtaining that information.
Datalog simplifies writing simple queries and makes
query optimization easier.
Logical Query Languages
Motivation
Logical rules extend more naturally to
recursive queries than does relational
algebra
Used in SQL recursion
Logical rules form the basis for many
information integration systems and
applications
Meaning of Rules
Head is true of its arguments if there exist values for
local variables those in body not in head that make all
of the subgoals true
If no negation or arithmetic comparisons just natural
join the subgoals and project onto the head variables
Terminology
Variable
A variable is like a variable in a mathematical
equation, it represents some constant that has yet to
be determined.
By convention variables always start with an upper
case letter, e.g., City, Firstname,Code, A, B, C, etc
Constant
A constant is an attribute value. By convention all
constants begin with lower-case letters such as:
sammy, joe, xxy2003, etc
fact
A fact is the same things a tuple in a relation. A fact
has the following structure. (called Ground facts,
because there are no variables)
<predicate name>(<list of constants>)
Example: Facts about student enrollment:
The following set of facts shows some students
and the subjects in which they are enrolled.
enrolledIn(joe, cp2001)
enrolledIn(sue, cp2001)
enrolledIn(joe, cp2003).
In relational database terms, it would be the same
as the following relation. enrolledIn
Rules
A rule is a way to derive new facts. It is part of a query.
Name Phone
joe 408-489-
5454
enrolledIn
Name Code
joe CP2004
sue CP2001
joe CP2003
Result:
result(joe, CP2004, 408-489-5454)
result(joe, CP2003, 408-489-5454)
Safety
It may be possible to write rules that generate an an
infinite number of answers. For example:
employee(X,Y) :- X>Y
Since the relation defining > is infinite, this rule would
generate an infinite number of facts for the relation
employee. Also the use of negation can cause similar
problems. For example:
not-in-loan(L, B, A) :- not loan(L, B, A)
We want to retrieve all tuples that are not in the loan
relation but if account numbers, branch-name and
balance is infinite then the relation not-in-loan would
also be infinite.
To avoid such problems Datalog rules are required to
satisfy the following safety conditions:
1. Every variable that appears in the head of the rule
also appears in a nonarithmetic positive literal in the
body of the rule
2. Every variable appearing in a negative literal in the
body of the rule also appears in some positive literal in
the body of the rule.
Recursion in Datalog
Suppose now that we want to find out which
employees are supervised, directly or indirectly by a
given manager, "Jones".
(1) People whose manager is "Jones"
(2) People whose manager is supervised by "Jones"
Ex. Tim manager is Jones
Kelly manager is Tim
employee-jones(X) :- manager(X, "Jones")
employee-jones(X) :- manager(X,Y), employee-jones(Y)
Procedure
I = set of facts in the database
repeat
Old_I = I
I = I U infer( R, I)
until I = Old_I
employee-jones(X) :- manager(X, "Jones")
employee-jones(X) :- manager(X,Y), employee-jonesY
Manager relation
employee- manager-
name name
Alon Barinsky
Barinsky Estovar
Corbin Duarte
Duarte Jones
Estovar Jones
Jones Klinger
Rensal Klinger
Iteration Tuples in
employee-
jones
1 (Duarte),
(Estovar)
2 (Duarte),
(Estovar),
(Barinsky),
(Corbin)
3 (Duarte),
(Estovar),
(Barinsky),
(Corbin),
(Alon)
4 (Duarte),
(Estovar),
(Barinsky),
(Corbin),
(Alon)
Recursive Rules
movie sequel
Rocky Rocky II
Rocky
Rocky II III
Rocky
Rocky III IV
At the first round of computation, FollowOn is
assumed empty. Thus, rule (2) cannot yield any
FollowOn tuples. However, rule (1) says that every
SequelOf tuple is a FollowOn tuple. Thus, after the first
round, the value of FollowOn is identical to the
SequelOf relation above.
In the second round, we use the relation as FollowOn
and apply the two rules to this relation and the given
SequelOf relation. The first rule gives us the three
tuples that we already have, and in fact it is easy to see
that rule (1) will never yield any tuples for FollowOn
other than these three. For rule (2), we look for a
tuple from SequelOf whose second component equals
the first component of a tuple from FollowOn.
Thus, we can take the tuple (Rocky; Rocky II) from
SequelOf and pair it with the tuple (Rocky II; Rocky
III) from FollowOn to get the new tuple (Rocky; Rocky
III) for FollowOn. Similarly, we can take the tuple
(Rocky II; Rocky III)
Rocky Rocky II
Rocky
Rocky II III
Rocky
Rocky III IV
xy
Rocky Rocky II
Rocky
Rocky II III
Rocky
Rocky III IV
Rocky
Rocky III
Rocky
Rocky II IV
Rocky Rocky II
Rocky
Rocky II III
Rocky
Rocky III IV
Rocky
Rocky III
Rocky
Rocky II IV
Rocky
Rocky IV
1. FollowOn(x,y) SequelOf(x,y)
1. FollowOn(x,y) SequelOf(x,y)
2)
Many examples of the use of recursion can be found in
a study of paths in a graph. Figure 10.2 shows a
relation representing some flights of two hypothetical
airlines | United Airlines (UA), and Arrow Airlines
(AA) | among the cities San Francisco, Denver, Dallas,
Chicago, and New York.
Flights(airline, from, to, departs, arrives)
Reaches(x,y) Flights(a,x,y,d,r)
3)
A more complicated problem when two flights can be
combined into a longer sequence of flights is to
require that the second leaves an airport at least an
hour after the first arrives at that airport. Now, we use
an IDB predicate, which we shall call Connects(x,y,d,r),
that says we can take one or more flights, starting at
city x at time d and arriving at city y at time r. If there
are any connections, then there is at least an hour to
make the connection.
The rules for Connects are
1. Connects(x,y,d,r) Flights(a,x,y,d,r)
Connects(z,y,t2,r) AND
t1 <= t2 – 100
SF NY 900 2130
SF NY 900 2200
SF NY 930 2200
AN NO
1. P(x) R(x) D T Q(x)
AN NO
2. Q(x) R(x) D T P(x)
a)P = f(0)g Q =R ;
b) P = ;R Q = f(0)g
Both are minimal, in the sense that if we throw any tuple out of any
relation, the resulting relations no longer satisfy the rules. We cannot,
therefore, decide between the two least endpoints (a) and (b), so we cannot
answer a simple question such as \Is P (0)
We saw that our idea of defining the meaning of recursive rules by finding
the least endpoint no longer works when recursion and negation are
tangled up too intimately. There can be more than one least endpoint, and
these endpoints can contradict each other. It would be good if some other
approach to defining the meaning of recursive negation would work better
AA reaches
UA reaches
Related Works
[1] Faiz Arni, KayLiang Ong, Shalom Tsur, Haixun
Wang, and Carlo Zaniolo. The Deductive Database
System LDL++.
Describes the execution model and the open architecture
designed to integrate with existing DBMS and it’s
applications