Relax some asserts in merge join costing code
authorDavid Rowley <drowley@postgresql.org>
Mon, 19 Oct 2020 11:01:44 +0000 (00:01 +1300)
committerDavid Rowley <drowley@postgresql.org>
Mon, 19 Oct 2020 11:01:44 +0000 (00:01 +1300)
commit3798b4fe73b97147f67847bcb611283acd9fb0d4
tree78848429238d3c2ba1d31641a2dcb5848f02c132
parent099238322cf80dc0ea11d1cbd84e78fbf95f48e5
Relax some asserts in merge join costing code

In the planner, it was possible, given an extreme enough case containing a
large number of joins for the number of estimated rows to become infinite.
This could cause problems in initial_cost_mergejoin() where we perform
some calculations based on those row estimates.

A problem case, presented by Onder Kalaci showed an Assert failure from
an Assert checking outerstartsel <= outerendsel.  In his test case this
was effectively NaN <= Inf, which is false.  The NaN outerstartsel came
from multiplying the infinite outer_path_rows by 0.0.

In master, this problem was fixed by a90c950fc, however, that fix was too
invasive for the backbranches.  Here we just relax the Asserts to allow
them to pass.  The worst that appears to happen from this is that we show
NaN cost values and infinite row estimates in EXPLAIN.  add_path() would
have had a hard time doing anything useful with such costs, but that does
not really matter as if the row estimates were even close to accurate,
such plan would not complete this side of the heat death of the universe.

Reported-by: Onder Kalaci
Backpatch: 9.5 to 13
Discussion: http://postgr.es/m/DM6PR21MB1211FF360183BCA901B27F04D80B0@DM6PR21MB1211.namprd21.prod.outlook.com
src/backend/optimizer/path/costsize.c