On the power of magic

Catriel Beeri, Raghu Ramakrishnan
1991 The Journal of Logic Programming  
This paper considers the efficient evaluation of recursive queries expressed using Horn clauses. We define sideways information passing formally and show how a query evaluation algorithm may be defined in terms of sideways information passing and control. We then consider a class of information-passing strategies that suffices to describe most query evaluation algorithms in the database literature, and show that these strategies may always be implemented by rewriting a given program and
more » ... ng the rewritten program bottom-up. We describe in detail several algorithms for rewriting a program. These algorithms generalize the counting and magic-sets algorithms to work with arbitrary programs. Safety and optimality of the algorithms are also considered. a anc(X,Y):-par(X,Y) anc(X, Y 1 :-pa&X, 23, anc(Z, Y 1 and let the query be Query : anc( john , Y ) ? Assume that a database contains a parenthood relation par. Then the program defines a derived relation describing ancestors, and the query asks for the ances-
doi:10.1016/0743-1066(91)90038-q fatcat:zvduh4pqmbb7tmhxt4xjxirasi