Buggy code:
} if ( ! ( pred . getReferencedMap ( ) . hasSingleBitSet ( ) ) ) { constantStartStop = false ; break ; } } if ( constantStartStop ) { currentAccessPath . setLockMode ( MODE_RECORD ) ; optimizer . trace ( ROW_LOCK_ALL_CONSTANT_START_STOP , 0 , 0 , 0.0 , null ) ; } else { setLockingBasedOnThreshold ( optimizer , costEstimate . rowCount ( ) ) ; } optimizer . trace ( COST_OF_N_SCANS , tableNumber , 0 , outerCost . rowCount ( ) , costEstimate ) ; if ( ( cd . isIndex ( ) ) && ( ! ( isCoveringIndex ( cd ) ) ) ) { double singleFetchCost = getBaseCostController ( ) . getFetchFromRowLocationCost ( ( ( FormatableBitSet ) ( null ) ) , 0 ) ; cost = singleFetchCost * ( costEstimate . rowCount ( ) ) ; costEstimate . setEstimatedCost ( ( ( costEstimate . getEstimatedCost ( ) ) + cost ) ) ; optimizer . trace ( NON_COVERING_INDEX_COST , tableNumber , 0 , cost , null ) ; } } else { double extraFirstColumnSelectivity = 1.0 ; double extraStartStopSelectivity = 1.0 ; double extraQualifierSelectivity = 1.0 ; double extraNonQualifierSelectivity = 1.0 ; double statStartStopSelectivity = 1.0 ; double statCompositeSelectivity = 1.0 ; int numExtraFirstColumnPreds = 0 ; int numExtraStartStopPreds = 0 ; int numExtraQualifiers = 0 ; int numExtraNonQualifiers = 0 ; boolean startGap = false ; boolean stopGap = false ; boolean seenFirstColumn = false ; boolean constantStartStop = true ; boolean startStopFound = false ; int startKeyNum = 0 ; int stopKeyNum = 0 ; OptimizablePredicate pred ; int predListSize ; if ( predList != null ) predListSize = baseTableRestrictionList . size ( ) ; else predListSize = 0 ; int startStopPredCount = 0 ; ColumnReference firstColumn = null ; for ( int i = 0 ; i < predListSize ; i ++ ) { pred = baseTableRestrictionList . getOptPredicate ( i ) ; boolean startKey = pred . isStartKey ( ) ; boolean stopKey = pred . isStopKey ( ) ; if ( startKey || stopKey ) { startStopFound = true ; if ( ! ( pred . getReferencedMap ( ) . hasSingleBitSet ( ) ) ) { constantStartStop = false ; } boolean knownConstant = pred . compareWithKnownConstant ( this , true ) ; if ( startKey ) { if ( knownConstant && ( ! startGap ) ) { startKeyNum ++ ; if ( unknownPredicateList != null ) unknownPredicateList . removeOptPredicate ( pred ) ; } else { startGap = true ; } } if ( stopKey ) { if ( knownConstant && ( ! stopGap ) ) { stopKeyNum ++ ; if ( unknownPredicateList != null ) unknownPredicateList . removeOptPredicate ( pred ) ; } else { stopGap = true ; } } if ( startGap || stopGap ) { if ( baseTableRestrictionList . isRedundantPredicate ( i ) ) continue ; if ( startKey && stopKey ) startStopPredCount ++ ; if ( ( pred . getIndexPosition ( ) ) == 0 ) { extraFirstColumnSelectivity *= pred . selectivity ( this ) ; if ( ! seenFirstColumn ) { ValueNode relNode = ( ( Predicate ) ( pred ) ) . getAndNode ( ) . getLeftOperand ( ) ; if ( relNode instanceof BinaryRelationalOperatorNode ) firstColumn = ( ( BinaryRelationalOperatorNode ) ( relNode ) ) . getColumnOperand ( this ) ; seenFirstColumn = true ; } } else { extraStartStopSelectivity *= pred . selectivity ( this ) ; numExtraStartStopPreds ++ ; } } } else { if ( baseTableRestrictionList . isRedundantPredicate ( i ) ) { continue ; } if ( pred instanceof Predicate ) { ValueNode leftOpnd = ( ( Predicate ) ( pred ) ) . getAndNode ( ) . getLeftOperand ( ) ; if ( ( firstColumn != null ) && ( leftOpnd instanceof LikeEscapeOperatorNode ) ) { LikeEscapeOperatorNode likeNode = ( ( LikeEscapeOperatorNode ) ( leftOpnd ) ) ; <START_BUG> if ( likeNode . getLeftOperand ( ) . isParameterNode ( ) ) { <END_BUG> ValueNode receiver = ( ( TernaryOperatorNode ) ( likeNode ) ) . getReceiver ( ) ; if ( receiver instanceof ColumnReference ) { ColumnReference cr = ( ( ColumnReference ) ( receiver ) ) ; if ( ( ( cr . getTableNumber ( ) ) == ( firstColumn . getTableNumber ( ) ) ) && ( ( cr . getColumnNumber ( ) ) == ( firstColumn . getColumnNumber ( ) ) ) ) extraFirstColumnSelectivity *= 0.2 ; } } } } if ( pred . isQualifier ( ) ) { extraQualifierSelectivity *= pred . selectivity ( this ) ; numExtraQualifiers ++ ; } else { extraNonQualifierSelectivity *= pred . selectivity ( this ) ; numExtraNonQualifiers ++ ; } startGap = true ; stopGap = true ; } } if ( unknownPredicateList != null ) { statCompositeSelectivity = unknownPredicateList . selectivity ( this ) ; if ( statCompositeSelectivity == ( - 1.0 ) ) statCompositeSelectivity = 1.0 ; } if ( ( seenFirstColumn && statisticsForConglomerate ) && ( startStopPredCount > 0 ) ) { statStartStopSelectivity = tableDescriptor . selectivityForConglomerate ( cd , startStopPredCount ) ; } extraNonQualifierSelectivity *= currentJoinStrategy . nonBasePredicateSelectivity ( this , predList ) ; DataValueDescriptor [ ] startKeys ; DataValueDescriptor [ ] stopKeys ; if ( startKeyNum > 0 ) startKeys = new DataValueDescriptor [ startKeyNum ] ; else startKeys = null ; if ( stopKeyNum > 0 ) stopKeys = new DataValueDescriptor [ stopKeyNum ] ; else stopKeys = null ; startKeyNum = 0 ; stopKeyNum = 0 ; startGap = false ; stopGap = false ; for ( int i = 0 ; i < predListSize ; i ++ ) { pred = baseTableRestrictionList . getOptPredicate ( i ) ; boolean startKey = pred . isStartKey ( ) ; boolean stopKey = pred . isStopKey ( ) ; if ( startKey || stopKey ) { boolean knownConstant = pred . compareWithKnownConstant ( this , true ) ;

Fix:
if ( likeNode . getLeftOperand ( ) . requiresTypeFromContext ( ) ) {