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

Cost calculation adjustmnets for hash joins

This commit is contained in:
Dmitry Yemanov 2023-09-11 15:43:47 +03:00
parent b31fc0a4d1
commit b3c54800f3
2 changed files with 11 additions and 3 deletions

View File

@ -200,12 +200,16 @@ void InnerJoin::estimateCost(unsigned position,
{
// Calculate the hashing cost. It consists of the following parts:
// - hashed stream retrieval
// - copying rows into the hash table
// - copying rows into the hash table (including hash calculation)
// - probing the hash table and copying the matched rows
const auto hashCardinality = stream->baseSelectivity * streamCardinality;
const auto hashCost = stream->baseCost + hashCardinality +
cardinality * (1.0 + candidate->selectivity * streamCardinality);
const auto hashCost = stream->baseCost +
// hashing cost
hashCardinality * (COST_FACTOR_MEMCOPY + COST_FACTOR_HASHING) +
// probing + copying cost
cardinality * (COST_FACTOR_HASHING +
candidate->selectivity * streamCardinality * COST_FACTOR_MEMCOPY);
if (hashCost <= loopCost && hashCardinality <= HashJoin::maxCapacity())
{

View File

@ -52,6 +52,10 @@ const double REDUCE_SELECTIVITY_FACTOR_GREATER = 0.05;
const double REDUCE_SELECTIVITY_FACTOR_STARTING = 0.01;
const double REDUCE_SELECTIVITY_FACTOR_OTHER = 0.01;
// Cost of simple (CPU bound) operations is less than the page access cost
const double COST_FACTOR_MEMCOPY = 0.5;
const double COST_FACTOR_HASHING = 0.5;
const double MAXIMUM_SELECTIVITY = 1.0;
const double DEFAULT_SELECTIVITY = 0.1;