Improve ExplainState type handling in header files
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 15 Sep 2025 08:48:30 +0000 (10:48 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 15 Sep 2025 09:04:10 +0000 (11:04 +0200)
Now that we can have repeat typedefs with C11, we don't need to use
"struct ExplainState" anymore but can instead make a typedef where
necessary.  This doesn't change anything but makes it look nicer.

(There are more opportunities for similar changes, but this is broken
out because there was a separate discussion about it, and it's
somewhat bulky on its own.)

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/f36c0a45-98cd-40b2-a7cc-f2bf02b12890%40eisentraut.org#a12fb1a2c1089d6d03010f6268871b00
Discussion: https://www.postgresql.org/message-id/flat/10d32190-f31b-40a5-b177-11db55597355@eisentraut.org

doc/src/sgml/fdwhandler.sgml
src/include/commands/explain.h
src/include/commands/explain_dr.h
src/include/commands/explain_format.h
src/include/commands/explain_state.h
src/include/foreign/fdwapi.h

index b80320504d6951778da71a33c8130cf9cdfff993..c6d66414b8ea70c5ef78e26bbbf69e4be90b43ec 100644 (file)
@@ -1320,7 +1320,7 @@ ExplainForeignModify(ModifyTableState *mtstate,
                      ResultRelInfo *rinfo,
                      List *fdw_private,
                      int subplan_index,
-                     struct ExplainState *es);
+                     ExplainState *es);
 </programlisting>
 
      Print additional <command>EXPLAIN</command> output for a foreign table update.
index 3b122f79ed84877322baff1543275de9e823d42c..6e51d50efc73dfc8a65cdf95d35aba3d685165f8 100644 (file)
 #include "executor/executor.h"
 #include "parser/parse_node.h"
 
-struct ExplainState;           /* defined in explain_state.h */
+typedef struct ExplainState ExplainState;  /* defined in explain_state.h */
 
 /* Hook for plugins to get control in ExplainOneQuery() */
 typedef void (*ExplainOneQuery_hook_type) (Query *query,
                                           int cursorOptions,
                                           IntoClause *into,
-                                          struct ExplainState *es,
+                                          ExplainState *es,
                                           const char *queryString,
                                           ParamListInfo params,
                                           QueryEnvironment *queryEnv);
@@ -31,7 +31,7 @@ extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook;
 /* Hook for EXPLAIN plugins to print extra information for each plan */
 typedef void (*explain_per_plan_hook_type) (PlannedStmt *plannedstmt,
                                            IntoClause *into,
-                                           struct ExplainState *es,
+                                           ExplainState *es,
                                            const char *queryString,
                                            ParamListInfo params,
                                            QueryEnvironment *queryEnv);
@@ -42,7 +42,7 @@ typedef void (*explain_per_node_hook_type) (PlanState *planstate,
                                            List *ancestors,
                                            const char *relationship,
                                            const char *plan_name,
-                                           struct ExplainState *es);
+                                           ExplainState *es);
 extern PGDLLIMPORT explain_per_node_hook_type explain_per_node_hook;
 
 /* Hook for plugins to get control in explain_get_index_name() */
@@ -53,32 +53,32 @@ extern PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook;
 extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
                         ParamListInfo params, DestReceiver *dest);
 extern void standard_ExplainOneQuery(Query *query, int cursorOptions,
-                                    IntoClause *into, struct ExplainState *es,
+                                    IntoClause *into, ExplainState *es,
                                     const char *queryString, ParamListInfo params,
                                     QueryEnvironment *queryEnv);
 
 extern TupleDesc ExplainResultDesc(ExplainStmt *stmt);
 
 extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into,
-                             struct ExplainState *es, ParseState *pstate,
+                             ExplainState *es, ParseState *pstate,
                              ParamListInfo params);
 
 extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
-                          struct ExplainState *es, const char *queryString,
+                          ExplainState *es, const char *queryString,
                           ParamListInfo params, QueryEnvironment *queryEnv,
                           const instr_time *planduration,
                           const BufferUsage *bufusage,
                           const MemoryContextCounters *mem_counters);
 
