1515
1616#include "catalog/pg_authid.h"
1717#include "commands/explain.h"
18+ #if PG_VERSION_NUM >= 180000
19+ #include "commands/explain_state.h"
20+ #include "commands/explain_format.h"
21+ #endif
1822#include "fmgr.h"
1923#include "funcapi.h"
2024#include "lib/stringinfo.h"
@@ -103,10 +107,20 @@ static void pgsp_shmem_request(void);
103107#endif
104108static void pgsp_shmem_startup (void );
105109/* Saves query plans to the shared hash table. */
106- static void pgsp_ExecutorStart (QueryDesc * queryDesc , int eflags );
110+ static
111+ #if PG_VERSION_NUM < 180000
112+ void
113+ #else
114+ bool
115+ #endif
116+ pgsp_ExecutorStart (QueryDesc * queryDesc , int eflags );
107117/* Keeps track of the nest level. */
108118static void pgsp_ExecutorRun (QueryDesc * queryDesc , ScanDirection direction ,
109- uint64 count , bool execute_once );
119+ uint64 count
120+ #if PG_VERSION_NUM < 180000
121+ , bool execute_once
122+ #endif
123+ );
110124
111125/* Show query plans of all the currently running statements. */
112126Datum pg_show_plans (PG_FUNCTION_ARGS );
@@ -455,26 +469,44 @@ pgsp_shmem_startup(void)
455469 LWLockRelease (AddinShmemInitLock );
456470}
457471
458- static void
472+ static
473+ #if PG_VERSION_NUM < 180000
474+ void
475+ #else
476+ bool
477+ #endif
459478pgsp_ExecutorStart (QueryDesc * queryDesc , int eflags )
460479{
461480 ExplainState * es ;
481+ #if PG_VERSION_NUM >= 180000
482+ bool ret_val ;
483+ #endif
462484
463485 if (prev_ExecutorStart )
486+ {
487+ #if PG_VERSION_NUM >= 180000
488+ ret_val =
489+ #endif
464490 prev_ExecutorStart (queryDesc , eflags );
491+ }
465492 else
493+ {
494+ #if PG_VERSION_NUM >= 180000
495+ ret_val =
496+ #endif
466497 standard_ExecutorStart (queryDesc , eflags );
498+ }
467499
468500 if (!ensure_cached ()) {
469501 ereport (WARNING ,
470502 errcode (ERRCODE_OUT_OF_MEMORY ),
471503 errmsg ("not enough memory to append new query plans" ),
472504 errhint ("Try increasing 'pg_show_plans.max_plan_length'." ));
473- return ;
505+ return ret_val ;
474506 }
475507
476508 if (!pgsp -> is_enabled )
477- return ;
509+ return ret_val ;
478510
479511 es = NewExplainState ();
480512 es -> format = pgsp -> plan_format ;
@@ -484,20 +516,35 @@ pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags)
484516
485517 append_query_plan (es );
486518 pfree (es -> str -> data );
519+
520+ return ret_val ;
487521}
488522
489523static void
490524pgsp_ExecutorRun (QueryDesc * queryDesc , ScanDirection direction ,
491- uint64 count , bool execute_once )
525+ uint64 count
526+ #if PG_VERSION_NUM < 180000
527+ , bool execute_once
528+ #endif
529+ )
492530{
493531 nest_level ++ ;
494532 PG_TRY ();
495533 {
496534 /* These functions return *after* the nested quries do. */
497535 if (prev_ExecutorRun )
498- prev_ExecutorRun (queryDesc , direction , count , execute_once );
536+ prev_ExecutorRun (queryDesc , direction , count
537+ #if PG_VERSION_NUM < 180000
538+ , execute_once );
539+ #else
540+ );
541+ #endif
499542 else
500- standard_ExecutorRun (queryDesc , direction , count , execute_once );
543+ standard_ExecutorRun (queryDesc , direction , count
544+ #if PG_VERSION_NUM < 180000
545+ , execute_once
546+ #endif
547+ );
501548
502549 nest_level -- ;
503550 /* Wait for reading to complete, then delete. */
0 commit comments