model-writtenrun 8318 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Jeff Janes reported that enabling postgres_fdw remote estimates reduced an estimated million input rows to one DISTINCT ON group, causing poor join plans; disabling remote estimates instead produced a more useful default estimate of 200 groups #1.
- Bharath Rupireddy discussed pushing DISTINCT operations to remote servers, and Etsuro Fujita identified upper-planner support as a possible implementation route, but that remained a future feature #2 #3.
- Tom Lane traced the immediate bug to estimate_num_groups() disregarding relations with rel->tuples equal to zero and posted two alternative fixes, each correcting Jeff's example without changing regression results #4 #5.
- Tom preferred preserving the group-estimation clamps and proposed enforcing tuples >= rows in core; Etsuro instead suggested estimating total tuples using restriction selectivity, while Tom argued that reliable selectivity was unavailable and new FDW requirements would be unsuitable for back-patching #5 #6 #7 #8 #9.
- Tom posted the core clamp and documentation update, leaving both original alternatives out; Etsuro clarified that his proposed selectivity included remote and local restrictions, acknowledged its error-proneness, and approved the final patch for back-patching #10 #11 #12.
- Tom explained why reconstructing table size from local selectivity could undermine remote estimation, raised a richer remote-planner API as future work, and committed #10 unchanged as ca5e93f769, with backports to all supported branches #13.
- Jeff subsequently tested PostgreSQL 12's stable branch against his real data and confirmed that the restored 200-group estimate eliminated the worst plans; the estimation safeguard had landed, while DISTINCT pushdown and richer remote statistics remained future work #14.