@@ -591,11 +591,10 @@ namespace
591591//
592592
593593Optimizer::Optimizer (thread_db* aTdbb, CompilerScratch* aCsb, RseNode* aRse,
594- bool parentFirstRows, double parentCardinality )
594+ bool parentFirstRows)
595595 : PermanentStorage(*aTdbb->getDefaultPool ()),
596596 tdbb(aTdbb), csb(aCsb), rse(aRse),
597597 firstRows(rse->firstRows.valueOr(parentFirstRows)),
598- cardinality(parentCardinality),
599598 compileStreams(getPool()),
600599 bedStreams(getPool()),
601600 keyStreams(getPool()),
@@ -651,7 +650,7 @@ RecordSource* Optimizer::compile(RseNode* subRse, BoolExprNodeStack* parentStack
651650 // if we're going to sort/aggregate the resultset afterwards
652651 const bool subFirstRows = firstRows && !rse->rse_sorted && !rse->rse_aggregate ;
653652
654- Optimizer subOpt (tdbb, csb, subRse, subFirstRows, cardinality );
653+ Optimizer subOpt (tdbb, csb, subRse, subFirstRows);
655654 const auto rsb = subOpt.compile (parentStack);
656655
657656 if (parentStack && subOpt.isInnerJoin ())
@@ -702,31 +701,11 @@ RecordSource* Optimizer::compile(BoolExprNodeStack* parentStack)
702701
703702 conjunctCount += distributeEqualities (conjunctStack, conjunctCount);
704703
705- if (parentStack)
706- {
707- // AB: If we have limit our retrieval with FIRST / SKIP syntax then
708- // we may not deliver above conditions (from higher rse's) to this
709- // rse, because the results should be consistent.
710- if (rse->rse_skip || rse->rse_first )
711- parentStack = nullptr ;
712-
713- if (isSpecialJoin () && parentStack->hasData ())
714- {
715- // We have a semi-join, look at the parent (priorly joined streams) cardinality.
716- // If it's known to be not very small, nullify the parent conjuncts
717- // to give up a possible nested loop join in favor of a hash join.
718- // Here we assume every equi-join condition having a default selectivity (0.1).
719- // TODO: replace with a proper cost-based decision in the future.
720-
721- double subSelectivity = MAXIMUM_SELECTIVITY;
722- for (auto count = parentStack->getCount (); count; count--)
723- subSelectivity *= DEFAULT_SELECTIVITY;
724- const auto thresholdCardinality = MINIMUM_CARDINALITY / subSelectivity;
725-
726- if (!cardinality || cardinality > thresholdCardinality)
727- parentStack = nullptr ;
728- }
729- }
704+ // AB: If we have limit our retrieval with FIRST / SKIP syntax then
705+ // we may not deliver above conditions (from higher rse's) to this
706+ // rse, because the results should be consistent.
707+ if (rse->rse_skip || rse->rse_first )
708+ parentStack = nullptr ;
730709
731710 // Set base-point before the parent/distributed nodes begin.
732711 const unsigned baseCount = conjunctCount;
@@ -905,7 +884,7 @@ RecordSource* Optimizer::compile(BoolExprNodeStack* parentStack)
905884 bool computable = false ;
906885
907886 // AB: Save all outer-part streams
908- if (isInnerJoin () || (isLeftJoin () && !innerSubStream))
887+ if (isInnerJoin () || (( isLeftJoin () || isSpecialJoin () ) && !innerSubStream))
909888 {
910889 if (node->computable (csb, INVALID_STREAM, false ))
911890 computable = true ;
0 commit comments