From 10135db80e674e2f0dfe83e4ac3231ea7c9ff987 Mon Sep 17 00:00:00 2001
From: Sami Imseih <simseih@amazon.com>
Date: Tue, 18 Mar 2025 13:17:19 -0400
Subject: [PATCH v1 1/1] Add new hooks for performing additional EXPLAIN
 options validation

c65bc2e1d1 made it possible for loadable modules to define EXPLAIN
options. This patch introduces a new hook to allow a module to
perform validation of options against other options.

Discussion: https://www.postgresql.org/message-id/CAA5RZ0tM8jEe_LSjjrTux9TbTpLex-PFQtSuVcfXCWT%3DN%2Bthug%40mail.gmail.com
---
 src/backend/commands/explain_state.c | 7 +++++++
 src/include/commands/explain.h       | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/src/backend/commands/explain_state.c b/src/backend/commands/explain_state.c
index 1d4be3c18ac..783004b3a05 100644
--- a/src/backend/commands/explain_state.c
+++ b/src/backend/commands/explain_state.c
@@ -37,6 +37,9 @@
 #include "commands/explain.h"
 #include "commands/explain_state.h"
 
+/* Hook to perform additional EXPLAIN options validation */
+explain_validate_options_hook_type explain_validate_options_hook = NULL;
+
 typedef struct
 {
 	const char *option_name;
@@ -196,6 +199,10 @@ ParseExplainOptionList(ExplainState *es, List *options, ParseState *pstate)
 
 	/* if the summary was not set explicitly, set default value */
 	es->summary = (summary_set) ? es->summary : es->analyze;
+
+	/* plugin specific option validation */
+	if (explain_validate_options_hook)
+		(*explain_validate_options_hook)(es);
 }
 
 /*
diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h
index 387839eb5d2..26b29677967 100644
--- a/src/include/commands/explain.h
+++ b/src/include/commands/explain.h
@@ -49,6 +49,14 @@ extern PGDLLIMPORT explain_per_node_hook_type explain_per_node_hook;
 typedef const char *(*explain_get_index_name_hook_type) (Oid indexId);
 extern PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook;
 
+/*
+ * Hook to perform additional EXPLAIN options validation.
+ *
+ * Returns void as we expect the plugin to throw an error when
+ * a validation fails.
+ */
+typedef void (*explain_validate_options_hook_type) (struct ExplainState *es);
+extern PGDLLIMPORT explain_validate_options_hook_type explain_validate_options_hook;
 
 extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
 						 ParamListInfo params, DestReceiver *dest);
-- 
2.39.5 (Apple Git-154)

