Buggy code:
public abstract class TableOperatorNode extends FromTable { boolean nestedInParens ; ResultSetNode leftResultSet ; ResultSetNode rightResultSet ; Optimizer leftOptimizer ; Optimizer rightOptimizer ; private boolean leftModifyAccessPathsDone ; private boolean rightModifyAccessPathsDone ; public void init ( Object leftResultSet , Object rightResultSet , Object tableProperties ) throws StandardException { } public Optimizable modifyAccessPath ( JBitSet outerTables ) throws StandardException { } public void verifyProperties ( DataDictionary dDictionary ) throws StandardException { } public void addOrLoadBestPlanMapping ( boolean doAdd , Optimizer optimizer ) throws StandardException { } public String toString ( ) { } public void printSubNodes ( int depth ) { } public ResultSetNode getLeftResultSet ( ) { } public ResultSetNode getRightResultSet ( ) { } public ResultSetNode getLeftmostResultSet ( ) { } public void setLeftmostResultSet ( ResultSetNode newLeftResultSet ) { } public void setLevel ( int level ) { } public String getExposedName ( ) { } public void setNestedInParens ( boolean nestedInParens ) { } public boolean getNestedInParens ( ) { } public ResultSetNode bindNonVTITables ( DataDictionary dataDictionary , FromList fromListParam ) throws StandardException { } public ResultSetNode bindVTITables ( FromList fromListParam ) throws StandardException { } public void bindExpressions ( FromList fromListParam ) throws StandardException { } public void rejectParameters ( ) throws StandardException { } public void bindExpressionsWithTables ( FromList fromListParam ) throws StandardException { } public void bindResultColumns ( FromList fromListParam ) throws StandardException { } public void bindResultColumns ( TableDescriptor targetTableDescriptor , FromVTI targetVTI , ResultColumnList targetColumnList , DMLStatementNode statement , FromList fromListParam ) throws StandardException { } protected FromTable getFromTableByName ( String name , String schemaName , boolean exactMatch ) throws StandardException { } public ResultSetNode preprocess ( int numTables , GroupByList gbl , FromList fromList ) throws StandardException { } void projectResultColumns ( ) throws StandardException { } void setReferencedColumns ( ) { } public ResultSetNode optimize ( DataDictionary dataDictionary , PredicateList predicateList , double outerRows ) throws StandardException { } public ResultSetNode modifyAccessPaths ( ) throws StandardException { } public boolean referencesTarget ( String name , boolean baseTable ) throws StandardException { } public boolean referencesSessionSchema ( ) throws StandardException { } protected ResultSetNode optimizeSource ( Optimizer optimizer , ResultSetNode sourceResultSet , PredicateList predList , CostEstimate outerCost ) throws StandardException { ResultSetNode retval ; if ( sourceResultSet instanceof FromTable ) { FromList optList = ( ( FromList ) ( getNodeFactory ( ) . getNode ( FROM_LIST , getNodeFactory ( ) . doJoinOrderOptimization ( ) , sourceResultSet , getContextManager ( ) ) ) ) ; if ( predList == null ) predList = ( ( PredicateList ) ( getNodeFactory ( ) . getNode ( PREDICATE_LIST , getContextManager ( ) ) ) ) ; LanguageConnectionContext lcc = getLanguageConnectionContext ( ) ; OptimizerFactory optimizerFactory = lcc . getOptimizerFactory ( ) ; optimizer = optimizerFactory . getOptimizer ( optList , predList , getDataDictionary ( ) , ( ( RequiredRowOrdering ) ( null ) ) , getCompilerContext ( ) . getNumTables ( ) , lcc ) ; <START_BUG> ( ( OptimizerImpl ) ( optimizer ) ) . prepForNextRound ( ) ; <END_BUG> if ( sourceResultSet == ( leftResultSet ) ) { leftOptimizer = optimizer ; } else if ( sourceResultSet == ( rightResultSet ) ) { rightOptimizer = optimizer ; } else { if ( SanityManager . DEBUG ) SanityManager . THROWASSERT ( "Result<seq2seq4repair_space>set<seq2seq4repair_space>being<seq2seq4repair_space>optimized<seq2seq4repair_space>is<seq2seq4repair_space>neither<seq2seq4repair_space>left<seq2seq4repair_space>nor<seq2seq4repair_space>right" ) ; } optimizer . setOuterRows ( outerCost . rowCount ( ) ) ; while ( optimizer . getNextPermutation ( ) ) { while ( optimizer . getNextDecoratedPermutation ( ) ) { optimizer . costPermutation ( ) ; } } retval = sourceResultSet ; } else { retval = sourceResultSet . optimize ( optimizer . getDataDictionary ( ) , predList , outerCost . rowCount ( ) ) ; } return retval ; } void decrementLevel ( int decrement ) { } void replaceDefaults ( TableDescriptor ttd , ResultColumnList tcl ) throws StandardException { } void markOrderingDependent ( ) { } public Visitable accept ( Visitor v ) throws StandardException { } public boolean needsSpecialRCLBinding ( ) { } }

Fix:
optimizer . prepForNextRound ( ) ;