diff --git a/.github/workflows/installcheck.yml b/.github/workflows/installcheck.yml
index aa35197..b339a0a 100644
--- a/.github/workflows/installcheck.yml
+++ b/.github/workflows/installcheck.yml
@@ -16,6 +16,7 @@ jobs:
strategy:
matrix:
pgversion:
+ - 18
- 17
- 16
- 15
diff --git a/expected/formats_1.out b/expected/formats_1.out
index 32ecd28..0782565 100644
--- a/expected/formats_1.out
+++ b/expected/formats_1.out
@@ -2,7 +2,7 @@
select setting::int < 140000 as pg12_13 from pg_settings where name = 'server_version_num';
pg12_13
---------
- t
+ f
(1 row)
-- json output
@@ -20,24 +20,28 @@ select * from nest();
| "Plan": { +
| "Node Type": "Function Scan", +
| "Parallel Aware": false, +
+ | "Async Capable": false, +
| "Function Name": "nest", +
| "Alias": "nest", +
| "Startup Cost": 0.25, +
| "Total Cost": 10.25, +
| "Plan Rows": 1000, +
- | "Plan Width": 36 +
+ | "Plan Width": 36, +
+ | "Disabled": false +
| } +
| ]
1 | [ +
| "Plan": { +
| "Node Type": "Function Scan", +
| "Parallel Aware": false, +
+ | "Async Capable": false, +
| "Function Name": "pg_show_plans",+
| "Alias": "pg_show_plans", +
| "Startup Cost": 0.00, +
| "Total Cost": 12.50, +
| "Plan Rows": 333, +
| "Plan Width": 36, +
+ | "Disabled": false, +
| "Filter": "(level >= 0)" +
| } +
| ]
@@ -57,21 +61,25 @@ select * from nest();
0 | Plan: +
| Node Type: "Function Scan" +
| Parallel Aware: false +
+ | Async Capable: false +
| Function Name: "nest" +
| Alias: "nest" +
| Startup Cost: 0.25 +
| Total Cost: 10.25 +
| Plan Rows: 1000 +
- | Plan Width: 36
+ | Plan Width: 36 +
+ | Disabled: false
1 | Plan: +
| Node Type: "Function Scan" +
| Parallel Aware: false +
+ | Async Capable: false +
| Function Name: "pg_show_plans"+
| Alias: "pg_show_plans" +
| Startup Cost: 0.00 +
| Total Cost: 12.50 +
| Plan Rows: 333 +
| Plan Width: 36 +
+ | Disabled: false +
| Filter: "(level >= 0)"
(2 rows)
@@ -90,24 +98,28 @@ select * from nest();
| +
| Function Scan +
| false +
+ | false +
| nest +
| nest +
| 0.25 +
| 10.25 +
| 1000 +
| 36 +
+ | false +
| +
|
1 | +
| +
| Function Scan +
| false +
+ | false +
| pg_show_plans +
| pg_show_plans +
| 0.00 +
| 12.50 +
| 333 +
| 36 +
+ | false +
| (level >= 0) +
| +
|
diff --git a/pg_show_plans.c b/pg_show_plans.c
index f41f998..c8aa102 100644
--- a/pg_show_plans.c
+++ b/pg_show_plans.c
@@ -15,6 +15,10 @@
#include "catalog/pg_authid.h"
#include "commands/explain.h"
+#if PG_VERSION_NUM >= 180000
+#include "commands/explain_state.h"
+#include "commands/explain_format.h"
+#endif
#include "fmgr.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
@@ -103,10 +107,20 @@ static void pgsp_shmem_request(void);
#endif
static void pgsp_shmem_startup(void);
/* Saves query plans to the shared hash table. */
-static void pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags);
+static
+#if PG_VERSION_NUM < 180000
+void
+#else
+bool
+#endif
+pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags);
/* Keeps track of the nest level. */
static void pgsp_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
- uint64 count, bool execute_once);
+ uint64 count
+#if PG_VERSION_NUM < 180000
+ , bool execute_once
+#endif
+ );
/* Show query plans of all the currently running statements. */
Datum pg_show_plans(PG_FUNCTION_ARGS);
@@ -455,26 +469,54 @@ pgsp_shmem_startup(void)
LWLockRelease(AddinShmemInitLock);
}
-static void
+static
+#if PG_VERSION_NUM < 180000
+void
+#else
+bool
+#endif
pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags)
{
ExplainState *es;
+#if PG_VERSION_NUM >= 180000
+ bool ret_val;
+#endif
if (prev_ExecutorStart)
+ {
+#if PG_VERSION_NUM >= 180000
+ ret_val =
+#endif
prev_ExecutorStart(queryDesc, eflags);
+ }
else
+ {
+#if PG_VERSION_NUM >= 180000
+ ret_val =
+#endif
standard_ExecutorStart(queryDesc, eflags);
+ }
if (!ensure_cached()) {
ereport(WARNING,
errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("not enough memory to append new query plans"),
errhint("Try increasing 'pg_show_plans.max_plan_length'."));
- return;
+ return
+#if PG_VERSION_NUM >= 180000
+ ret_val
+#endif
+ ;
}
if (!pgsp->is_enabled)
- return;
+ {
+ return
+#if PG_VERSION_NUM >= 180000
+ ret_val
+#endif
+ ;
+ }
es = NewExplainState();
es->format = pgsp->plan_format;
@@ -484,20 +526,39 @@ pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags)
append_query_plan(es);
pfree(es->str->data);
+
+ return
+#if PG_VERSION_NUM >= 180000
+ ret_val
+#endif
+ ;
}
static void
pgsp_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
- uint64 count, bool execute_once)
+ uint64 count
+#if PG_VERSION_NUM < 180000
+ , bool execute_once
+#endif
+ )
{
nest_level++;
PG_TRY();
{
/* These functions return *after* the nested quries do. */
if (prev_ExecutorRun)
- prev_ExecutorRun(queryDesc, direction, count, execute_once);
+ prev_ExecutorRun(queryDesc, direction, count
+#if PG_VERSION_NUM < 180000
+ , execute_once);
+#else
+ );
+#endif
else
- standard_ExecutorRun(queryDesc, direction, count, execute_once);
+ standard_ExecutorRun(queryDesc, direction, count
+#if PG_VERSION_NUM < 180000
+ , execute_once
+#endif
+ );
nest_level--;
/* Wait for reading to complete, then delete. */