diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-07-30 12:11:23 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-07-30 12:11:23 -0400 |
commit | 3b4a9dbfa5339405f7f78639b83bfb563603cfe3 (patch) | |
tree | b07d5789d289bf7f8bbe2cdb0f3fabb25a5a37f9 /src/backend/executor | |
parent | 76cf5f1956cec181dcf0956d0d7b673453a50e74 (diff) | |
download | postgresql-3b4a9dbfa5339405f7f78639b83bfb563603cfe3.tar.gz postgresql-3b4a9dbfa5339405f7f78639b83bfb563603cfe3.zip |
Avoid some zero-divide hazards in the planner.
Although I think on all modern machines floating division by zero
results in Infinity not SIGFPE, we still don't want infinities
running around in the planner's costing estimates; too much risk
of that leading to insane behavior.
grouping_planner() failed to consider the possibility that final_rel
might be known dummy and hence have zero rowcount. (I wonder if it
would be better to set a rows estimate of 1 for dummy relations?
But at least in the back branches, changing this convention seems
like a bad idea, so I'll leave that for another day.)
Make certain that get_variable_numdistinct() produces a nonzero result.
The case that can be shown to be broken is with stadistinct < 0.0 and
small ntuples; we did not prevent the result from rounding to zero.
For good luck I applied clamp_row_est() to all the nonconstant return
values.
In ExecChooseHashTableSize(), Assert that we compute positive nbuckets
and nbatch. I know of no reason to think this isn't the case, but it
seems like a good safety check.
Per reports from Piotr Stefaniak. Back-patch to all active branches.
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/nodeHash.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index 589b2f15099..6917d3f4e6c 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -509,6 +509,9 @@ ExecChooseHashTableSize(double ntuples, int tupwidth, bool useskew, i++; nbuckets = (1 << i); + Assert(nbuckets > 0); + Assert(nbatch > 0); + *numbuckets = nbuckets; *numbatches = nbatch; } |