A nonrecursive system is any database system whose query language does not support recursive queries. Thus, many existing commerical SQL database systems are nonrecursive systems. Query optimization is an important issue for nonrecursive queries, and the magic-sets transformation has been shown to improve the performance of nonrecursive queries by many orders of magnitude [MFPR90]. It is thus important to use the magic-sets transformation in nonrecursive systems.
However, there is a problem. The magic-sets optimization can transform a nonrecursive query into a recursive query. Since a recursive query cannot be executed by a nonrecursive system, such a transformation is fatal. The magic-sets transformation cannot therefore be used in nonrecursive systems.
In this paper we present algorithms that achieve the optimization of the magic-sets transformation while guaranteeing that the transformed program will be nonrecursive whenever the original program is nonrecursive. The algorithms can be extended to the supplementary magic-sets transformation. We also define a new optimization technique for recursive and nonrecursive queries, covered subgoal elimination, that can eliminate subgoals from a rule, and can sometimes convert a recursive query into a nonrecursive one.
The algorithms presented in this paper are of practical relevance since they make it possible to incorporate the magic-sets transformation into existing commercial database systems.
[1]
John C. Shepherdson,et al.
Unfold/fold transformations of logic programs
,
1992,
Mathematical Structures in Computer Science.
[2]
Jeffrey F. Naughton,et al.
Data independent recursion in deductive databases
,
1985,
J. Comput. Syst. Sci..
[3]
Jeffrey D. Uuman.
Principles of database and knowledge- base systems
,
1989
.
[4]
Hamid Pirahesh,et al.
Magic is relevant
,
1990,
SIGMOD '90.
[5]
Catriel Beeri,et al.
On the power of magic
,
1987,
J. Log. Program..
[6]
Divesh Srivastava,et al.
Magic Sets and Bottom-Up Evaluation of Well-Founded Models
,
1991,
ISLP.
[7]
Inderpal Singh Mumick.
Query Optimization in Deductive and Relational Databases
,
1991
.
[8]
Divesh Srivastava,et al.
Rule Ordering in Bottom-Up Fixpoint Evaluation of Logic Programs
,
1990,
IEEE Trans. Knowl. Data Eng..
[9]
Jeffrey D. Ullman,et al.
Principles Of Database And Knowledge-Base Systems
,
1979
.
[10]
K. A. Ross.
Modular stratification and magic sets for DATALOG programs with negation
,
1990,
PODS 1990.
[11]
Hamid Pirahesh,et al.
The Magic of Duplicates and Aggregates
,
1990,
VLDB.
[12]
Jeffrey D. Ullman,et al.
Principles of Database and Knowledge-Base Systems, Volume II
,
1988,
Principles of computer science series.