Package edu.caltech.nanodb.plannodes
Class SortMergeJoinNode
- java.lang.Object
-
- edu.caltech.nanodb.plannodes.PlanNode
-
- edu.caltech.nanodb.plannodes.ThetaJoinNode
-
- edu.caltech.nanodb.plannodes.SortMergeJoinNode
-
- All Implemented Interfaces:
java.lang.Cloneable
public class SortMergeJoinNode extends ThetaJoinNode
This class implements the basic sort-merge join algorithm for use in join evaluation. This join node is only useful for equijoins, but it has the benefit that it can compute full outer joins easily, where the nested-loops join algorithm is unable to do so.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
done
Set to true when we have exhausted all tuples from our subplans.private Tuple
leftTuple
Most recently retrieved tuple of the left relation.private static org.apache.logging.log4j.Logger
logger
A logging object for reporting anything interesting that happens.private Tuple
rightTuple
Most recently retrieved tuple of the right relation.-
Fields inherited from class edu.caltech.nanodb.plannodes.ThetaJoinNode
joinType, leftSchema, leftStats, predicate, rightSchema, rightStats, schemaSwapped
-
Fields inherited from class edu.caltech.nanodb.plannodes.PlanNode
cost, environment, leftChild, rightChild, schema, stats
-
-
Constructor Summary
Constructors Constructor Description SortMergeJoinNode(PlanNode leftChild, PlanNode rightChild, JoinType joinType, Expression predicate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanUp()
Perform any necessary clean up tasks.protected PlanNode
clone()
Creates a copy of this plan node and its subtrees.boolean
equals(java.lang.Object obj)
Checks if the argument is a plan node tree with the same structure, but not necessarily the same references.Tuple
getNextTuple()
Gets the next tuple that fulfills the conditions for this plan node.int
hashCode()
Computes the hash-code of the sort-merge join plan node.void
initialize()
Do initialization for the join operation.void
markCurrentPosition()
Marks the current tuple in the tuple-stream produced by this node.void
prepare()
This method is responsible for computing critical details about the plan node, such as the schema of the results that are produced, the estimated cost of evaluating the plan node (and its children), and statistics describing the results produced by the plan node.boolean
requiresLeftMarking()
This plan-node does not require marking on the left child-plan.boolean
requiresRightMarking()
This plan-node requires marking on the right child-plan.void
resetToLastMark()
Resets the node's tuple-stream to the most recently marked position.java.util.List<OrderByExpression>
resultsOrderedBy()
Sort-merge join produces results in the same order as the children.boolean
supportsMarking()
This plan-node does not support marking.java.lang.String
toString()
Returns a string representing this sort-merge join's vital information.-
Methods inherited from class edu.caltech.nanodb.plannodes.ThetaJoinNode
isSwapped, joinTuples, prepareSchemaStats, swap
-
Methods inherited from class edu.caltech.nanodb.plannodes.PlanNode
addParentEnvironmentToPlanTree, duplicate, getCost, getEnvironment, getSchema, getStats, printNodeTree, printNodeTree, printNodeTree, printNodeTreeToString, printNodeTreeToString, setEnvironment
-
-
-
-
Field Detail
-
logger
private static org.apache.logging.log4j.Logger logger
A logging object for reporting anything interesting that happens.
-
leftTuple
private Tuple leftTuple
Most recently retrieved tuple of the left relation.
-
rightTuple
private Tuple rightTuple
Most recently retrieved tuple of the right relation.
-
done
private boolean done
Set to true when we have exhausted all tuples from our subplans.
-
-
Constructor Detail
-
SortMergeJoinNode
public SortMergeJoinNode(PlanNode leftChild, PlanNode rightChild, JoinType joinType, Expression predicate)
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object obj)
Checks if the argument is a plan node tree with the same structure, but not necessarily the same references.
-
hashCode
public int hashCode()
Computes the hash-code of the sort-merge join plan node.
-
toString
public java.lang.String toString()
Returns a string representing this sort-merge join's vital information.
-
clone
protected PlanNode clone() throws java.lang.CloneNotSupportedException
Creates a copy of this plan node and its subtrees.
-
resultsOrderedBy
public java.util.List<OrderByExpression> resultsOrderedBy()
Sort-merge join produces results in the same order as the children. (That's kinda the point.)- Specified by:
resultsOrderedBy
in classPlanNode
- Returns:
- true always
-
supportsMarking
public boolean supportsMarking()
This plan-node does not support marking.- Overrides:
supportsMarking
in classPlanNode
- Returns:
- true if the node supports position marking, false otherwise.
-
requiresLeftMarking
public boolean requiresLeftMarking()
This plan-node does not require marking on the left child-plan.- Overrides:
requiresLeftMarking
in classPlanNode
- Returns:
- true if the node requires that its left child supports marking, false otherwise.
-
requiresRightMarking
public boolean requiresRightMarking()
This plan-node requires marking on the right child-plan.- Overrides:
requiresRightMarking
in classPlanNode
- Returns:
- true if the node requires that its right child supports marking, false otherwise.
-
prepare
public void prepare()
Description copied from class:PlanNode
This method is responsible for computing critical details about the plan node, such as the schema of the results that are produced, the estimated cost of evaluating the plan node (and its children), and statistics describing the results produced by the plan node.
-
initialize
public void initialize()
Description copied from class:ThetaJoinNode
Do initialization for the join operation. Resets state variables. Initialize both children.- Overrides:
initialize
in classThetaJoinNode
-
getNextTuple
public Tuple getNextTuple()
Description copied from class:PlanNode
Gets the next tuple that fulfills the conditions for this plan node. If the node has a child, it should call getNextTuple() on the child. If the node is a leaf, the tuple comes from some external source such as a table file, the network, etc.- Specified by:
getNextTuple
in classPlanNode
- Returns:
- the next tuple to be generated by this plan, or null if the plan has finished generating plan nodes.
-
markCurrentPosition
public void markCurrentPosition()
Description copied from class:PlanNode
Marks the current tuple in the tuple-stream produced by this node. ThePlanNode.resetToLastMark()
method can be used to return to this tuple. Note that only one marker can be set in the tuple-stream at a time.- Overrides:
markCurrentPosition
in classPlanNode
-
resetToLastMark
public void resetToLastMark()
Description copied from class:PlanNode
Resets the node's tuple-stream to the most recently marked position. Note that only one marker can be set in the tuple-stream at a time.- Overrides:
resetToLastMark
in classPlanNode
-
-