Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 69995c3

Browse files
committed
Fix cost_rescan() to account for multi-batch hashing correctly.
cost_rescan assumed that we don't need to rebuild the hash table when rescanning a hash join. However, that's currently only true for single-batch joins; for a multi-batch join we must charge full freight. This probably has escaped notice because we'd be unlikely to put a hash join on the inside of a nestloop anyway. Nonetheless, it's wrong. Fix in HEAD, but don't backpatch for fear of destabilizing plans in stable releases.
1 parent b31875b commit 69995c3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/backend/optimizer/path/costsize.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -3114,11 +3114,21 @@ cost_rescan(PlannerInfo *root, Path *path,
31143114
case T_HashJoin:
31153115

31163116
/*
3117-
* Assume that all of the startup cost represents hash table
3118-
* building, which we won't have to do over.
3117+
* If it's a single-batch join, we don't need to rebuild the hash
3118+
* table during a rescan.
31193119
*/
3120-
*rescan_startup_cost = 0;
3121-
*rescan_total_cost = path->total_cost - path->startup_cost;
3120+
if (((HashPath *) path)->num_batches == 1)
3121+
{
3122+
/* Startup cost is exactly the cost of hash table building */
3123+
*rescan_startup_cost = 0;
3124+
*rescan_total_cost = path->total_cost - path->startup_cost;
3125+
}
3126+
else
3127+
{
3128+
/* Otherwise, no special treatment */
3129+
*rescan_startup_cost = path->startup_cost;
3130+
*rescan_total_cost = path->total_cost;
3131+
}
31223132
break;
31233133
case T_CteScan:
31243134
case T_WorkTableScan:

0 commit comments

Comments
 (0)