]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
postgres_fdw: Add Assert to estimate_path_cost_size().
authorEtsuro Fujita <efujita@postgresql.org>
Sun, 6 Jul 2025 08:15:00 +0000 (17:15 +0900)
committerEtsuro Fujita <efujita@postgresql.org>
Sun, 6 Jul 2025 08:15:00 +0000 (17:15 +0900)
When estimating the cost/size of a pre-sorted path for a given upper
relation using local stats, this function dereferences the passed-in
PgFdwPathExtraData pointer without checking that it is not NULL.  But
that is not a bug as the pointer is guaranteed to be non-NULL in that
case; to avoid confusion, add an Assert to ensure that it is not NULL
before dereferencing it.

Reported-by: Ranier Vilela <ranier.vf@gmail.com>
Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Discussion: https://postgr.es/m/CAEudQArgiALbV1akQpeZOgim7XP05n%3DbDP1%3DTcOYLA43nRX_vA%40mail.gmail.com

contrib/postgres_fdw/postgres_fdw.c

index 4283ce9f96252e521687fab1228da2ea57bf36bb..e0a34b27c7cfdc88c4bf147c15aec536a5b0d06c 100644 (file)
@@ -3507,6 +3507,13 @@ estimate_path_cost_size(PlannerInfo *root,
                        {
                                Assert(foreignrel->reloptkind == RELOPT_UPPER_REL &&
                                           fpinfo->stage == UPPERREL_GROUP_AGG);
+
+                               /*
+                                * We can only get here when this function is called from
+                                * add_foreign_ordered_paths() or add_foreign_final_paths();
+                                * in which cases, the passed-in fpextra should not be NULL.
+                                */
+                               Assert(fpextra);
                                adjust_foreign_grouping_path_cost(root, pathkeys,
                                                                                                  retrieved_rows, width,
                                                                                                  fpextra->limit_tuples,