Re: [HACKERS] parallelize queries containing subplans - Mailing list pgsql-hackers

From Robert Haas
Subject Re: [HACKERS] parallelize queries containing subplans
Date
Msg-id CA+Tgmob+huYGMwL9ta+Wrgk1FuiKyjiSFNRE4nM4BSj8hBipeA@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] parallelize queries containing subplans  (Amit Kapila <amit.kapila16@gmail.com>)
Responses Re: [HACKERS] parallelize queries containing subplans  (Amit Kapila <amit.kapila16@gmail.com>)
List pgsql-hackers
On Tue, Jan 31, 2017 at 6:01 AM, Amit Kapila <amit.kapila16@gmail.com> wrote:
> Moved this patch to next CF.

So here is what seems to be the key hunk from this patch:
    /*
-     * Since we don't have the ability to push subplans down to workers at
-     * present, we treat subplan references as parallel-restricted.  We need
-     * not worry about examining their contents; if they are unsafe, we would
-     * have found that out while examining the whole tree before reduction of
-     * sublinks to subplans.  (Really we should not see SubLink during a
-     * max_interesting == restricted scan, but if we do, return true.)
+     * We can push the subplans only if they don't contain any parallel-aware
+     * node as we don't support multi-level parallelism (parallel workers
+     * invoking another set of parallel workers).     */
-    else if (IsA(node, SubLink) ||
-             IsA(node, SubPlan) ||
-             IsA(node, AlternativeSubPlan))
+    else if (IsA(node, SubPlan))
+        return !((SubPlan *) node)->parallel_safe;
+    else if (IsA(node, AlternativeSubPlan))    {
-        if (max_parallel_hazard_test(PROPARALLEL_RESTRICTED, context))
-            return true;
+        AlternativeSubPlan *asplan = (AlternativeSubPlan *) node;
+        ListCell   *lc;
+
+        foreach(lc, asplan->subplans)
+        {
+            SubPlan    *splan = (SubPlan *) lfirst(lc);
+
+            Assert(IsA(splan, SubPlan));
+
+            if (max_parallel_hazard_walker((Node *) splan, context))
+                return true;
+        }
+
+        return false;    }

I don't see the reason for having this new code that makes
AlternativeSubPlan walk over the subplans; expression_tree_walker
already does that.  On the flip side I don't see the reason for
removing the max_parallel_hazard_test() call for AlternativeSubPlan or
for SubLink.  I think that the core of this change is to change the
handling for SubPlan nodes to just return the flag from the subplan,
and that seems fine, but the rest of this I'm skeptical about.

+                * CTE scans are not consider for parallelism (cf


considered

+       select count(*)from tenk1 where (two, four) not in

whitespace

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] Improvements in psql hooks for variables
Next
From: Fujii Masao
Date:
Subject: Re: [HACKERS] Cannot shutdown subscriber after DROP SUBSCRIPTION