Skip to content

Commit 4a7aea9

Browse files
committed
Add PostgreSQL 18 support
1 parent 306ad79 commit 4a7aea9

File tree

3 files changed

+85
-11
lines changed

3 files changed

+85
-11
lines changed

.github/workflows/installcheck.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
pgversion:
19+
- 18
1920
- 17
2021
- 16
2122
- 15

expected/formats_1.out

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
select setting::int < 140000 as pg12_13 from pg_settings where name = 'server_version_num';
33
pg12_13
44
---------
5-
t
5+
f
66
(1 row)
77

88
-- json output
@@ -20,24 +20,28 @@ select * from nest();
2020
| "Plan": { +
2121
| "Node Type": "Function Scan", +
2222
| "Parallel Aware": false, +
23+
| "Async Capable": false, +
2324
| "Function Name": "nest", +
2425
| "Alias": "nest", +
2526
| "Startup Cost": 0.25, +
2627
| "Total Cost": 10.25, +
2728
| "Plan Rows": 1000, +
28-
| "Plan Width": 36 +
29+
| "Plan Width": 36, +
30+
| "Disabled": false +
2931
| } +
3032
| ]
3133
1 | [ +
3234
| "Plan": { +
3335
| "Node Type": "Function Scan", +
3436
| "Parallel Aware": false, +
37+
| "Async Capable": false, +
3538
| "Function Name": "pg_show_plans",+
3639
| "Alias": "pg_show_plans", +
3740
| "Startup Cost": 0.00, +
3841
| "Total Cost": 12.50, +
3942
| "Plan Rows": 333, +
4043
| "Plan Width": 36, +
44+
| "Disabled": false, +
4145
| "Filter": "(level >= 0)" +
4246
| } +
4347
| ]
@@ -57,21 +61,25 @@ select * from nest();
5761
0 | Plan: +
5862
| Node Type: "Function Scan" +
5963
| Parallel Aware: false +
64+
| Async Capable: false +
6065
| Function Name: "nest" +
6166
| Alias: "nest" +
6267
| Startup Cost: 0.25 +
6368
| Total Cost: 10.25 +
6469
| Plan Rows: 1000 +
65-
| Plan Width: 36
70+
| Plan Width: 36 +
71+
| Disabled: false
6672
1 | Plan: +
6773
| Node Type: "Function Scan" +
6874
| Parallel Aware: false +
75+
| Async Capable: false +
6976
| Function Name: "pg_show_plans"+
7077
| Alias: "pg_show_plans" +
7178
| Startup Cost: 0.00 +
7279
| Total Cost: 12.50 +
7380
| Plan Rows: 333 +
7481
| Plan Width: 36 +
82+
| Disabled: false +
7583
| Filter: "(level >= 0)"
7684
(2 rows)
7785

@@ -90,24 +98,28 @@ select * from nest();
9098
| <Plan> +
9199
| <Node-Type>Function Scan</Node-Type> +
92100
| <Parallel-Aware>false</Parallel-Aware> +
101+
| <Async-Capable>false</Async-Capable> +
93102
| <Function-Name>nest</Function-Name> +
94103
| <Alias>nest</Alias> +
95104
| <Startup-Cost>0.25</Startup-Cost> +
96105
| <Total-Cost>10.25</Total-Cost> +
97106
| <Plan-Rows>1000</Plan-Rows> +
98107
| <Plan-Width>36</Plan-Width> +
108+
| <Disabled>false</Disabled> +
99109
| </Plan> +
100110
| </explain>
101111
1 | <explain xmlns="http://www.postgresql.org/2009/explain">+
102112
| <Plan> +
103113
| <Node-Type>Function Scan</Node-Type> +
104114
| <Parallel-Aware>false</Parallel-Aware> +
115+
| <Async-Capable>false</Async-Capable> +
105116
| <Function-Name>pg_show_plans</Function-Name> +
106117
| <Alias>pg_show_plans</Alias> +
107118
| <Startup-Cost>0.00</Startup-Cost> +
108119
| <Total-Cost>12.50</Total-Cost> +
109120
| <Plan-Rows>333</Plan-Rows> +
110121
| <Plan-Width>36</Plan-Width> +
122+
| <Disabled>false</Disabled> +
111123
| <Filter>(level &gt;= 0)</Filter> +
112124
| </Plan> +
113125
| </explain>

pg_show_plans.c

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
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
104108
static 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. */
108118
static 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. */
112126
Datum pg_show_plans(PG_FUNCTION_ARGS);
@@ -455,26 +469,54 @@ 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
459478
pgsp_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
506+
#if PG_VERSION_NUM >= 180000
507+
ret_val
508+
#endif
509+
;
474510
}
475511

476512
if (!pgsp->is_enabled)
477-
return;
513+
{
514+
return
515+
#if PG_VERSION_NUM >= 180000
516+
ret_val
517+
#endif
518+
;
519+
}
478520

479521
es = NewExplainState();
480522
es->format = pgsp->plan_format;
@@ -484,20 +526,39 @@ pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags)
484526

485527
append_query_plan(es);
486528
pfree(es->str->data);
529+
530+
return
531+
#if PG_VERSION_NUM >= 180000
532+
ret_val
533+
#endif
534+
;
487535
}
488536

489537
static void
490538
pgsp_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
491-
uint64 count, bool execute_once)
539+
uint64 count
540+
#if PG_VERSION_NUM < 180000
541+
, bool execute_once
542+
#endif
543+
)
492544
{
493545
nest_level++;
494546
PG_TRY();
495547
{
496548
/* These functions return *after* the nested quries do. */
497549
if (prev_ExecutorRun)
498-
prev_ExecutorRun(queryDesc, direction, count, execute_once);
550+
prev_ExecutorRun(queryDesc, direction, count
551+
#if PG_VERSION_NUM < 180000
552+
, execute_once);
553+
#else
554+
);
555+
#endif
499556
else
500-
standard_ExecutorRun(queryDesc, direction, count, execute_once);
557+
standard_ExecutorRun(queryDesc, direction, count
558+
#if PG_VERSION_NUM < 180000
559+
, execute_once
560+
#endif
561+
);
501562

502563
nest_level--;
503564
/* Wait for reading to complete, then delete. */

0 commit comments

Comments
 (0)