Magic Sets vs. SLD-Resolution

  • Stefan Brass
Conference paper
Part of the Workshops in Computing book series (WORKSHOPS COMP.)


It is by now folklore that the bottom-up evaluation of a program after the “magic set” transformation is “as efficient as” top-down evaluation. There are a number of formalizations of this in the literature. However, the naive formalization is false: As shown by Ross, SLD-resolution can be much more efficient than bottom-up evaluation with magic sets on tail-recursive programs.

We show that this happens only for tail-recursive programs, and that the only problem of magic sets is the materialization of “lemmas”. So magic sets are always “as goal-directed as” SLD-resolution. These results are not surprising, but we believe that the variants given here are especially useful for teaching purposes. We also give rather simple proofs.

Furthermore, we demonstrate that SLD-resolution can be directly simulated by bottom-up evaluable programs if all recursions are tail-recursive. This is based on the meta-interpreter approach of Bry and seems to be very promising.


Logic Program Transitive Closure Node Type Query Evaluation Query Path 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [1]
    F. Bancilhon and Ft. Ramakrishnan. An amateur’s introduction to recursive query processing. In C. Zaniolo, editor, Proc. of SIGMOD’86, pages 16–52, 1986.Google Scholar
  2. [2]
    S. Brass and J. Dix. A general approach to bottom-up computation of disjunctive semantics. In J. Dix, L. M. Pereira, and T. Przymusinski, editors, Nonmonotonic Extensions of Logic Programming, number 927 in LNAI, pages 127–155. Springer, 1995.CrossRefGoogle Scholar
  3. [3]
    F. Bry. Query evaluation in recursive databases: bottom-up and top-down reconciled. Data & Knowledge Engineering, 5:289–312, 1990.CrossRefGoogle Scholar
  4. [4]
    S. Greco and C. Zaniolo. Optimization of linear logic programs using counting methods. In A. Pirotte, C. Delobel, and G. Gottlob, editors, Advances in Database TechnologyEDBT’92, 3rd Int. Conf., number 580 in LNCS, pages 72–87. Springer-Verlag, 1992.Google Scholar
  5. [5]
    L. Kalinichenko and V. Zadorozhny. A generalized information resource query language and basic query evaluation technique. In C. Delobel, M. Kifer, and Y. Masunaga, editors, Deductive and Object-Oriented Databases, 2nd Int. Conf. (DOOD’91), number 566 in LNCS, pages 547–566. Springer, 1991.Google Scholar
  6. [6]
    D. B. Kemp, K. Ramamohanarao, and Z. Somogyi. Right-, left- and multi-linear rule transformations that maintain context information. In D. McLeod, R. Sacks-Davis, and H. Schek, editors, Proc. Very Large Data Bases, 16th Int. Conf. (VLDB’90), pages 380–391. Morgan Kaufmann Publishers, 1990.Google Scholar
  7. [7]
    R. Ramakrishnan, D. Srivastava, S. Sudarshan, and P. Seshadri. The CORAL deductive system. The VLDB Journal, 3:161–210, 1994.CrossRefGoogle Scholar
  8. [8]
    R. Ramakrishnan and S. Sudarshan. Top-down vs. bottom-up revisited. In V. Saraswat and K. Ueda, editors, Proc. of the 1991 Int. Symposium on Logic Programming, pages 321–336. MIT Press, 1991.Google Scholar
  9. [9]
    K. Ramamohanarao. An implementation overview of the Aditi deductive database system. In S. Ceri, K. Tanaka, and S. Tsur, editors, Deductive and Object-Oriented Databases, Third Int. Conf, (DOOD’93), number 760 in LNCS, pages 184–203. Springer, 1993.Google Scholar
  10. [10]
    K. A. Ross. Modular acyclicity and tail recursion in logic programs. In Proc. of the Tenth ACM SIGACT-SIGMOD-SIGART Symp. on Princ. of Database Systems (PODS y 91), pages 92–101, 1991.CrossRefGoogle Scholar
  11. [11]
    Y. Sagiv. Is there anything better than magic? In S. Debray and M. Hermenegildo, editors, Proc. of the North American Conf. on Logic Programming, pages 235–254. MIT Press, 1990.Google Scholar
  12. [12]
    K. Sagonas, T. Swift, and D. S. Warren. XSB as an efficient deductive database engine. In R. T. Snodgrass and M. Winslett, editors, Proc. of the 1994 ACM SIGMOD Int. Conf on Management of Data (SIGMOD’94), pages 442–453, 1994.CrossRefGoogle Scholar
  13. [13]
    H. Seki. On the power of Alexander templates. In Proc. of the Eighth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems (PODS’89), pages 150–159, 1989.CrossRefGoogle Scholar
  14. [14]
    J. D. Ullman. Bottom-up beats top-down for Datalog. In Proc. of the Eighth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems (PODS’89), pages 140–149, 1989.CrossRefGoogle Scholar
  15. [15]
    J. D. Ullman. Principles of Database and Knowledge-Base Systems, Vol. 2. Computer Science Press, 1989.Google Scholar

Copyright information

© British Computer Society 1996

Authors and Affiliations

  • Stefan Brass
    • 1
  1. 1.Institut für InformatikUniversität HannoverHannoverFed. Rep. Germany

Personalised recommendations