subplan resets wrong hashtable

Justin Pryzby <pryzby@telsasoft.com>

From: Justin Pryzby <pryzby@telsasoft.com>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2020-02-10T03:25:47Z
Lists: pgsql-hackers
I believe the 2nd hunk should reset node->hashnulls, rather than reset
->hashtable a 2nd time:

@@ -505,7 +505,10 @@ buildSubPlanHash(SubPlanState *node, ExprContext *econtext)
        if (nbuckets < 1)
                nbuckets = 1;
 
-       node->hashtable = BuildTupleHashTable(node->parent,
+       if (node->hashtable)
+               ResetTupleHashTable(node->hashtable);
+       else
+               node->hashtable = BuildTupleHashTableExt(node->parent,
                                                                                                 node->descRight,
                                                                                                 ncols,
                                                                                                 node->keyColIdx,
...

@@ -527,7 +531,11 @@ buildSubPlanHash(SubPlanState *node, ExprContext *econtext)
                        if (nbuckets < 1)
                                nbuckets = 1;
                }
-               node->hashnulls = BuildTupleHashTable(node->parent,
+
+               if (node->hashnulls)
+                       ResetTupleHashTable(node->hashtable);
+               else
+                       node->hashnulls = BuildTupleHashTableExt(node->parent,
                                                                                                         node->descRight,
                                                                                                         ncols,
                                                                                                         node->keyColIdx,

Added here:

commit 356687bd825e5ca7230d43c1bffe7a59ad2e77bd
Author: Andres Freund <andres@anarazel.de>
Date:   Sat Feb 9 00:35:57 2019 -0800

    Reset, not recreate, execGrouping.c style hashtables.



Commits

  1. Correctly re-use hash tables in buildSubPlanHash().

  2. Reset, not recreate, execGrouping.c style hashtables.