Buggy code:
public class JoinNode extends TableOperatorNode { public static final int INNERJOIN = 1 ; public static final int CROSSJOIN = 2 ; public static final int LEFTOUTERJOIN = 3 ; public static final int RIGHTOUTERJOIN = 4 ; public static final int FULLOUTERJOIN = 5 ; public static final int UNIONJOIN = 6 ; private boolean optimized ; private PredicateList leftPredicateList ; private PredicateList rightPredicateList ; protected boolean flattenableJoin = true ; Vector aggregateVector ; SubqueryList subqueryList ; ValueNode joinClause ; boolean joinClauseNormalized ; PredicateList joinPredicates ; ResultColumnList usingClause ; public void init ( Object leftResult , Object rightResult , Object onClause , Object usingClause , Object selectList , Object tableProperties ) throws StandardException { } public CostEstimate optimizeIt ( Optimizer optimizer , OptimizablePredicateList predList , CostEstimate outerCost , RowOrdering rowOrdering ) throws StandardException { optimizer . trace ( CALLING_ON_JOIN_NODE , 0 , 0 , 0.0 , null ) ; <START_BUG> addOrLoadBestPlanMapping ( true , this ) ; <END_BUG> leftResultSet = optimizeSource ( optimizer , leftResultSet , getLeftPredicateList ( ) , outerCost ) ; for ( int index = ( joinPredicates . size ( ) ) - 1 ; index >= 0 ; index -- ) { JBitSet curBitSet ; Predicate predicate ; predicate = ( ( Predicate ) ( joinPredicates . elementAt ( index ) ) ) ; if ( ! ( predicate . getPushable ( ) ) ) { continue ; } joinPredicates . removeElementAt ( index ) ; getRightPredicateList ( ) . addElement ( predicate ) ; } rightResultSet = optimizeSource ( optimizer , rightResultSet , getRightPredicateList ( ) , leftResultSet . getCostEstimate ( ) ) ; costEstimate = getCostEstimate ( optimizer ) ; costEstimate . setCost ( ( ( leftResultSet . getCostEstimate ( ) . getEstimatedCost ( ) ) + ( rightResultSet . getCostEstimate ( ) . getEstimatedCost ( ) ) ) , rightResultSet . getCostEstimate ( ) . rowCount ( ) , rightResultSet . getCostEstimate ( ) . rowCount ( ) ) ; adjustNumberOfRowsReturned ( costEstimate ) ; getCurrentAccessPath ( ) . getJoinStrategy ( ) . estimateCost ( this , predList , ( ( ConglomerateDescriptor ) ( null ) ) , outerCost , optimizer , costEstimate ) ; optimizer . considerCost ( this , predList , costEstimate , outerCost ) ; if ( ( ! ( optimized ) ) && ( ( subqueryList ) != null ) ) { subqueryList . optimize ( optimizer . getDataDictionary ( ) , costEstimate . rowCount ( ) ) ; subqueryList . modifyAccessPaths ( ) ; } optimized = true ; return costEstimate ; } public boolean pushOptPredicate ( OptimizablePredicate optimizablePredicate ) throws StandardException { } public Optimizable modifyAccessPath ( JBitSet outerTables ) throws StandardException { } protected void adjustNumberOfRowsReturned ( CostEstimate costEstimate ) { } public ResultColumnList getAllResultColumns ( TableName allTableName ) throws StandardException { } private ResultColumnList getAllResultColumnsNoUsing ( TableName allTableName ) throws StandardException { } public ResultColumn getMatchingColumn ( ColumnReference columnReference ) throws StandardException { } public void bindResultColumns ( FromList fromListParam ) throws StandardException { } public void bindResultColumns ( TableDescriptor targetTableDescriptor , FromVTI targetVTI , ResultColumnList targetColumnList , DMLStatementNode statement , FromList fromListParam ) throws StandardException { } private void buildRCL ( ) throws StandardException { } private void deferredBindExpressions ( FromList fromListParam ) throws StandardException { } public ResultSetNode preprocess ( int numTables , GroupByList gbl , FromList fromList ) throws StandardException { } void projectResultColumns ( ) throws StandardException { } public void normExpressions ( ) throws StandardException { } public void pushExpressions ( PredicateList outerPredicateList ) throws StandardException { } protected void pushExpressionsToLeft ( PredicateList outerPredicateList ) throws StandardException { } private void pushExpressionsToRight ( PredicateList outerPredicateList ) throws StandardException { } private void grabJoinPredicates ( PredicateList outerPredicateList ) throws StandardException { } public FromList flatten ( ResultColumnList rcl , PredicateList outerPList , SubqueryList sql , GroupByList gbl ) throws StandardException { } public boolean LOJ_reorderable ( int numTables ) throws StandardException { } public FromTable transformOuterJoins ( ValueNode predicateTree , int numTables ) throws StandardException { } public void generate ( ActivationClassBuilder acb , MethodBuilder mb ) throws StandardException { } public void generateCore ( ActivationClassBuilder acb , MethodBuilder mb , int joinType ) throws StandardException { } protected void generateCore ( ActivationClassBuilder acb , MethodBuilder mb , int joinType , ValueNode joinClause , SubqueryList subquerys ) throws StandardException { } private int getJoinArguments ( ActivationClassBuilder acb , MethodBuilder mb , ValueNode joinClause ) throws StandardException { } public CostEstimate getFinalCostEstimate ( ) throws StandardException { } protected void oneRowRightSide ( ActivationClassBuilder acb , MethodBuilder mb ) throws StandardException { } protected int getNumJoinArguments ( ) { } protected int addOuterJoinArguments ( ActivationClassBuilder acb , MethodBuilder mb ) throws StandardException { } public static String joinTypeToString ( int joinType ) { } protected PredicateList getLeftPredicateList ( ) throws StandardException { } protected PredicateList getRightPredicateList ( ) throws StandardException { } public int updateTargetLockMode ( ) { } void notFlattenableJoin ( ) { } public boolean isFlattenableJoinNode ( ) { } boolean isOrderedOn ( ColumnReference [ ] crs , boolean permuteOrdering , Vector fbtVector ) throws StandardException { } public void printSubNodes ( int depth ) { } void setSubqueryList ( SubqueryList subqueryList ) { } void setAggregateVector ( Vector aggregateVector ) { } ResultSetNode getLogicalLeftResultSet ( ) { } ResultSetNode getLogicalRightResultSet ( ) { } public Visitable accept ( Visitor v ) throws StandardException { } public JBitSet LOJgetReferencedTables ( int numTables ) throws StandardException { } }

Fix:
updateBestPlanMap ( ADD_PLAN , this ) ;