Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostgreSQL 17 compatibility #44

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
fail-fast: false
matrix:
version:
- 17
- 16
- 15
- 14
Expand Down
8 changes: 4 additions & 4 deletions expected/store.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
SET client_min_messages = 'error';
CREATE EXTENSION IF NOT EXISTS pg_store_plans;
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
SELECT pg_stat_statements_reset();
pg_stat_statements_reset
--------------------------

SELECT pg_stat_statements_reset() IS NOT NULL AS t;
t
---
t
(1 row)

SELECT pg_store_plans_reset();
Expand Down
8 changes: 4 additions & 4 deletions expected/store_2.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
SET client_min_messages = 'error';
CREATE EXTENSION IF NOT EXISTS pg_store_plans;
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
SELECT pg_stat_statements_reset();
pg_stat_statements_reset
--------------------------

SELECT pg_stat_statements_reset() IS NOT NULL AS t;
t
---
t
(1 row)

SELECT pg_store_plans_reset();
Expand Down
20 changes: 11 additions & 9 deletions pg_store_plans.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ typedef struct Counters
int64 local_blks_written; /* # of local disk blocks written */
int64 temp_blks_read; /* # of temp blocks read */
int64 temp_blks_written; /* # of temp blocks written */
double blk_read_time; /* time spent reading, in msec */
double blk_write_time; /* time spent writing, in msec */
double shared_blk_read_time;/* time spent reading, in msec */
double shared_blk_write_time;/* time spent writing, in msec */
double temp_blk_read_time; /* time spent reading temp blocks,
in msec */
double temp_blk_write_time;/* time spent writing temp blocks,
Expand Down Expand Up @@ -1362,8 +1362,13 @@ pgsp_store(char *plan, queryid_t queryId,
e->counters.temp_blks_read += bufusage->temp_blks_read;
e->counters.temp_blks_written += bufusage->temp_blks_written;

e->counters.blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_read_time);
e->counters.blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_write_time);
#if PG_VERSION_NUM >= 170000
e->counters.shared_blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->shared_blk_read_time);
e->counters.shared_blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->shared_blk_write_time);
#else
e->counters.shared_blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_read_time);
e->counters.shared_blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_write_time);
#endif

#if PG_VERSION_NUM >= 150000
e->counters.temp_blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->temp_blk_read_time);
Expand Down Expand Up @@ -1664,8 +1669,8 @@ pg_store_plans_internal(FunctionCallInfo fcinfo,
values[i++] = Int64GetDatumFast(tmp.local_blks_written);
values[i++] = Int64GetDatumFast(tmp.temp_blks_read);
values[i++] = Int64GetDatumFast(tmp.temp_blks_written);
values[i++] = Float8GetDatumFast(tmp.blk_read_time);
values[i++] = Float8GetDatumFast(tmp.blk_write_time);
values[i++] = Float8GetDatumFast(tmp.shared_blk_read_time);
values[i++] = Float8GetDatumFast(tmp.shared_blk_write_time);

if (api_version >= PGSP_V1_7)
{
Expand All @@ -1685,9 +1690,6 @@ pg_store_plans_internal(FunctionCallInfo fcinfo,
}

LWLockRelease(shared_state->lock);

/* clean up and return the tuplestore */
tuplestore_donestoring(tupstore);
}

/* Number of output arguments (columns) for pg_stat_statements_info */
Expand Down
31 changes: 8 additions & 23 deletions pgsp_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,7 @@
#else
/* In PG16, include/scan.h was gone. Define required symbols manually.. */
/* must be in sync with src/backend/parser/gram.h */
enum pgsptokentype
{
IDENT = 258, /* IDENT */
FCONST = 260, /* FCONST */
SCONST = 261, /* SCONST */
BCONST = 263, /* BCONST */
XCONST = 264, /* XCONST */
Op = 265, /* Op */
ICONST = 266, /* ICONST */
CURRENT_CATALOG = 358, /* CURRENT_CATALOG */
CURRENT_DATE = 359, /* CURRENT_DATE */
CURRENT_ROLE = 360, /* CURRENT_ROLE */
CURRENT_SCHEMA = 361, /* CURRENT_SCHEMA */
CURRENT_TIME = 362, /* CURRENT_TIME */
CURRENT_TIMESTAMP = 363, /* CURRENT_TIMESTAMP */
CURRENT_USER = 364, /* CURRENT_USER */
FALSE_P = 415, /* FALSE_P */
LOCALTIME = 502, /* LOCALTIME */
LOCALTIMESTAMP = 503, /* LOCALTIMESTAMP */
NULL_P = 540, /* NULL_P */
TRUE_P = 689, /* TRUE_P */
};
#include "pgsp_token_types.h"
#define JSONACTION_RETURN_SUCCESS() return JSON_SUCCESS
#endif

