An analysis of magic sets and related optimization strategies for logic queries

We analyze the optimization effect of the “magic sets” rewriting technique for datalog queries and present some supplementary or alternative techniques that avoid many shortcomings of the basic technique. Given a magic sets rewritten query, the set of facts generated for the original, nonmagic predicates by the seminaive bottom-up evaluation is characterized precisely. It is shown that—because of the additional magic facts—magic sets processing may result in generating an order of magnitude more facts than the straightforward naive evaluation. A refinement of magic sets in factorized magic sets is defined. These magic sets retain most of the efficiency of original magic sets in regards to the number of nonmagic facts generated and have the property that a linear-time bound with respect to seminaive evaluation is guaranteed in all cases. An alternative technique for magic sets, called envelopes, which has several desirable properties over magic sets, is introduced. Envelope predicates are never recursive with the original predicates; thus, envelopes can be computed as a preprocessing task. Envelopes also allow the utilization of multiple sideways information passing strategies (sips) for a rule. An envelope-transformed program may be “readorned” according to another choice of sips and reoptimized by magic sets (or envelopes), thus making possible an optimization effect that cannot be achieved by magic sets based on a particular choice of sips.

[1]  Yehoshua Sagiv,et al.  Is There Anything Better than Magic? , 1990, NACLP.

[2]  Hamid Pirahesh,et al.  Magic is relevant , 1990, SIGMOD '90.

[3]  Catriel Beeri,et al.  On the power of magic , 1987, J. Log. Program..

[4]  Jeffrey F. Naughton,et al.  One-sided recursions , 1987, J. Comput. Syst. Sci..

[5]  Allen Van Gelder,et al.  A message passing framework for logical query evaluation , 1986, SIGMOD '86.

[6]  Eljas Soisalon-Soininen,et al.  Multiple SIP Strategies and Bottom-Up Adorning in Logic Query Optimization , 1990, ICDT.

[7]  Raghu Ramakrishnan,et al.  Magic Templates: A Spellbinding Approach To Logic Programs , 1991, J. Log. Program..

[8]  David Maier,et al.  Magic sets and other strange ways to implement logic programs (extended abstract) , 1985, PODS '86.

[9]  Jeffrey D. Ullman,et al.  Bottom-up beats top-down for datalog , 1989, PODS '89.

[10]  Jeffrey D. Ullman,et al.  Implementation of logical query languages for databases , 1985, TODS.

[11]  François Bancilhon,et al.  Naive Evaluation of Recursively Defined Relations , 1986, On Knowledge Base Management Systems.

[12]  Catriel Beeri,et al.  On the power of magic , 1987, PODS '87.

[13]  Jeffrey D. Uuman Principles of database and knowledge- base systems , 1989 .

[14]  Hirohisa Seki,et al.  On the power of Alexander templates , 1989, PODS.

[15]  Jeffrey D. Ullman,et al.  Principles of database and knowledge-base systems, Vol. I , 1988 .

[16]  Eljas Soisalon-Soininen,et al.  An optimization strategy for recursive queries in logic databases , 1988, Proceedings. Fourth International Conference on Data Engineering.

[17]  Hamid Pirahesh,et al.  Magic conditions , 1990, PODS.

[18]  Inderpal Singh Mumick,et al.  Magic-sets transformation in nonrecursive systems , 1992, PODS '92.

[19]  Hamid Pirahesh,et al.  The Magic of Duplicates and Aggregates , 1990, VLDB.