postgres_fdw: Fix issues with statistics import. When analyzing a foreign table pointing to a partitioned or inherited table on the remote server, this method just imported relpages and reltuples for the parent table from the remote pg_class, causing a discrepancy or an error in results compared to the sampling method.
* In the partitioning case, while the sampling method sets relpages=0, this method set relpages=-1. (For reltuples, the results of both methods match.) * In the inheritance case, while the sampling method sets reltuples=(# of rows in the parent and child tables), this method set reltuples=(# of rows in the parent table). (For relpages, the results of both methods match.) As relpages and reltuples are used for costing foreign paths, these would lead to incorrect plans or plan changes depending on the method. To fix, do the following: * For the partitioning case, modify postgres_fdw to set relpages=0 to match the sampling method. * For the inheritance case, we could also modify it to set the correct reltuples value by fetching reltuples for the child tables as well, but 1) the change isn't small, and 2) table inheritance hasn't been used that much these days, so fix by disabling this method. While at it, adjust comments and docs slightly. Oversight in commit 28972b6fc. Author: Etsuro Fujita <[email protected]> Discussion: https://postgr.es/m/CAPmGK173b2Xvyoeq%3DY7L09H%2BajgMgxC2fYe%3D7CCunZz8tGTfFA%40mail.gmail.com Backpatch-through: 19 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/f4012672bb2e5f1b0a4641826e14e9d209049dea Modified Files -------------- contrib/postgres_fdw/deparse.c | 11 ++- contrib/postgres_fdw/expected/postgres_fdw.out | 27 +++++++ contrib/postgres_fdw/postgres_fdw.c | 100 +++++++++++++------------ contrib/postgres_fdw/sql/postgres_fdw.sql | 17 +++++ doc/src/sgml/postgres-fdw.sgml | 5 +- 5 files changed, 108 insertions(+), 52 deletions(-)
