Cost-based optimization for magic: algebra and implementation

Magic sets rewriting is a well-known optimization heuristic for complex decision-support queries. There can be many variants of this rewriting even for a single query, which differ greatly in execution performance. We propose cost-based techniques for selecting an efficient variant from the many choices.Our first contribution is a practical scheme that models magic sets rewriting as a special join method that can be added to any cost-based query optimizer. We derive cost formulas that allow an optimizer to choose the best variant of the rewriting and to decide whether it is beneficial. The order of complexity of the optimization process is preserved by limiting the search space in a reasonable manner. We have implemented this technique in IBM's DB2 C/S V2 database system. Our performance measurements demonstrate that the cost-based magic optimization technique performs well, and that without it, several poor decisions could be made.Our second contribution is a formal algebraic model of magic sets rewriting, based on an extension of the multiset relational algebra, which cleanly defines the search space and can be used in a rule-based optimizer. We introduce the multiset θ-semijoin operator, and derive equivalence rules involving this operator. We demonstrate that magic sets rewriting for non-recursive SQL queries can be modeled as a sequential composition of these equivalence rules.

[1]  J. W. Jenkins,et al.  THE UNIVERSITY OF WISCONSIN. , 1905, Science.

[2]  Burton H. Bloom,et al.  Space/time trade-offs in hash coding with allowable errors , 1970, CACM.

[3]  S. B. Yao,et al.  Approximating block accesses in database organizations , 1977, CACM.

[4]  Patricia G. Selinger,et al.  Access path selection in a relational database management system , 1979, SIGMOD '79.

[5]  Eugene Wong,et al.  Query processing in a system for distributed databases (SDD-1) , 1981, TODS.

[6]  Anthony C. Klug Equivalence of Relational Algebra and Relational Calculus Query Languages Having Aggregate Functions , 1982, JACM.

[7]  Randy H. Katz,et al.  An extended relational algebra with control over duplicate elimination , 1982, PODS.

[8]  Toshihide Ibaraki,et al.  On the optimal nesting order for computing N-relational joins , 1984, TODS.

[9]  Georg Gottlob,et al.  Translating SQL Into Relational Algebra: Optimization, Semantics, and Equivalence of SQL Queries , 1985, IEEE Transactions on Software Engineering.

[10]  Dean Daniels,et al.  Query Processing in R* , 1985, Query Processing in Database Systems.

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

[12]  Carlo Zaniolo,et al.  Optimization of Nonrecursive Queries , 1986, VLDB.

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

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

[15]  Ramez Elmasri,et al.  Fundamentals of Database Systems , 1989 .

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

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

[18]  Hamid Pirahesh,et al.  Starburst Mid-Flight: As the Dust Clears , 1990, IEEE Trans. Knowl. Data Eng..

[19]  Goetz Graefe,et al.  The Volcano optimizer generator: extensibility and efficient search , 1993, Proceedings of IEEE 9th International Conference on Data Engineering.

[20]  Jeffrey F. Naughton,et al.  Efficient Sampling Strategies for Relational Database Operations , 1993, Theor. Comput. Sci..

[21]  Peter J. Stuckey,et al.  Compiling query constraints , 1994, ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems.

[22]  Peter J. Stuckey,et al.  Compiling query constraints (extended abstract) , 1994, PODS.

[23]  Hamid Pirahesh,et al.  Implementation of magic-sets in a relational database system , 1994, SIGMOD '94.

[24]  Joseph M. Hellerstein,et al.  Optimization and Execution Techniques for Queries With Expensive Methods , 1996, Technical Report / University of Wisconsin, Madison / Computer Sciences Department.

[25]  Hamid Pirahesh,et al.  Complex query decorrelation , 1996, Proceedings of the Twelfth International Conference on Data Engineering.

[26]  Timos K. Sellis,et al.  Parametric query optimization , 1992, The VLDB Journal.