Fix broken MemoizePath support in reparameterize_path().
authorTom Lane
Sun, 4 Dec 2022 18:48:12 +0000 (13:48 -0500)
committerTom Lane
Sun, 4 Dec 2022 18:48:12 +0000 (13:48 -0500)
It neglected to recurse to the subpath, meaning you'd get back
a path identical to the input.  This could produce wrong query
results if the omission meant that the subpath fails to enforce
some join clause it should be enforcing.  We don't have a test
case for this at the moment, but the code is obviously broken
and the fix is equally obvious.  Back-patch to v14 where
Memoize was introduced.

Richard Guo

Discussion: https://postgr.es/m/CAMbWs4_R=ORpz=Lkn2q3ebPC5EuWyfZF+tmfCPVLBVK5W39mHA@mail.gmail.com

src/backend/optimizer/util/pathnode.c

index ad3070352f02541d15a483038215c6fff84764f8..a3880c7624c78a045e5f9ce542880657f18888b5 100644 (file)
@@ -3937,9 +3937,15 @@ reparameterize_path(PlannerInfo *root, Path *path,
        case T_Memoize:
            {
                MemoizePath *mpath = (MemoizePath *) path;
+               Path       *spath = mpath->subpath;
 
+               spath = reparameterize_path(root, spath,
+                                           required_outer,
+                                           loop_count);
+               if (spath == NULL)
+                   return NULL;
                return (Path *) create_memoize_path(root, rel,
-                                                   mpath->subpath,
+                                                   spath,
                                                    mpath->param_exprs,
                                                    mpath->hash_operators,
                                                    mpath->singlerow,