Professional Documents
Culture Documents
Glue-Nail: A Deductive Database System
Glue-Nail: A Deductive Database System
It often happens that we want to nd the \aggregate" The third subgoal joins the T and MinT columns, hence
value of a set of tuples, for example the minimum value the only tuples left in the supplementary relation after
of a particular attribute. In the version of Glue de- this subgoal are those with minimal temperatures. For
scribed so far, the value of a tuple in a supplementary example:
relation is independent of all the other tuples. This is
not true for statements containing aggregate operators. sup1
Here the values of tuples typically do depend on each Name T
other. San Francisco 12
The aggregate operators (aggregators) available in Madang 36
Glue are: min, max, mean, sum, product, arbitrary, Copenhagen -2
std dev (standard deviation), and count. These op- sup2
erators take a single bound term as an argument, and Name T MinT
return a single value. The operator arbitrary returns San Francisco 12 -2
a single arbitrary value from the binding set of the argu- Madang 36 -2
ment term, the other operators have their usual mean- Copenhagen -2 -2
ings. A simple example: sup3
The second attribute of dept employees relation is a There is no automatic need for set unication in
set valued attribute, it holds the name of the predicate Glue-Nail; if two set valued attributes contain the same
which holds the employees in the toy department. predicate name, then the two sets are identical. Hence
Although the syntax is second order, the semantics much of the time a simple string-string matching suf-
is rst order. Predicate variables can only range over ces to determine equality. Of course, there will be
predicate names, not over all predicate extensions (val- times when the programmer needs to test whether two
ues). This distinction is important, because the set dierently named sets have the same members. Here is
of predicate names is always nite, whereas the set a small procedure which compares two sets S and T.
of possible predicates is innite. The scoping rules of proc set_eq( S, T: )
Glue's modules and procedures give the compiler a list rels different(S,T);
of the predicates which a subgoal variable could possi- different(S,T):= in(S,T) & S(X) & !T(X).
bly match, so much of the predicate selection analysis different(S,T)+= in(S,T) & T(X) & !S(X).
can be done at compile time. return(S,T:):= !different(S,T).
Here is an example set denition in Glue: end
The predicate class info contains information about Our example in Section 4 could have taken e as a for-
a class: its identifying code, instructor, set of TA's mal argument, thus allowing us to write one universal
(Teaching Assistants), and set of students. The pred- transitive closure predicate.
icate tas(ID) denes the TA's for a course, notably
those graduate students who failed the graduate qual-
ifying exam in the course's subject area. Observe 6 Modules
that the name of this predicate is a compound term. Both logic programming and deductive database lan-
The predicate students(ID) contains the names of guages have had problems \programming in the large,"
the students who are taking the course ID. The predi- partly due to their lack of large scale code organization
cates class instructor, class room, class subject, structures. Hence, in common with several other lan-
failed exam, and attends are dened elsewhere. Here
guages, Glue-Nail has a module system. Modules are
is an example EDB: purely a compile time concept, they do not have any
class_instructor( cs99, smith ). run time semantics. Besides oering the usual advan-
class_room( cs99, mjh460a ). tages of separate compilation, modularity etc; modules
class_subject( cs99, databases ). give the Glue compiler valuable information concern-
failed_exam( jones, databases ). ing which predicates are visible at any point in a pro-
attends( wilson, cs99 ). gram. This information can be used to perform much
attends( green, cs99 ). of the predicate dereferencing at compile time, work
which would otherwise have to be done at run time.
It implies the following IDB tuples: This is especially true for subgoals which use predicate
variables.
class_info( cs99, smith, mjh460a,
Modules have:
tas(cs99), students(cs99)).
tas(cs99)( jones ). a name,
a list of imported EDB predicates,
a list of imported IDB predicates,
a list of exported IDB predicates, and
IDB predicate code, both for Glue procedures and
NAIL! rules.
Notice that a module can contain both Glue proce- module example;
dures and NAIL rules, thus allowing the programmer export select(:Key);
to group predicates by function, rather than by type. from windows import event( :Type, Data );
from graphics import