OSDN Git Service

Make HashJoin hint more coercive.
authorKyotaro Horiguchi <horikyoga.ntt@gmail.com>
Wed, 28 Oct 2020 06:50:58 +0000 (15:50 +0900)
committerKyotaro Horiguchi <horikyoga.ntt@gmail.com>
Thu, 29 Oct 2020 12:03:05 +0000 (21:03 +0900)
Even with HashJoin hint, hash joins may be rejected by planner if hash
table for the inner-rel is estimated too large.  Make HashJoin hint
more coercive by increasing hash_mem_multiplier.

pg_hint_plan.c

index 29e3e6a..048e85b 100644 (file)
@@ -2777,6 +2777,31 @@ set_join_config_options(unsigned char enforce_mask, GucContext context)
        SET_CONFIG_OPTION("enable_nestloop", ENABLE_NESTLOOP);
        SET_CONFIG_OPTION("enable_mergejoin", ENABLE_MERGEJOIN);
        SET_CONFIG_OPTION("enable_hashjoin", ENABLE_HASHJOIN);
+
+       /*
+        * Hash join may be rejected for the reason of estimated memory usage. Try
+        * getting rid of that limitation.
+        */
+       if (enforce_mask == ENABLE_HASHJOIN)
+       {
+               char                    buf[32];
+               int                             new_multipler;
+
+               /* See final_cost_hashjoin(). */
+               new_multipler = MAX_KILOBYTES / work_mem;
+
+               /* See guc.c for the upper limit */
+               if (new_multipler >= 1000)
+                       new_multipler = 1000;
+
+               if (new_multipler > hash_mem_multiplier)
+               {
+                       snprintf(buf, sizeof(buf), UINT64_FORMAT, (uint64)new_multipler);
+                       set_config_option_noerror("hash_mem_multiplier", buf,
+                                                                         context, PGC_S_SESSION, GUC_ACTION_SAVE,
+                                                                         true, ERROR);
+               }
+       }
 }
 
 /*