From f4e7a43206965605c730e0b024a077e346343e25 Mon Sep 17 00:00:00 2001 From: Ivan Kovmir Date: Tue, 29 Apr 2025 08:58:10 +0200 Subject: [PATCH 1/5] Add PostgreSQL 18 support --- pg_show_plans.c | 63 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/pg_show_plans.c b/pg_show_plans.c index f41f998..77e4b60 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,44 @@ 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 ret_val; } if (!pgsp->is_enabled) - return; + return ret_val; es = NewExplainState(); es->format = pgsp->plan_format; @@ -484,20 +516,35 @@ pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags) append_query_plan(es); pfree(es->str->data); + + return ret_val; } 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. */ From b059b23b177c7de58ab115e48dd350f6536aad7e Mon Sep 17 00:00:00 2001 From: Ivan Kovmir Date: Tue, 29 Apr 2025 09:02:57 +0200 Subject: [PATCH 2/5] Add 18 CI support --- .github/workflows/installcheck.yml | 1 + 1 file changed, 1 insertion(+) 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 From 9dfd5ac7dc516ca8bfc692d688c5b3903d5c34d9 Mon Sep 17 00:00:00 2001 From: Ivan Kovmir Date: Tue, 29 Apr 2025 09:07:39 +0200 Subject: [PATCH 3/5] Add missing #ifdefs --- pg_show_plans.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pg_show_plans.c b/pg_show_plans.c index 77e4b60..c8aa102 100644 --- a/pg_show_plans.c +++ b/pg_show_plans.c @@ -502,11 +502,21 @@ pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags) errcode(ERRCODE_OUT_OF_MEMORY), errmsg("not enough memory to append new query plans"), errhint("Try increasing 'pg_show_plans.max_plan_length'.")); - return ret_val; + return +#if PG_VERSION_NUM >= 180000 + ret_val +#endif + ; } if (!pgsp->is_enabled) - return ret_val; + { + return +#if PG_VERSION_NUM >= 180000 + ret_val +#endif + ; + } es = NewExplainState(); es->format = pgsp->plan_format; @@ -517,7 +527,11 @@ pgsp_ExecutorStart(QueryDesc *queryDesc, int eflags) append_query_plan(es); pfree(es->str->data); - return ret_val; + return +#if PG_VERSION_NUM >= 180000 + ret_val +#endif + ; } static void From de1d774a8a13cc1c6548f91bdd1d55712405bc15 Mon Sep 17 00:00:00 2001 From: Ivan Kovmir Date: Tue, 29 Apr 2025 09:13:49 +0200 Subject: [PATCH 4/5] Remove expected tests for unsupported versions --- expected/formats_1.out | 123 ----------------------------------------- 1 file changed, 123 deletions(-) delete mode 100644 expected/formats_1.out diff --git a/expected/formats_1.out b/expected/formats_1.out deleted file mode 100644 index 32ecd28..0000000 --- a/expected/formats_1.out +++ /dev/null @@ -1,123 +0,0 @@ --- explain output on PG12/13 is missing "Async Capable" -select setting::int < 140000 as pg12_13 from pg_settings where name = 'server_version_num'; - pg12_13 ---------- - t -(1 row) - --- json output -set pg_show_plans.plan_format = 'json'; -show pg_show_plans.plan_format; - pg_show_plans.plan_format ---------------------------- - json -(1 row) - -select * from nest(); - level | plan --------+--------------------------------------- - 0 | [ + - | "Plan": { + - | "Node Type": "Function Scan", + - | "Parallel Aware": false, + - | "Function Name": "nest", + - | "Alias": "nest", + - | "Startup Cost": 0.25, + - | "Total Cost": 10.25, + - | "Plan Rows": 1000, + - | "Plan Width": 36 + - | } + - | ] - 1 | [ + - | "Plan": { + - | "Node Type": "Function Scan", + - | "Parallel Aware": false, + - | "Function Name": "pg_show_plans",+ - | "Alias": "pg_show_plans", + - | "Startup Cost": 0.00, + - | "Total Cost": 12.50, + - | "Plan Rows": 333, + - | "Plan Width": 36, + - | "Filter": "(level >= 0)" + - | } + - | ] -(2 rows) - --- yaml output -set pg_show_plans.plan_format = 'yaml'; -show pg_show_plans.plan_format; - pg_show_plans.plan_format ---------------------------- - yaml -(1 row) - -select * from nest(); - level | plan --------+---------------------------------- - 0 | Plan: + - | Node Type: "Function Scan" + - | Parallel Aware: false + - | Function Name: "nest" + - | Alias: "nest" + - | Startup Cost: 0.25 + - | Total Cost: 10.25 + - | Plan Rows: 1000 + - | Plan Width: 36 - 1 | Plan: + - | Node Type: "Function Scan" + - | Parallel Aware: false + - | Function Name: "pg_show_plans"+ - | Alias: "pg_show_plans" + - | Startup Cost: 0.00 + - | Total Cost: 12.50 + - | Plan Rows: 333 + - | Plan Width: 36 + - | Filter: "(level >= 0)" -(2 rows) - --- xml output -set pg_show_plans.plan_format = 'xml'; -show pg_show_plans.plan_format; - pg_show_plans.plan_format ---------------------------- - xml -(1 row) - -select * from nest(); - level | plan --------+---------------------------------------------------------- - 0 | + - | + - | Function Scan + - | false + - | nest + - | nest + - | 0.25 + - | 10.25 + - | 1000 + - | 36 + - | + - | - 1 | + - | + - | Function Scan + - | false + - | pg_show_plans + - | pg_show_plans + - | 0.00 + - | 12.50 + - | 333 + - | 36 + - | (level >= 0) + - | + - | -(2 rows) - --- check plan format after reconnect -\c -show pg_show_plans.plan_format; - pg_show_plans.plan_format ---------------------------- - xml -(1 row) - From 6242acbfb352d5dc0ed4317cd17bc0900c193ea8 Mon Sep 17 00:00:00 2001 From: Ivan Kovmir Date: Tue, 29 Apr 2025 09:17:22 +0200 Subject: [PATCH 5/5] Add new expected tests results for version 18 --- expected/formats_1.out | 135 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 expected/formats_1.out diff --git a/expected/formats_1.out b/expected/formats_1.out new file mode 100644 index 0000000..0782565 --- /dev/null +++ b/expected/formats_1.out @@ -0,0 +1,135 @@ +-- explain output on PG12/13 is missing "Async Capable" +select setting::int < 140000 as pg12_13 from pg_settings where name = 'server_version_num'; + pg12_13 +--------- + f +(1 row) + +-- json output +set pg_show_plans.plan_format = 'json'; +show pg_show_plans.plan_format; + pg_show_plans.plan_format +--------------------------- + json +(1 row) + +select * from nest(); + level | plan +-------+--------------------------------------- + 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, + + | "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) + +-- yaml output +set pg_show_plans.plan_format = 'yaml'; +show pg_show_plans.plan_format; + pg_show_plans.plan_format +--------------------------- + yaml +(1 row) + +select * from nest(); + level | plan +-------+---------------------------------- + 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 + + | 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) + +-- xml output +set pg_show_plans.plan_format = 'xml'; +show pg_show_plans.plan_format; + pg_show_plans.plan_format +--------------------------- + xml +(1 row) + +select * from nest(); + level | plan +-------+---------------------------------------------------------- + 0 | + + | + + | 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) + + | + + | +(2 rows) + +-- check plan format after reconnect +\c +show pg_show_plans.plan_format; + pg_show_plans.plan_format +--------------------------- + xml +(1 row) +