@@ -189,15 +189,14 @@ void InnerJoin::estimateCost(unsigned position,
189189 // Remember selectivity of this stream
190190 joinedStreams[position].selectivity = candidate->selectivity ;
191191
192+ // Calculate the nested loop cost, it's our default option
193+ const auto loopCost = candidate->cost * cardinality;
194+ cost = loopCost;
195+
192196 // Get the stream cardinality
193197 const auto streamCardinality = csb->csb_rpt [stream->number ].csb_cardinality ;
194198
195- // If the table looks like empty during preparation time, we cannot be sure about
196- // its real cardinality during execution. So, unless we have some index-based
197- // filtering applied, let's better be pessimistic and avoid hash joining due to
198- // likely cardinality under-estimation.
199- const bool avoidHashJoin = (streamCardinality <= MINIMUM_CARDINALITY && !stream->baseIndexes );
200-
199+ // Calculate the retrieval cardinality
201200 auto currentCardinality = streamCardinality * candidate->selectivity ;
202201
203202 // Given the "first-rows" mode specified (or implied)
@@ -212,9 +211,11 @@ void InnerJoin::estimateCost(unsigned position,
212211 if ((candidate->unique || firstRows) && currentCardinality > MINIMUM_CARDINALITY )
213212 currentCardinality = MINIMUM_CARDINALITY ;
214213
215- // Calculate the nested loop cost, it's our default option
216- const auto loopCost = candidate->cost * cardinality;
217- cost = loopCost;
214+ // If the table looks like empty during preparation time, we cannot be sure about
215+ // its real cardinality during execution. So, unless we have some index-based
216+ // filtering applied, let's better be pessimistic and avoid hash joining due to
217+ // likely cardinality under-estimation.
218+ const bool avoidHashJoin = (streamCardinality <= MINIMUM_CARDINALITY && !stream->baseIndexes );
218219
219220 // Consider whether the current stream can be hash-joined to the prior ones.
220221 // Beware conditional retrievals, this is impossible for them.
@@ -271,7 +272,7 @@ void InnerJoin::estimateCost(unsigned position,
271272 }
272273 }
273274
274- cardinality = MAX ( currentCardinality, MINIMUM_CARDINALITY ) ;
275+ cardinality = currentCardinality;
275276}
276277
277278
0 commit comments