On Fri, Apr 29, 2022 at 11:09 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
In short, these SubqueryScans are being labeled as producing 60000 rows when their input only produces 25000 rows, which is surely insane.
So: even though the SubqueryScan itself isn't parallel-aware, the number of rows it processes has to be de-rated according to the number of workers involved.
Right, so why does baserel.rows show 60,000 here when path->subpath->rows only shows 25,000? Because if you substitute path->subpath->rows for baserel.rows in cost_subquery you get (with your cost change above):
Which shows your 1400 cost goal from union all, and the expected row counts, for gather-atop-append.
The fact that (baserel.rows > path->subpath->rows) here seems like a straight bug: there are no filters involved in this case but in the presence of filters baserel->rows should be strictly (<= path->subpath->rows), right?