de.fuberlin.wiwiss.d2rq.algebra
Class JoinOptimizer

java.lang.Object
  extended by de.fuberlin.wiwiss.d2rq.algebra.JoinOptimizer

public class JoinOptimizer
extends Object

Removes unnecessary joins from an RDFRelation in cases where this is possible without affecting the result. This is an optimization.

A join J from table T1 to table T2 with join condition T1.c_1 = T2.c_1 && T1.c_2 = T2.c_2 && ... can be removed if these conditions hold:

  1. The only join mentioning T2 is J.
  2. All columns of T2 that are selected or constrained or used in an expression occur in J's join condition.
  3. All values of T1.c_n are guaranteed to occur in T2.c_n, that is, there is a foreign key constraint on T1.c_n.

In this case, J can be dropped, and all mentions of T2.c_n can be replaced with T1.c_n.

TODO: Note: The third condition is currently not enforced. This is not a problem in most situations, because d2rq:join is typically used along an FK constraint. At this point in the code, we don't know the direction of the FK though. The way 1:n and n:m joins are typically used, condition 2 will exclude most cases where the FK is on T2.c_n. However, it will not catch cases that result from a d2rq:join on a d2rq:ClassMap along an 1:1 relation. This should be considered a bug. TODO: Prune unnecessary aliases after removing joins

Version:
$Id: JoinOptimizer.java,v 1.11 2006/09/28 12:17:44 cyganiak Exp $
Author:
Richard Cyganiak (richard@cyganiak.de)

Constructor Summary
JoinOptimizer(RDFRelation base)
          Constructs a new JoinOptimizer.
 
Method Summary
 RDFRelation optimize()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JoinOptimizer

public JoinOptimizer(RDFRelation base)
Constructs a new JoinOptimizer.

Parameters:
base - The RDFRelation to be optimized
Method Detail

optimize

public RDFRelation optimize()