public inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH v12 2/6] introduce routine for checking mutually exclusive string GUCs
3+ messages / 3 participants
[nested] [flat]

* [PATCH v12 2/6] introduce routine for checking mutually exclusive string GUCs
@ 2023-02-15 22:28  Nathan Bossart <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: Nathan Bossart @ 2023-02-15 22:28 UTC (permalink / raw)

---
 src/backend/postmaster/pgarch.c |  8 +++-----
 src/backend/utils/misc/guc.c    | 22 ++++++++++++++++++++++
 src/include/utils/guc.h         |  3 +++
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 46af349564..d94730c50c 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -824,11 +824,9 @@ LoadArchiveLibrary(void)
 {
 	ArchiveModuleInit archive_init;
 
-	if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0')
-		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("both archive_command and archive_library set"),
-				 errdetail("Only one of archive_command, archive_library may be set.")));
+	(void) CheckMutuallyExclusiveStringGUCs(XLogArchiveLibrary, "archive_library",
+											XLogArchiveCommand, "archive_command",
+											ERROR);
 
 	/*
 	 * If shell archiving is enabled, use our special initialization function.
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 51e07d5582..e780438948 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -2610,6 +2610,28 @@ ReportGUCOption(struct config_generic *record)
 	pfree(val);
 }
 
+/*
+ * If both parameters are set, emits a log message at 'elevel' and returns
+ * false.  Otherwise, returns true.
+ */
+bool
+CheckMutuallyExclusiveStringGUCs(const char *p1val, const char *p1name,
+								 const char *p2val, const char *p2name,
+								 int elevel)
+{
+	if (p1val[0] != '\0' && p2val[0] != '\0')
+	{
+		ereport(elevel,
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				 errmsg("cannot set both %s and %s", p1name, p2name),
+				 errdetail("Only one of %s or %s may be set.",
+						   p1name, p2name)));
+		return false;
+	}
+
+	return true;
+}
+
 /*
  * Convert a value from one of the human-friendly units ("kB", "min" etc.)
  * to the given base unit.  'value' and 'unit' are the input value and unit
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index ba89d013e6..7346a3f1ea 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -372,6 +372,9 @@ extern int	NewGUCNestLevel(void);
 extern void AtEOXact_GUC(bool isCommit, int nestLevel);
 extern void BeginReportingGUCOptions(void);
 extern void ReportChangedGUCOptions(void);
+extern bool CheckMutuallyExclusiveStringGUCs(const char *p1val, const char *p1name,
+											 const char *p2val, const char *p2name,
+											 int elevel);
 extern void ParseLongOption(const char *string, char **name, char **value);
 extern const char *get_config_unit_name(int flags);
 extern bool parse_int(const char *value, int *result, int flags,
-- 
2.25.1


--YiEDa0DAkWCtVeE4
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v12-0003-refactor-code-for-restoring-via-shell.patch"



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Change the bool member of the Query structure to bits
@ 2024-02-20 15:45  Tom Lane <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2024-02-20 15:45 UTC (permalink / raw)
  To: Quan Zongliang <[email protected]>; +Cc: [email protected]

Quan Zongliang <[email protected]> writes:
> The Query structure has an increasing number of bool attributes. This is 
> likely to increase in the future. And they have the same properties. 
> Wouldn't it be better to store them in bits? Common statements don't use 
> them, so they have little impact. This also saves memory space.

I'm -1 on that, for three reasons:

* The amount of space saved is quite negligible.  If queries had many
Query structs then it could matter, but they don't.

* This causes enough code churn to create a headache for back-patching.

* This'll completely destroy the readability of these flags in
pprint output.

I'm not greatly in love with the macro layer you propose, either,
but those details don't matter because I think we should just
leave well enough alone.

			regards, tom lane






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Change the bool member of the Query structure to bits
@ 2024-02-20 23:45  Quan Zongliang <[email protected]>
  parent: Tom Lane <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: Quan Zongliang @ 2024-02-20 23:45 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: [email protected]



On 2024/2/20 23:45, Tom Lane wrote:
> Quan Zongliang <[email protected]> writes:
>> The Query structure has an increasing number of bool attributes. This is
>> likely to increase in the future. And they have the same properties.
>> Wouldn't it be better to store them in bits? Common statements don't use
>> them, so they have little impact. This also saves memory space.
> 
> I'm -1 on that, for three reasons:
> 
> * The amount of space saved is quite negligible.  If queries had many
> Query structs then it could matter, but they don't.
> 
> * This causes enough code churn to create a headache for back-patching.
> 
> * This'll completely destroy the readability of these flags in
> pprint output.
> 
> I'm not greatly in love with the macro layer you propose, either,
> but those details don't matter because I think we should just
> leave well enough alone.
> 
> 			regards, tom lane
I get it. Withdraw.







^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2024-02-20 23:45 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15 22:28 [PATCH v12 2/6] introduce routine for checking mutually exclusive string GUCs Nathan Bossart <[email protected]>
2024-02-20 15:45 Re: Change the bool member of the Query structure to bits Tom Lane <[email protected]>
2024-02-20 23:45 ` Re: Change the bool member of the Query structure to bits Quan Zongliang <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox