Refactor the checks for parameterized partial paths
authorRichard Guo <[email protected]>
Tue, 30 Jul 2024 06:49:44 +0000 (15:49 +0900)
committerRichard Guo <[email protected]>
Tue, 30 Jul 2024 06:49:44 +0000 (15:49 +0900)
Parameterized partial paths are not supported, and we have several
checks in try_partial_xxx_path functions to enforce this.  For a
partial nestloop join path, we need to ensure that if the inner path
is parameterized, the parameterization is fully satisfied by the
proposed outer path.  For a partial merge/hashjoin join path, we need
to ensure that the inner path is not parameterized.  In all cases, we
need to ensure that the outer path is not parameterized.

However, the comment in try_partial_hashjoin_path does not describe
this correctly.  This patch fixes that.

In addtion, this patch simplifies the checks peformed in
try_partial_hashjoin_path and try_partial_mergejoin_path with the help
of macro PATH_REQ_OUTER, and also adds asserts that the outer path is
not parameterized in try_partial_xxx_path functions.

Author: Richard Guo
Discussion: https://postgr.es/m/CAMbWs48mKJ6g_GnYNa7dnw04MHaMK-jnAEBrMVhTp2uUg3Ut4A@mail.gmail.com

src/backend/optimizer/path/joinpath.c

index 0367e1aacdb88fb3b5e897aa758acbfb03bfb74f..e858f596005532257761b71252eef08ce337aca0 100644 (file)
@@ -961,6 +961,7 @@ try_partial_nestloop_path(PlannerInfo *root,
     * rels are required here.
     */
    Assert(bms_is_empty(joinrel->lateral_relids));
+   Assert(bms_is_empty(PATH_REQ_OUTER(outer_path)));
    if (inner_path->param_info != NULL)
    {
        Relids      inner_paramrels = inner_path->param_info->ppi_req_outer;
@@ -1144,13 +1145,9 @@ try_partial_mergejoin_path(PlannerInfo *root,
     * See comments in try_partial_hashjoin_path().
     */
    Assert(bms_is_empty(joinrel->lateral_relids));
-   if (inner_path->param_info != NULL)
-   {
-       Relids      inner_paramrels = inner_path->param_info->ppi_req_outer;
-
-       if (!bms_is_empty(inner_paramrels))
-           return;
-   }
+   Assert(bms_is_empty(PATH_REQ_OUTER(outer_path)));
+   if (!bms_is_empty(PATH_REQ_OUTER(inner_path)))
+       return;
 
    /*
     * If the given paths are already well enough ordered, we can skip doing
@@ -1286,19 +1283,14 @@ try_partial_hashjoin_path(PlannerInfo *root,
    JoinCostWorkspace workspace;
 
    /*
-    * If the inner path is parameterized, the parameterization must be fully
-    * satisfied by the proposed outer path.  Parameterized partial paths are
-    * not supported.  The caller should already have verified that no lateral
-    * rels are required here.
+    * If the inner path is parameterized, we can't use a partial hashjoin.
+    * Parameterized partial paths are not supported.  The caller should
+    * already have verified that no lateral rels are required here.
     */
    Assert(bms_is_empty(joinrel->lateral_relids));
-   if (inner_path->param_info != NULL)
-   {
-       Relids      inner_paramrels = inner_path->param_info->ppi_req_outer;
-
-       if (!bms_is_empty(inner_paramrels))
-           return;
-   }
+   Assert(bms_is_empty(PATH_REQ_OUTER(outer_path)));
+   if (!bms_is_empty(PATH_REQ_OUTER(inner_path)))
+       return;
 
    /*
     * Before creating a path, get a quick lower bound on what it is likely to