Magic Sets for Disjunctive Datalog Programs Mario Alviano, Wolfgang Faber, Gianluigi Greco, Nicola Leone {alviano,faber,greco,leone}@mat.unical.it Department of Mathematics, University of Calabria 87036 Rende, Italy MAT Technical Report 09/2009 November 2009 Abstract In this paper, a new technique for the optimization of (partially) bound queries over disjunctive Datalog programs with stratified negation is pre- sented. The technique exploits the propagation of query bindings and extends the Magic Set optimization technique (originally defined for non- disjunctive programs). An important feature of disjunctive Datalog programs is nonmono- tonicity, which calls for nondeterministic implementations, such as back- tracking search. A distinguishing feature of the new method is that the optimization can be exploited during the nondeterministic phase. In par- ticular, after some assumptions have been made, parts of the program may become irrelevant to a query under these assumptions. This allows for dynamic pruning of the search space. In contrast, the effect of the only previously defined Magic Set method for disjunctive Datalog (APM) is limited to the deterministic portion of the process. In this way the proposed method allows for exponential performance gains with respect to APM, which could also be confirmed empirically. The correctness of the method is established and proved in a formal way, in which the strong relationship between magic sets and unfounded sets is exploited, which has not been studied in the literature before. This knowledge allows for extending the method and the correctness proof also to programs with stratified negation in a clean and founded way. The proposed method has been implemented in the DLV system and various experiments on synthetic as well as on real-world data have been conducted. The experimental results on synthetic data confirm the utility of Magic Sets for disjunctive Datalog, and they highlight the computa- tional gain that may be obtained by the new method with respect to the previously proposed Magic Set method APM for disjunctive Datalog pro- grams. Further experiments on data taken from a real-life application show the benefits of the Magic Set method within an application scenario that has received considerable attention in recent years, the problem of answering user queries over possibly inconsistent databases originating from integration of autonomous sources. 1