Expand Down Expand Up @@ -1347,13 +1326,19 @@ run_pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
void
init_json_lex_context(JsonLexContext *lex, char *json)
{
#if PG_VERSION_NUM < 170000
memset(lex, 0, sizeof(JsonLexContext));
lex->input = lex->token_terminator = lex->line_start = json;
lex->line_number = 1;
lex->input_length = strlen(json);
#if PG_VERSION_NUM >= 130000
lex->input_encoding = GetDatabaseEncoding();
#endif
#endif /* PG13+ */
lex->strval = makeStringInfo();
#else /* PG17- */
makeJsonLexContextCstringLen(lex, json, strlen(json),
GetDatabaseEncoding(), true);
#endif /* PG17+ */
}

static void
Expand Down
67 changes: 67 additions & 0 deletions pgsp_token_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*-------------------------------------------------------------------------
*
* pgsp_json.c: Plan handler for JSON/XML/YAML style plans
*
* Copyright (c) 2012-2024, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
* IDENTIFICATION
* pg_store_plans/pgsp_json.c
*
*-------------------------------------------------------------------------
*/

#include "postgres.h"

/* In PG16, include/scan.h was gone. Define required symbols manually.. */
/* must be in sync with src/backend/parser/gram.h */
#if PG_VERSION_NUM < 160000
#error This file should only be included for PostgreSQL 16 and above
#elif PG_VERSION_NUM < 170000
enum pgsptokentype
{
IDENT = 258, /* IDENT */
FCONST = 260, /* FCONST */
SCONST = 261, /* SCONST */
BCONST = 263, /* BCONST */
XCONST = 264, /* XCONST */
Op = 265, /* Op */
ICONST = 266, /* ICONST */
CURRENT_CATALOG = 358, /* CURRENT_CATALOG */
CURRENT_DATE = 359, /* CURRENT_DATE */
CURRENT_ROLE = 360, /* CURRENT_ROLE */
CURRENT_SCHEMA = 361, /* CURRENT_SCHEMA */
CURRENT_TIME = 362, /* CURRENT_TIME */
CURRENT_TIMESTAMP = 363, /* CURRENT_TIMESTAMP */
CURRENT_USER = 364, /* CURRENT_USER */
FALSE_P = 415, /* FALSE_P */
LOCALTIME = 502, /* LOCALTIME */
LOCALTIMESTAMP = 503, /* LOCALTIMESTAMP */
NULL_P = 540, /* NULL_P */
TRUE_P = 689, /* TRUE_P */
};
#elif PG_VERSION_NUM < 180000
enum pgsptokentype
{
IDENT = 258, /* IDENT */
FCONST = 260, /* FCONST */
SCONST = 261, /* SCONST */
BCONST = 263, /* BCONST */
XCONST = 264, /* XCONST */
Op = 265, /* Op */
ICONST = 266, /* ICONST */
CURRENT_CATALOG = 359, /* CURRENT_CATALOG */
CURRENT_DATE = 360, /* CURRENT_DATE */
CURRENT_ROLE = 361, /* CURRENT_ROLE */
CURRENT_SCHEMA = 362, /* CURRENT_SCHEMA */
CURRENT_TIME = 363, /* CURRENT_TIME */
CURRENT_TIMESTAMP = 364, /* CURRENT_TIMESTAMP */
CURRENT_USER = 365, /* CURRENT_USER */
FALSE_P = 418, /* FALSE_P */
LOCALTIME = 512, /* LOCALTIME */
LOCALTIMESTAMP = 513, /* LOCALTIMESTAMP */
NULL_P = 552, /* NULL_P */
TRUE_P = 708, /* TRUE_P */
};
#else
#error This version of PostgeSQL is not supported
#endif
2 changes: 1 addition & 1 deletion sql/store.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SET client_min_messages = 'error';
CREATE EXTENSION IF NOT EXISTS pg_store_plans;
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
SELECT pg_stat_statements_reset();
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
SELECT pg_store_plans_reset();

DROP TABLE IF EXISTS t1;
Expand Down