Package edu.caltech.nanodb.plannodes
Class ThetaJoinNode
- java.lang.Object
-
- edu.caltech.nanodb.plannodes.PlanNode
-
- edu.caltech.nanodb.plannodes.ThetaJoinNode
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
NestedLoopJoinNode
,SortMergeJoinNode
public abstract class ThetaJoinNode extends PlanNode
PlanNode representing the FROM clause in a SELECT operation. This is the relational algebra ThetaJoin operator.
-
-
Field Summary
Fields Modifier and Type Field Description JoinType
joinType
The type of the join operation to perform.protected Schema
leftSchema
The cached schema of the left subplan, used for join-predicate evaluation.protected java.util.ArrayList<ColumnStats>
leftStats
The cached statistics of the left subplan, used for cost estimation.Expression
predicate
Join condition.protected Schema
rightSchema
The cached schema of the right subplan, used for join-predicate evaluation.protected java.util.ArrayList<ColumnStats>
rightStats
The cached statistics of the right subplan, used for cost estimation.protected boolean
schemaSwapped
True if the output schema of this node is swapped.-
Fields inherited from class edu.caltech.nanodb.plannodes.PlanNode
cost, environment, leftChild, rightChild, schema, stats
-
-
Constructor Summary
Constructors Constructor Description ThetaJoinNode(PlanNode leftChild, PlanNode rightChild, JoinType joinType, Expression predicate)
Constructs a ThetaJoinNode that joins the tuples from the left and right subplans, using the specified join type and join predicate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
initialize()
Do initialization for the join operation.boolean
isSwapped()
Returns true if the schema is swapped in this theta join node, false otherwise.protected Tuple
joinTuples(Tuple left, Tuple right)
Combine the left tuple and the right tuple.protected void
prepareSchemaStats()
This helper method can be used by thePlanNode.prepare()
method in subclasses, to compute the output schema and initial stats of the join operation.void
swap()
Swaps the left child and right child subtrees.-
Methods inherited from class edu.caltech.nanodb.plannodes.PlanNode
addParentEnvironmentToPlanTree, cleanUp, clone, duplicate, equals, getCost, getEnvironment, getNextTuple, getSchema, getStats, hashCode, markCurrentPosition, prepare, printNodeTree, printNodeTree, printNodeTree, printNodeTreeToString, printNodeTreeToString, requiresLeftMarking, requiresRightMarking, resetToLastMark, resultsOrderedBy, setEnvironment, supportsMarking, toString
-
-
-
-
Field Detail
-
joinType
public JoinType joinType
The type of the join operation to perform. Note that not all join implementations can necessarily implement all possible join types.
-
predicate
public Expression predicate
Join condition.
-
leftSchema
protected Schema leftSchema
The cached schema of the left subplan, used for join-predicate evaluation.
-
leftStats
protected java.util.ArrayList<ColumnStats> leftStats
The cached statistics of the left subplan, used for cost estimation.
-
rightSchema
protected Schema rightSchema
The cached schema of the right subplan, used for join-predicate evaluation.
-
rightStats
protected java.util.ArrayList<ColumnStats> rightStats
The cached statistics of the right subplan, used for cost estimation.
-
schemaSwapped
protected boolean schemaSwapped
True if the output schema of this node is swapped. If this flag is true then tuples from the left subplan will be on the right of joined results and so forth, but if the flag is false then the tuples from the left subplan will be on the left of the joined results. The schema and the statistics values reflect the state of this flag, afterPlanNode.prepare()
has been called.
-
-
Constructor Detail
-
ThetaJoinNode
public ThetaJoinNode(PlanNode leftChild, PlanNode rightChild, JoinType joinType, Expression predicate)
Constructs a ThetaJoinNode that joins the tuples from the left and right subplans, using the specified join type and join predicate.- Parameters:
leftChild
- the left relationrightChild
- the right relationjoinType
- the type of join operation to performpredicate
- the join condition
-
-
Method Detail
-
joinTuples
protected Tuple joinTuples(Tuple left, Tuple right)
Combine the left tuple and the right tuple. If schemaSwapped is set to true, the tuples are copied in the opposite order. This can only happen if swap() was called an odd number of times, switching the left and right subtrees.- Parameters:
left
- the left tupleright
- the right tuple- Returns:
- the combined tuple
-
initialize
public void initialize()
Do initialization for the join operation. Resets state variables. Initialize both children.- Overrides:
initialize
in classPlanNode
-
prepareSchemaStats
protected void prepareSchemaStats()
This helper method can be used by thePlanNode.prepare()
method in subclasses, to compute the output schema and initial stats of the join operation. This method is provided because it takes theschemaSwapped
flag into account when ordering the schema and stats.
-
swap
public void swap()
Swaps the left child and right child subtrees. Ensures that the schema of the node does not change in the swap, so that this is still a valid query plan.
-
isSwapped
public boolean isSwapped()
Returns true if the schema is swapped in this theta join node, false otherwise.- Returns:
- true if the schema is swapped in this theta join node, false otherwise.
-
-