Prevent Parallel Hash Join for JOIN_UNIQUE_INNER.
authorThomas Munro
Tue, 18 Jun 2019 10:38:30 +0000 (22:38 +1200)
committerThomas Munro
Tue, 18 Jun 2019 13:25:57 +0000 (01:25 +1200)
WHERE EXISTS (...) queries cannot be executed by Parallel Hash Join
with jointype JOIN_UNIQUE_INNER, because there is no way to make a
partial plan totally unique.  The consequence of allowing such plans
was duplicate results from some EXISTS queries.

Back-patch to 11.  Bug #15857.

Author: Thomas Munro
Reviewed-by: Tom Lane
Reported-by: Vladimir Kriukov
Discussion: https://postgr.es/m/15857-d1ba2a64bce0795e%40postgresql.org

src/backend/optimizer/path/joinpath.c

index 501ad775cbe9ce05fcbc182e21cd30e22883d403..dc28b56e7427e13aa5db455d840f1bfcea6565a3 100644 (file)
@@ -1867,9 +1867,12 @@ hash_inner_and_outer(PlannerInfo *root,
 
            /*
             * Can we use a partial inner plan too, so that we can build a
-            * shared hash table in parallel?
+            * shared hash table in parallel?  We can't handle
+            * JOIN_UNIQUE_INNER because we can't guarantee uniqueness.
             */
-           if (innerrel->partial_pathlist != NIL && enable_parallel_hash)
+           if (innerrel->partial_pathlist != NIL &&
+               save_jointype != JOIN_UNIQUE_INNER &&
+               enable_parallel_hash)
            {
                cheapest_partial_inner =
                    (Path *) linitial(innerrel->partial_pathlist);