Subject: Replace (GUC_UNIT_MEMORY | GUC_UNIT_TIME) with GUC_UNIT in guc.c

From: Japin Li <[email-masked]>
Date: Wed, 14 Jun 2023 11:33:06 +0800

Hi, hackers

We use (GUC_UNIT_MEMORY | GUC_UNIT_TIME) instead of GUC_UNIT even though we
already define it in guc.h.

Maybe using GUC_UNIT is better?  Here is a patch to fix it.

diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index a9033b7a54..5308896c87 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -2766,7 +2766,7 @@ convert_real_from_base_unit(double base_value, int base_unit,
 const char *
 get_config_unit_name(int flags)
 {
-    switch (flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
+    switch (flags & GUC_UNIT)
     {
         case 0:
             return NULL;        /* GUC has no units */
@@ -2802,7 +2802,7 @@ get_config_unit_name(int flags)
             return "min";
         default:
             elog(ERROR, "unrecognized GUC units value: %d",
-                 flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
+                 flags & GUC_UNIT);
             return NULL;
     }
 }
 
-- 
Regrads,
Japin Li.

---

From: Masahiko Sawada <[email-masked]>
Date: Wed, 14 Jun 2023 14:06:26 +0900

> Maybe using GUC_UNIT is better?  Here is a patch to fix it.

Yeah, it seems more consistent with other places in guc.c. I'll push
it, barring any objections.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

---

From: Richard Guo <[email-masked]>
Date: Wed, 14 Jun 2023 15:38:10 +0800

> it, barring any objections.

+1.  BTW, it seems that GUC_UNIT_TIME is not used anywhere except in
GUC_UNIT.  I was wondering if we can retire it, but maybe we'd better
not.  It still indicates that we need to use time units table.

Thanks
Richard

---

From: Michael Paquier <[email-masked]>
Date: Wed, 14 Jun 2023 16:47:45 +0900

> not.  It still indicates that we need to use time units table.

Some out-of-core code declaring custom GUCs could rely on that, so
it is better not to remove it.
--
Michael

---

From: Masahiko Sawada <[email-masked]>
Date: Thu, 15 Jun 2023 11:02:07 +0900

> it is better not to remove it.

+1 not to remove it.

I've attached the patch to fix  (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
thing, and am going to push it later today to only master branch.

Regards,