-extern void ExplainPrintPlan(struct ExplainState *es, QueryDesc *queryDesc);
-extern void ExplainPrintTriggers(struct ExplainState *es,
+extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
+extern void ExplainPrintTriggers(ExplainState *es,
                                 QueryDesc *queryDesc);
 
-extern void ExplainPrintJITSummary(struct ExplainState *es,
+extern void ExplainPrintJITSummary(ExplainState *es,
                                   QueryDesc *queryDesc);
 
-extern void ExplainQueryText(struct ExplainState *es, QueryDesc *queryDesc);
-extern void ExplainQueryParameters(struct ExplainState *es,
+extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
+extern void ExplainQueryParameters(ExplainState *es,
                                   ParamListInfo params, int maxlen);
 
 #endif                         /* EXPLAIN_H */
index 55da63d66bdf6fa35a1acbf6a7cafd44b728cbd8..b62f1f8542cb56c8b6b1b06cc1c85a5fabd66c56 100644 (file)
@@ -16,7 +16,8 @@
 #include "executor/instrument.h"
 #include "tcop/dest.h"
 
-struct ExplainState;           /* avoid including explain.h here */
+/* avoid including explain_state.h here */
+typedef struct ExplainState ExplainState;
 
 /* Instrumentation data for EXPLAIN's SERIALIZE option */
 typedef struct SerializeMetrics
@@ -26,7 +27,7 @@ typedef struct SerializeMetrics
    BufferUsage bufferUsage;    /* buffers accessed during serialization */
 } SerializeMetrics;
 
-extern DestReceiver *CreateExplainSerializeDestReceiver(struct ExplainState *es);
+extern DestReceiver *CreateExplainSerializeDestReceiver(ExplainState *es);
 extern SerializeMetrics GetSerializationMetrics(DestReceiver *dest);
 
 #endif
index 05045bf8cb4af3150c77ecdb9e35af84914e8f68..f849a3938ce994275cb89afb00c6043c8e13c438 100644 (file)
 
 #include "nodes/pg_list.h"
 
-struct ExplainState;           /* avoid including explain.h here */
+/* avoid including explain_state.h here */
+typedef struct ExplainState ExplainState;
 
 extern void ExplainPropertyList(const char *qlabel, List *data,
-                               struct ExplainState *es);
+                               ExplainState *es);
 extern void ExplainPropertyListNested(const char *qlabel, List *data,
-                                     struct ExplainState *es);
+                                     ExplainState *es);
 extern void ExplainPropertyText(const char *qlabel, const char *value,
-                               struct ExplainState *es);
+                               ExplainState *es);
 extern void ExplainPropertyInteger(const char *qlabel, const char *unit,
-                                  int64 value, struct ExplainState *es);
+                                  int64 value, ExplainState *es);
 extern void ExplainPropertyUInteger(const char *qlabel, const char *unit,
-                                   uint64 value, struct ExplainState *es);
+                                   uint64 value, ExplainState *es);
 extern void ExplainPropertyFloat(const char *qlabel, const char *unit,
                                 double value, int ndigits,
-                                struct ExplainState *es);
+                                ExplainState *es);
 extern void ExplainPropertyBool(const char *qlabel, bool value,
-                               struct ExplainState *es);
+                               ExplainState *es);
 
 extern void ExplainOpenGroup(const char *objtype, const char *labelname,
-                            bool labeled, struct ExplainState *es);
+                            bool labeled, ExplainState *es);
 extern void ExplainCloseGroup(const char *objtype, const char *labelname,
-                             bool labeled, struct ExplainState *es);
+                             bool labeled, ExplainState *es);
 
 extern void ExplainOpenSetAsideGroup(const char *objtype, const char *labelname,
                                     bool labeled, int depth,
-                                    struct ExplainState *es);
-extern void ExplainSaveGroup(struct ExplainState *es, int depth,
+                                    ExplainState *es);
+extern void ExplainSaveGroup(ExplainState *es, int depth,
                             int *state_save);
-extern void ExplainRestoreGroup(struct ExplainState *es, int depth,
+extern void ExplainRestoreGroup(ExplainState *es, int depth,
                                int *state_save);
 
 extern void ExplainDummyGroup(const char *objtype, const char *labelname,
-                             struct ExplainState *es);
+                             ExplainState *es);
 
-extern void ExplainBeginOutput(struct ExplainState *es);
-extern void ExplainEndOutput(struct ExplainState *es);
-extern void ExplainSeparatePlans(struct ExplainState *es);
+extern void ExplainBeginOutput(ExplainState *es);
+extern void ExplainEndOutput(ExplainState *es);
+extern void ExplainSeparatePlans(ExplainState *es);
 
-extern void ExplainIndentText(struct ExplainState *es);
+extern void ExplainIndentText(ExplainState *es);
 
 #endif
index 32728f5d1a1759acc5db196f9b4c3d79b4646b18..ba073b86918d514f3e119264af9573ae4d91e716 100644 (file)
@@ -79,7 +79,7 @@ typedef struct ExplainState
 typedef void (*ExplainOptionHandler) (ExplainState *, DefElem *, ParseState *);
 
 /* Hook to perform additional EXPLAIN options validation */
-typedef void (*explain_validate_options_hook_type) (struct ExplainState *es, List *options,
+typedef void (*explain_validate_options_hook_type) (ExplainState *es, List *options,
                                                    ParseState *pstate);
 extern PGDLLIMPORT explain_validate_options_hook_type explain_validate_options_hook;
 
index b4da4e6a16aacce2845bba8b26dc87a591919810..fcd7e7027f3b614253ac81b0ec9926988ff52903 100644 (file)
@@ -16,8 +16,8 @@
 #include "nodes/execnodes.h"
 #include "nodes/pathnodes.h"
 
-/* To avoid including explain.h here, reference ExplainState thus: */
-struct ExplainState;
+/* avoid including explain_state.h here */
+typedef struct ExplainState ExplainState;
 
 
 /*
@@ -137,16 +137,16 @@ typedef void (*RefetchForeignRow_function) (EState *estate,
                                            bool *updated);
 
 typedef void (*ExplainForeignScan_function) (ForeignScanState *node,
-                                            struct ExplainState *es);
+                                            ExplainState *es);
 
 typedef void (*ExplainForeignModify_function) (ModifyTableState *mtstate,
                                               ResultRelInfo *rinfo,
                                               List *fdw_private,
                                               int subplan_index,
-                                              struct ExplainState *es);
+                                              ExplainState *es);
 
 typedef void (*ExplainDirectModify_function) (ForeignScanState *node,
-                                             struct ExplainState *es);
+                                             ExplainState *es);
 
 typedef int (*AcquireSampleRowsFunc) (Relation relation, int elevel,
                                      HeapTuple *rows, int targrows,