Magic sets and other strange ways to implement logic programs (extended abstract)

Several methods for implementing database queries expressed as logical rules are given and they are compared for efficiency. One method, called “magic sets,” is a general algorithm for rewriting logical rules so that they may be implemented bottomUP (= forward chaining) in a way that cuts down on the irrelevant facts that are generated. The advantage of this scheme is that by working bottom-up, we can take advantage of efficient methods for doing massive joins. Two other methods are ad hoc ways of implementing “linear” rules, i.e., rules where at most one predicate in any body is recursive. These methods are 1 Work supported by NSF grant IST-83-51730, cosponsored by Tektronix Foundation, Intel, Mentor Graphics, DEC, Servio Logic Corp., IBM, Xerox and Beaverton Chamber of Commerce. 20n a leave of absence from Hebrew University. Work supported by a grant of AT&T Foundation and a grant of IBM Corp. SWork supported by NSF grant IST-84-12791 and a grant of IBM Corp. Permission to copy without lee all or part of this material is granted provided Out the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publi&on and its date appear. and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise..or to republish, rquim a fee and/or specific permission.