@@ -587,7 +587,7 @@ namespace
587587
588588
589589//
590- // Constructor
590+ // Constructors
591591//
592592
593593Optimizer::Optimizer (thread_db* aTdbb, CompilerScratch* aCsb, RseNode* aRse,
@@ -622,6 +622,37 @@ Optimizer::Optimizer(thread_db* aTdbb, CompilerScratch* aCsb, RseNode* aRse,
622622}
623623
624624
625+ Optimizer::Optimizer (thread_db* aTdbb, CompilerScratch* aCsb, RseNode* aRse,
626+ const BoolExprNodeStack& stack)
627+ : PermanentStorage(*aTdbb->getDefaultPool ()),
628+ tdbb(aTdbb), csb(aCsb), rse(aRse),
629+ compileStreams(getPool()),
630+ bedStreams(getPool()),
631+ keyStreams(getPool()),
632+ outerStreams(getPool()),
633+ conjuncts(getPool())
634+ {
635+ for (BoolExprNodeStack::const_iterator iter (stack); iter.hasData (); ++iter)
636+ {
637+ const auto boolean = iter.object ();
638+
639+ conjuncts.add ({boolean, 0 });
640+ baseConjuncts++;
641+ baseParentConjuncts++;
642+ baseMissingConjuncts++;
643+ }
644+
645+ StreamList rseStreams;
646+ rse->computeRseStreams (rseStreams);
647+
648+ for (const auto stream : rseStreams)
649+ {
650+ if (csb->csb_rpt [stream].csb_relation )
651+ compileRelation (stream);
652+ }
653+ }
654+
655+
625656//
626657// Destructor
627658//
@@ -1179,6 +1210,29 @@ RecordSource* Optimizer::compile(BoolExprNodeStack* parentStack)
11791210}
11801211
11811212
1213+ //
1214+ // Calculate selectivity of the dependent booleans
1215+ //
1216+
1217+ double Optimizer::getDependentSelectivity ()
1218+ {
1219+ StreamStateHolder stateHolder (csb, compileStreams);
1220+ stateHolder.activate ();
1221+
1222+ double selectivity = MAXIMUM_SELECTIVITY ;
1223+ for (const auto stream : compileStreams)
1224+ {
1225+ Retrieval retrieval (tdbb, this , stream, false , false , nullptr , true );
1226+ const auto candidate = retrieval.getInversion ();
1227+
1228+ if (candidate->dependencies )
1229+ selectivity *= candidate->matchSelectivity ;
1230+ }
1231+
1232+ return selectivity;
1233+ }
1234+
1235+
11821236//
11831237// Prepare relation and its indices for optimization
11841238//
0 commit comments