public class PlanBuilder
extends java.lang.Object
Constructor and Description |
---|
PlanBuilder(Catalog catalog,
StorageManager sm,
java.util.Map<java.lang.String,java.lang.String> parameters)
Constructs a new plan builder instance, given a catalog and
a storage manager.
|
Modifier and Type | Method and Description |
---|---|
protected java.util.List<InitialProjection> |
buildInitialProjections(java.util.List<Projection> projections,
java.util.List<Selection> selections,
java.util.List<Join> joins,
java.util.Set<java.lang.String> tables)
Given a list of projections, a list of selections and a list of
joins, return a vector of initial projections, i.e., the
projections that should be pushed down right above the scans.
|
Operator |
buildPlan(java.lang.String filename,
java.util.List<AlgebraicOperator> operators)
Given a collection of algebraic operators, construct the
evaluation plan and return its root.
|
protected java.util.List<RelationScan> |
buildScans(java.util.Set<java.lang.String> tables)
Given a set of tables, return a list of physical scan
operators.
|
protected int[] |
convertProjectionList(java.lang.Iterable<Variable> pl,
Relation rel)
Given an iterable collection of variables a relation, it
converts the collection into an array of slots.
|
protected Predicate |
convertQualification(Qualification q,
Operator op)
Converts a logical qualification to a physical predicate.
|
protected Predicate |
convertQualification(Qualification q,
Operator left,
Operator right)
Converts a qualification to a phyical predicate (used for joins).
|
protected java.lang.Comparable |
createComparable(java.lang.Class<?> type,
java.lang.String value)
Given a type and a value, it creates a comparable object for
use in the physical predicates.
|
protected PhysicalJoin |
createJoin(Operator left,
Operator right,
java.util.List<Join> joins)
Given two input operators and a collection of algebraic joins,
returns a physical join to evaluate them.
|
protected Predicate |
createJoinPredicate(Operator left,
Operator right,
Join join)
Builds a single join predicate over two sources.
|
protected java.util.List<Variable> |
createProjectionList(java.util.List<Projection> projections)
Given a list of projections, it collapses their projection
lists into a single one.
|
protected TupleSlotPointer |
createSlotPointer(Variable var,
Relation r)
Given a variable and a relation, it creates a slot pointer.
|
protected java.util.List<Operator> |
enumerateJoins(java.util.List<Join> joins,
java.util.List<Operator> branches)
Enumerates the joins between a collection of sub-plans.
|
protected java.util.List<Join> |
findJoins(Operator left,
Operator right,
java.util.List<Join> joins)
Given two operators and a collection of joins, return all joins
over the operators in a new vector.
|
protected java.util.Set<Variable> |
getAttributes(java.lang.String table,
java.util.List<? extends AlgebraicOperator> operators)
Given a table name and a list of algebraic operators,
return a projection list of all accessed attributes.
|
protected java.util.List<Group> |
getGroups(java.util.List<AlgebraicOperator> operators)
Given a list of algebraic operators, identify the groupings
and return them in a new list.
|
protected java.util.List<Join> |
getJoins(java.util.List<AlgebraicOperator> operators)
Given a list of algebraic operators, identify the joins
and return them in a new list.
|
protected java.util.List<Projection> |
getProjections(java.util.List<AlgebraicOperator> operators)
Given a list of algebraic operators, identify the projections
and return them in a new list.
|
protected InitialProjection |
getRelevantInitialProjection(java.util.List<InitialProjection> ips,
RelationScan rs)
Given a list of projections and a scan, return the relevant
projection.
|
protected java.util.List<Selection> |
getRelevantSelections(java.util.List<Selection> selections,
java.lang.String table)
Given a list of selections and a table name, identify the
relevant selections on that table.
|
protected java.util.List<Selection> |
getSelections(java.util.List<AlgebraicOperator> operators)
Given a list of algebraic operators, identify the selections
and return them in a new list.
|
protected java.util.List<Sort> |
getSorts(java.util.List<AlgebraicOperator> operators)
Given a list of algebraic operators, identify the sorts
and return them in a new list.
|
protected java.util.Set<java.lang.String> |
getTables(java.util.List<AlgebraicOperator> operators)
Given a list of algebraic operators, return a set with the
names of all tables appearing in the operators.
|
protected java.util.Set<java.lang.String> |
getTables(Operator operator)
Given a physical operator, return a set with the names
of all tables participating in it.
|
protected Operator |
imposeFinalProjections(java.util.List<Projection> projections,
Operator operator)
Imposes the final result projection.
|
protected Operator |
imposeGroups(java.util.List<Group> groups,
Operator operator)
Imposes the final grouping.
|
protected java.util.List<Operator> |
imposeInitialProjections(java.util.List<InitialProjection> iProjections,
java.util.List<RelationScan> scans)
Imposes the initial projections over the scan operations.
|
protected java.util.List<Operator> |
imposeSelections(java.util.List<Selection> selections,
java.util.List<? extends Operator> sources)
Imposes the selections over execution branches.
|
protected Operator |
imposeSorts(java.util.List<Sort> sorts,
Operator operator)
Imposes the final sort.
|
protected boolean |
isMergeable(Join join)
Checks whether sort-merge can be used or not.
|
protected boolean |
joined(Operator left,
Operator right,
java.util.List<Join> joins)
Given two operators (sub-plans) and a list of joins, it checks
if the two operators are joined.
|
static void |
main(java.lang.String[] args)
Debug main
|
protected Triplet<Operator,Operator,java.util.List<Join>> |
pickPair(java.util.List<Join> joins,
java.util.List<Operator> sources)
Given a collection of algebraic joins and a collection
of sub-plans, it picks a pair of branches to join.
|
protected Qualification.Relationship |
reverseQR(Qualification.Relationship relationship) |
protected Condition.Qualification |
reverseRelationship(Qualification.Relationship relationship) |
protected Condition.Qualification |
translateRelationship(Qualification.Relationship relationship)
Translator from logical to physical qualifications.
|
public PlanBuilder(Catalog catalog, StorageManager sm, java.util.Map<java.lang.String,java.lang.String> parameters)
catalog
- the database catalog.sm
- the storage manager.parameters
- the server parameters.public Operator buildPlan(java.lang.String filename, java.util.List<AlgebraicOperator> operators) throws PlanBuilderException
operators
- the collection of algebraic operators.PlanBuilderException
- thrown whenever a plan cannot be
constructed.protected java.util.Set<java.lang.String> getTables(Operator operator) throws PlanBuilderException
operator
- the physical operatorPlanBuilderException
- whenever the tables cannot be
fetched.protected java.util.Set<java.lang.String> getTables(java.util.List<AlgebraicOperator> operators)
operators
- a list of algebraic operators.protected java.util.List<InitialProjection> buildInitialProjections(java.util.List<Projection> projections, java.util.List<Selection> selections, java.util.List<Join> joins, java.util.Set<java.lang.String> tables)
projections
- a list of algebraic projections.selections
- a list of algebraic selections.joins
- a list of algebraic joins.tables
- the set of tables names.protected java.util.Set<Variable> getAttributes(java.lang.String table, java.util.List<? extends AlgebraicOperator> operators)
table
- the table name.operators
- a list of algebraic operators.protected java.util.List<RelationScan> buildScans(java.util.Set<java.lang.String> tables) throws PlanBuilderException
tables
- a set of table names.PlanBuilderException
- thrown whenever the scans cannot
be constructed.protected java.util.List<Operator> imposeInitialProjections(java.util.List<InitialProjection> iProjections, java.util.List<RelationScan> scans) throws PlanBuilderException
iProjections
- the vector of initial projections.scans
- the vector of scan operators.PlanBuilderException
- thrown whenever the projections cannot
be imposed.protected InitialProjection getRelevantInitialProjection(java.util.List<InitialProjection> ips, RelationScan rs) throws PlanBuilderException
ips
- the list of initial projections.rs
- the relation scan.StorageManagerException
- thrown whenever the initial
projections cannot be identified.PlanBuilderException
protected java.util.List<Operator> imposeSelections(java.util.List<Selection> selections, java.util.List<? extends Operator> sources) throws PlanBuilderException
selections
- the list of selections.sources
- the incoming plan sources.PlanBuilderException
- thrown whenever the selections
cannot be imposed.protected java.util.List<Selection> getRelevantSelections(java.util.List<Selection> selections, java.lang.String table)
selections
- the list of selections.table
- a table name.protected int[] convertProjectionList(java.lang.Iterable<Variable> pl, Relation rel) throws PlanBuilderException
pl
- the projection list.rel
- the relation schema.PlanBuilderException
- thrown whenever the conversion cannot
be performed.protected Predicate convertQualification(Qualification q, Operator op) throws PlanBuilderException
q
- the qualification to be converted.op
- the incoming physical operator.PlanBuilderException
- thrown whenever the phyiscal
predicate cannot be constructed.protected Predicate convertQualification(Qualification q, Operator left, Operator right) throws PlanBuilderException
q
- the qualification to be converted.left
- the incoming left source.right
- the incoming right source.PlanBuilderException
- thrown whenever the predicate
cannot be constructed.protected TupleSlotPointer createSlotPointer(Variable var, Relation r)
var
- the variable to be converted.r
- the incoming relation.protected java.lang.Comparable createComparable(java.lang.Class<?> type, java.lang.String value) throws PlanBuilderException
type
- the type.value
- the value of the logical qualification.PlanBuilderException
- thrown whenever a comparable object
cannot be instantiated.protected Condition.Qualification translateRelationship(Qualification.Relationship relationship)
relationship
- the logical relationship between to values.protected Condition.Qualification reverseRelationship(Qualification.Relationship relationship)
protected Qualification.Relationship reverseQR(Qualification.Relationship relationship)
protected java.util.List<Operator> enumerateJoins(java.util.List<Join> joins, java.util.List<Operator> branches) throws PlanBuilderException
joins
- the logical joins to be enumerated.branches
- the incoming sub-plans (branches).PlanBuilderException
- thrown whenever join enumeration or
physical join construction is not possible.protected Triplet<Operator,Operator,java.util.List<Join>> pickPair(java.util.List<Join> joins, java.util.List<Operator> sources) throws PlanBuilderException
joins
- a list of logical joins.sources
- the incoming sub-plans.null
if there are no more joins,
signifying that a Cartesian product should be built.PlanBuilderException
- thrown whenever a pair cannot be
picked.protected boolean joined(Operator left, Operator right, java.util.List<Join> joins) throws PlanBuilderException
left
- the left input.right
- the right input.joins
- a list of algebraic joins.true
if the sources are joined,
false
otherwise.PlanBuilderException
protected java.util.List<Join> findJoins(Operator left, Operator right, java.util.List<Join> joins) throws PlanBuilderException
left
- the left input operator.right
- the right input operator.joins
- all joins between the two input operators.PlanBuilderException
- thrown whenever joins cannot be
identified.protected PhysicalJoin createJoin(Operator left, Operator right, java.util.List<Join> joins) throws PlanBuilderException
left
- the left input operator.right
- the right input operator.joins
- the joins between the two inputs.PlanBuilderException
- thrown whenever the physical join
cannot be instantiated.protected boolean isMergeable(Join join)
join
- the logical join predicate to checktrue
if sort-merge can be used,
false
otherwise.protected Predicate createJoinPredicate(Operator left, Operator right, Join join) throws PlanBuilderException
left
- the left input.right
- the right input.join
- the algebraic join.PlanBuilderException
- thrown whenever the physical join
predicate cannot be instantiated.protected java.util.List<Projection> getProjections(java.util.List<AlgebraicOperator> operators)
operators
- the list of algebraic operators.protected java.util.List<Selection> getSelections(java.util.List<AlgebraicOperator> operators)
operators
- the list of algebraic operatorsprotected java.util.List<Join> getJoins(java.util.List<AlgebraicOperator> operators)
operators
- the list of algebraic operators.protected java.util.List<Sort> getSorts(java.util.List<AlgebraicOperator> operators)
operators
- the list of algebraic operators.protected java.util.List<Group> getGroups(java.util.List<AlgebraicOperator> operators)
operators
- the list of algebraic operators.protected Operator imposeFinalProjections(java.util.List<Projection> projections, Operator operator) throws PlanBuilderException
projections
- the list of final projections.operator
- the incoming operator.PlanBuilderException
- thrown whenever the projection
cannot be instantiated.protected Operator imposeSorts(java.util.List<Sort> sorts, Operator operator) throws PlanBuilderException
sorts
- the list of sort operations.operator
- the incoming top operator.PlanBuilderException
- thrown whenever the final sort
cannot be instantiated.protected Operator imposeGroups(java.util.List<Group> groups, Operator operator) throws PlanBuilderException
groups
- the list of group operations.operator
- the incoming top operator.PlanBuilderException
- thrown whenever the final group
cannot be instantiated.protected java.util.List<Variable> createProjectionList(java.util.List<Projection> projections)
projections
- the list of algebraic projections.public static void main(java.lang.String[] args)
args
- arguments