Package edu.caltech.nanodb.plannodes
Class NestedLoopJoinNode
- java.lang.Object
-
- edu.caltech.nanodb.plannodes.PlanNode
-
- edu.caltech.nanodb.plannodes.ThetaJoinNode
-
- edu.caltech.nanodb.plannodes.NestedLoopJoinNode
-
- All Implemented Interfaces:
java.lang.Cloneable
public class NestedLoopJoinNode extends ThetaJoinNode
This plan node implements a nested-loop join operation, which can support arbitrary join conditions but is also the slowest join implementation.
-
-
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 NestedLoopJoinNode(PlanNode leftChild, PlanNode rightChild, JoinType joinType, Expression predicate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
canJoinTuples()
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()
Returns the next joined tuple that satisfies the join condition.private boolean
getTuplesToJoin()
This helper function implements the logic that setsleftTuple
andrightTuple
based on the nested-loops logic.int
hashCode()
Computes the hash-code of the nested-loop 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()
True if the node requires that its left child supports marking.boolean
requiresRightMarking()
True if the node requires that its right child supports marking.void
resetToLastMark()
Resets the node's tuple-stream to the most recently marked position.java.util.List<OrderByExpression>
resultsOrderedBy()
Nested-loop joins can conceivably produce sorted results in situations where the outer relation is ordered, but we will keep it simple and just report that the results are not ordered.boolean
supportsMarking()
True if the node supports position marking.java.lang.String
toString()
Returns a string representing this nested-loop 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
-
NestedLoopJoinNode
public NestedLoopJoinNode(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 nested-loop plan node.
-
toString
public java.lang.String toString()
Returns a string representing this nested-loop 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()
Nested-loop joins can conceivably produce sorted results in situations where the outer relation is ordered, but we will keep it simple and just report that the results are not ordered.- Specified by:
resultsOrderedBy
in classPlanNode
- Returns:
- If the plan node produces ordered results, this will be a list of objects specifying the ordering. If the node doesn't produce ordered results then the return-value will either be an empty list or it will be null.
-
supportsMarking
public boolean supportsMarking()
True if the node supports position marking.- Overrides:
supportsMarking
in classPlanNode
- Returns:
- true if the node supports position marking, false otherwise.
-
requiresLeftMarking
public boolean requiresLeftMarking()
True if the node requires that its left child supports marking.- Overrides:
requiresLeftMarking
in classPlanNode
- Returns:
- true if the node requires that its left child supports marking, false otherwise.
-
requiresRightMarking
public boolean requiresRightMarking()
True if the node requires that its right child supports marking.- 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()
Returns the next joined tuple that satisfies the join condition.- Specified by:
getNextTuple
in classPlanNode
- Returns:
- the next joined tuple that satisfies the join condition.
-
getTuplesToJoin
private boolean getTuplesToJoin()
This helper function implements the logic that setsleftTuple
andrightTuple
based on the nested-loops logic.- Returns:
true
if another pair of tuples was found to join, orfalse
if no more pairs of tuples are available to join.
-
canJoinTuples
private boolean canJoinTuples()
-
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() throws java.lang.IllegalStateException
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
- Throws:
java.lang.IllegalStateException
- ifPlanNode.markCurrentPosition()
hasn't yet been called on this plan-node
-
-