saffron.rel
Class QueryInfo

java.lang.Object
  |
  +--saffron.rel.QueryInfo

class QueryInfo
extends Object

A QueryInfo holds all the information about a QueryExpression while it is being translated into a collection of Rels.

Those Rels will all belong to the same Cluster, but Cluster is much simpler. Please put the stuff which is only needed at translation time into QueryInfo, and keep Cluster simple.


Field Summary
(package private)  Cluster cluster
           
(package private)  Environment env
           
(package private)  SaffronQueryExpander expander
           
(package private)  ArrayList leaves
           
(package private)  QueryInfo parent
           
private  Rel root
           
 
Constructor Summary
(package private) QueryInfo(QueryInfo parent, Environment env, SaffronQueryExpander expander, Expression exp)
          Creates a QueryInfo
 
Method Summary
 Expression convertExpToInternal(Expression exp)
          Translates an expression into one which references only internal variables.
 Expression convertExpToInternal(Expression exp, Rel[] inputs)
           
(package private)  Rel convertFromExpToRel(Expression exp)
          Converts an expression into a relational expression.
 Expression convertGroupExpToInternal(Expression exp, Expression[] groups, ExpressionList aggInputList, Vector aggCallVector)
          Translates an aggregate expression into one which references only variables.
(package private)  Rel convertQueryToRel(QueryExpression queryExp)
          Converts a QueryExpression into a Rel.
(package private)  int countColumns(Rel rel)
          Returns the number of columns in this input.
(package private) static Cluster createCluster(QueryInfo queryInfo, Environment env, Expression exp)
           
private  Rel findLeaf(Rel rel, int count, int[] seen, ArrayList path, int depth)
          Returns the countth leaf (Rel which implements a from-list item) below this one.
(package private)  Rel getRoot()
           
(package private)  Expression lookup(int offset, Rel[] inputs, boolean foo, String varName)
          Creates an expression with which to reference expression, whose offset in its from-list is offset.
(package private)  Expression lookup(int offset, Rel input, boolean foo, String varName)
           
(package private)  Expression removeSubqueries(Expression exp)
          Goes through an expression looking for sub-queries (in or exists).
(package private)  void setRoot(Rel root)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

QueryInfo parent

env

Environment env

expander

SaffronQueryExpander expander

leaves

ArrayList leaves

cluster

Cluster cluster

root

private Rel root
Constructor Detail

QueryInfo

QueryInfo(QueryInfo parent,
          Environment env,
          SaffronQueryExpander expander,
          Expression exp)
Creates a QueryInfo

Parameters:
env - environment of the query that this expression was contained in - gives us access to the from list of that query
Method Detail

createCluster

static Cluster createCluster(QueryInfo queryInfo,
                             Environment env,
                             Expression exp)

getRoot

Rel getRoot()

setRoot

void setRoot(Rel root)

convertExpToInternal

public Expression convertExpToInternal(Expression exp)
Translates an expression into one which references only internal variables. Clones the expression first.

Parameters:
exp - expression to translate
Returns:
converted expression

convertExpToInternal

public Expression convertExpToInternal(Expression exp,
                                       Rel[] inputs)

convertGroupExpToInternal

public Expression convertGroupExpToInternal(Expression exp,
                                            Expression[] groups,
                                            ExpressionList aggInputList,
                                            Vector aggCallVector)
Translates an aggregate expression into one which references only variables. Expressions inside aggregate functions are added to aggList, if they are not already present.

Parameters:
exp - expression to translate
groups - expressions from the group by clause
aggInputList - expressions inside aggregations; expressions are added to this list if an aggregate needs one and it is not present
aggCallVector - calls to aggregates; Aggregate.Calls are added to this list if they are needed but are not present

findLeaf

private Rel findLeaf(Rel rel,
                     int count,
                     int[] seen,
                     ArrayList path,
                     int depth)
Returns the countth leaf (Rel which implements a from-list item) below this one.

Parameters:
rel - relation to start from
count - leaf number we want
seen - seen[0] contains the number of leaves we have seen so far
path - List containing the rel at each depth
depth - Current depth

countColumns

int countColumns(Rel rel)
Returns the number of columns in this input.


lookup

Expression lookup(int offset,
                  Rel[] inputs,
                  boolean foo,
                  String varName)
Creates an expression with which to reference expression, whose offset in its from-list is offset.


lookup

Expression lookup(int offset,
                  Rel input,
                  boolean foo,
                  String varName)

convertQueryToRel

Rel convertQueryToRel(QueryExpression queryExp)
Converts a QueryExpression into a Rel. Capture occurs when a query is converted into relational expressions. The scalar expressions in the query reference (a) rows from their own query, (b) rows from an enclosing query, (c) variables from the enclosing environment. We have already dealt with (a), and we can leave environmental references (c) as they are. So, we deal with references to rows in this query now. References to queries inside or outside this query will happen in due course.


convertFromExpToRel

Rel convertFromExpToRel(Expression exp)
Converts an expression into a relational expression. For example, an array becomes an ExpressionReader. Leaf nodes are registered in leaves.

Parameters:
exp - the expression to convert
Returns:
the equivalent relational expression

removeSubqueries

Expression removeSubqueries(Expression exp)
Goes through an expression looking for sub-queries (in or exists). If it finds one, it joins the query to the from clause, replaces the condition, and returns true. Examples:
  • exists becomes a reference to a indicator query:
    select from dept
     where dept.location.equals("SF") && exists (
       select from emp
       where emp.deptno == dept.deptno && emp.gender.equals("F"))
    becomes
    select from dept cross join (
       select distinct from emp
       where emp.deptno == dept.deptno && emp.gender.equals("F"))
     where dept.location.equals("SF") && indicator != null

    The reference to 'dept' from within a join query is illegal -- but we haven't de-correlated yet.

  • in becomes a test to see whether an outer-joined query met the join condition:
    select from emp
     where emp.deptno in (
       select dept.deptno from dept where dept.location.equals("SF"))
     && emp.gender.equals("F")
    becomes
    select from emp left join (
       select dept.deptno from dept where dept.location.equals("SF")) q1
     on emp.deptno == q1.deptno
     where q1 is not null && emp.gender.equals("F")
    Optimization #1: If the in condition is &&ed into the where clause, then make the join into a full join, and omit the condition. Hence,
    select from emp join (
       select dept.deptno from dept where dept.location.equals("SF")) q1
     on emp.deptno == q1.deptno
     where emp.gender.equals("F")

Parameters:
exp - Expression
Returns:
expression with subqueries removed

SourceForge.net_Logo