pgsql: Avoid some zero-divide hazards in the planner.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Avoid some zero-divide hazards in the planner.
Date: 2015-07-30 16:11:45
Message-ID: E1ZKqQr-0006PA-FO@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/c7d1712519085b46b084412631ab3a0c27a7a1a6

Modified Files
--------------
src/backend/executor/nodeHash.c | 3 +++
src/backend/optimizer/plan/planmain.c | 2 +-
src/backend/optimizer/plan/planner.c | 7 +++++--
src/backend/utils/adt/selfuncs.c | 10 +++++-----
4 files changed, 14 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Joe Conway 2015-07-30 16:39:06 pgsql: Use appropriate command type when retrieving relation's policies
Previous Message Dean Rasheed 2015-07-30 13:52:18 Re: [COMMITTERS] pgsql: Row-Level Security Policies (RLS)