Fix mistakes in commit 4020b370f214315b8c10430301898ac21658143f master github/master
authorRobert Haas <rhaas@postgresql.org>
Thu, 29 Jan 2026 13:04:23 +0000 (08:04 -0500)
committerRobert Haas <rhaas@postgresql.org>
Thu, 29 Jan 2026 13:04:47 +0000 (08:04 -0500)
cost_tidrangescan() was setting the disabled_nodes value correctly,
and then immediately resetting it to zero, due to poor code editing on
my part.

materialized_finished_plan correctly set matpath.parent to
zero, but forgot to also set matpath.parallel_workers = 0, causing
an access to uninitialized memory in cost_material. (This shouldn't
result in any real problem, but it makes valgrind unhappy.)

reparameterize_path was dereferencing a variable before verifying that
it was not NULL.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us> (issue #1)
Reported-by: Michael Paquier <michael@paquier.xyz> (issue #1)
Diagnosed-by: Lukas Fittl <lukas@fittl.com> (issue #1)
Reported-by: Zsolt Parragi <zsolt.parragi@percona.com> (issue #2)
Reported-by: Richard Guo <guofenglinux@gmail.com> (issue #3)
Discussion: http://postgr.es/m/CAN4CZFPvwjNJEZ_JT9Y67yR7C=KMNa=LNefOB8ZY7TKDcmAXOA@mail.gmail.com
Discussion: http://postgr.es/m/aXrnPgrq6Gggb5TG@paquier.xyz

src/backend/optimizer/path/costsize.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/util/pathnode.c

index 4da0b17f137ee4a11a4623d0039f4927704160c8..c30d6e84672f0d27eae1923983ea3af0d46191df 100644 (file)
@@ -1461,7 +1461,6 @@ cost_tidrangescan(Path *path, PlannerInfo *root,
        enable_mask |= PGS_CONSIDER_NONPARTIAL;
    path->disabled_nodes =
        (baserel->pgs_mask & enable_mask) != enable_mask ? 1 : 0;
-   path->disabled_nodes = 0;
    path->startup_cost = startup_cost;
    path->total_cost = startup_cost + cpu_run_cost + disk_run_cost;
 }
index c26e841f537fc015478f6736c325f02bc613ddff..e5200f4b3ced3e39f082eeb80de6cc83002346fa 100644 (file)
@@ -6526,8 +6526,11 @@ materialize_finished_plan(Plan *subplan)
    subplan->startup_cost -= initplan_cost;
    subplan->total_cost -= initplan_cost;
 
-   /* Set cost data */
+   /* Clear fields that cost_material() will consult */
+   matpath.parallel_workers = 0;
    matpath.parent = NULL;
+
+   /* Set cost data */
    cost_material(&matpath,
                  enable_material,
                  subplan->disabled_nodes,
index 7295438ad2057c619998554ca9c4dd145349e0b2..7b6c5d51e5d6b03cebb27126b19b2b854931377e 100644 (file)
@@ -3971,10 +3971,10 @@ reparameterize_path(PlannerInfo *root, Path *path,
                spath = reparameterize_path(root, spath,
                                            required_outer,
                                            loop_count);
-               enabled =
-                   (mpath->path.disabled_nodes <= spath->disabled_nodes);
                if (spath == NULL)
                    return NULL;
+               enabled =
+                   (mpath->path.disabled_nodes <= spath->disabled_nodes);
                return (Path *) create_material_path(rel, spath, enabled);
            }
        case T_Memoize: