8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:43:02 +01:00

Attempt to avoid hash joining for possible cardinality under-estimations

This commit is contained in:
Dmitry Yemanov 2024-05-28 12:47:39 +03:00
parent 40d0b4150c
commit 95442bdfff

View File

@ -191,6 +191,12 @@ void InnerJoin::estimateCost(unsigned position,
// Get the stream cardinality
const auto streamCardinality = csb->csb_rpt[stream->number].csb_cardinality;
// If the table looks like empty during preparation time, we cannot be sure about
// its real cardinality during execution. So, unless we have some index-based
// filtering applied, let's better be pessimistic and avoid hash joining due to
// likely cardinality under-estimation.
const bool avoidHashJoin = (streamCardinality <= MINIMUM_CARDINALITY && !stream->baseIndexes);
auto currentCardinality = candidate->unique ?
MINIMUM_CARDINALITY : streamCardinality * candidate->selectivity;
auto currentCost = candidate->cost;
@ -210,7 +216,7 @@ void InnerJoin::estimateCost(unsigned position,
// Consider whether the current stream can be hash-joined to the prior ones.
// Beware conditional retrievals, this is impossible for them.
if (position && !candidate->condition)
if (position && !candidate->condition && !avoidHashJoin)
{
// Calculate the hashing cost. It consists of the following parts:
// - hashed stream retrieval