Skip to content

Commit 8612649

Browse files
committed
Adjust for PostgreSQL 17
This commit updates several components to align with PostgreSQL 17, including: - Initialization steps for the JSON parser - The list of lexical tokens assumed to be constants - Handling of local_blk_read_time and local_blk_write_time - Adjustments for the changes in pg_stat_statements_reset()
1 parent a073869 commit 8612649

File tree

8 files changed

+111
-39
lines changed

8 files changed

+111
-39
lines changed

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pg_stat_plan/Makefile
22

33
MODULES = pg_store_plans
4-
STOREPLANSVER = 1.8
4+
STOREPLANSVER = 1.9
55

66
MODULE_big = pg_store_plans
77
OBJS = pg_store_plans.o pgsp_json.o pgsp_json_text.o pgsp_explain.o
@@ -10,7 +10,7 @@ EXTENSION = pg_store_plans
1010

1111
PG_VERSION := $(shell pg_config --version | sed "s/^PostgreSQL //" | sed "s/\.[0-9]*$$//")
1212

13-
DATA = pg_store_plans--1.8.sql
13+
DATA = pg_store_plans--1.9.sql
1414

1515
REGRESS = convert store
1616
REGRESS_OPTS = --temp-config=regress.conf
@@ -25,8 +25,8 @@ include $(top_builddir)/src/Makefile.global
2525
include $(top_srcdir)/contrib/contrib-global.mk
2626
endif
2727

28-
STARBALL16 = pg_store_plans16-$(STOREPLANSVER).tar.gz
29-
STARBALLS = $(STARBALL16)
28+
STARBALL17 = pg_store_plans17-$(STOREPLANSVER).tar.gz
29+
STARBALLS = $(STARBALL17)
3030

3131
TARSOURCES = Makefile *.c *.h \
3232
pg_store_plans--*.sql \
@@ -40,7 +40,7 @@ endif
4040
## These entries need running server
4141
DBNAME = postgres
4242

43-
rpms: rpm16
43+
rpms: rpm17
4444

4545
$(STARBALLS): $(TARSOURCES)
4646
if [ -h $(subst .tar.gz,,$@) ]; then rm $(subst .tar.gz,,$@); fi
@@ -52,8 +52,8 @@ $(STARBALLS): $(TARSOURCES)
5252
tar -chzf $@ $(addprefix $(subst .tar.gz,,$@)/, $^)
5353
rm $(subst .tar.gz,,$@)
5454

55-
rpm16: $(STARBALL16)
56-
MAKE_ROOT=`pwd` rpmbuild -bb SPECS/pg_store_plans16.spec
55+
rpm17: $(STARBALL17)
56+
MAKE_ROOT=`pwd` rpmbuild -bb SPECS/pg_store_plans17.spec
5757

5858
testfiles: convert.out convert.sql
5959

SPECS/pg_store_plans16.spec renamed to SPECS/pg_store_plans17.spec

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPEC file for pg_store_plans
22
# Copyright(c) 2024, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
33

4-
%define _pgdir /usr/pgsql-16
4+
%define _pgdir /usr/pgsql-17
55
%define _bindir %{_pgdir}/bin
66
%define _libdir %{_pgdir}/lib
77
%define _datadir %{_pgdir}/share
@@ -14,9 +14,9 @@
1414
%endif
1515

1616
## Set general information for pg_store_plans.
17-
Summary: Record executed plans on PostgreSQL 16
18-
Name: pg_store_plans16
19-
Version: 1.8
17+
Summary: Record executed plans on PostgreSQL 17
18+
Name: pg_store_plans17
19+
Version: 1.9
2020
Release: 1%{?dist}
2121
License: BSD
2222
Group: Applications/Databases
@@ -26,28 +26,28 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
2626
Vendor: NIPPON TELEGRAPH AND TELEPHONE CORPORATION
2727

2828
## We use postgresql-devel package
29-
BuildRequires: postgresql16-devel
30-
Requires: postgresql16-libs
29+
BuildRequires: postgresql17-devel
30+
Requires: postgresql17-libs
3131

3232
## Description for "pg_store_plans"
3333
%description
3434

3535
pg_store_plans provides capability to record statistics for every plan
3636
executed on PostgreSQL.
3737

38-
Note that this package is available for only PostgreSQL 16.
38+
Note that this package is available for only PostgreSQL 17.
3939

4040
%package llvmjit
41-
Requires: postgresql16-server, postgresql16-llvmjit
42-
Requires: pg_store_plans16 = 1.8
43-
Summary: Just-in-time compilation support for pg_store_plans16
41+
Requires: postgresql17-server, postgresql17-llvmjit
42+
Requires: pg_store_plans17 = 1.9
43+
Summary: Just-in-time compilation support for pg_store_plans17
4444

4545
%description llvmjit
46-
Just-in-time compilation support for pg_store_plans16
46+
Just-in-time compilation support for pg_store_plans17
4747

4848
## pre work for build pg_store_plans
4949
%prep
50-
PATH=/usr/pgsql-16/bin:$PATH
50+
PATH=/usr/pgsql-17/bin:$PATH
5151
if [ "${MAKE_ROOT}" != "" ]; then
5252
pushd ${MAKE_ROOT}
5353
make clean %{name}-%{version}.tar.gz
@@ -58,14 +58,14 @@ if [ ! -d %{_rpmdir} ]; then mkdir -p %{_rpmdir}; fi
5858

5959
## Set variables for build environment
6060
%build
61-
PATH=/usr/pgsql-16/bin:$PATH
61+
PATH=/usr/pgsql-17/bin:$PATH
6262
pg_config
6363
make USE_PGXS=1 %{?_smp_mflags}
6464

6565
## Set variables for install
6666
%install
6767
rm -rf %{buildroot}
68-
PATH=/usr/pgsql-16/bin:$PATH
68+
PATH=/usr/pgsql-17/bin:$PATH
6969
make install DESTDIR=%{buildroot}
7070

7171
%clean
@@ -75,7 +75,7 @@ rm -rf %{buildroot}
7575
%defattr(0755,root,root)
7676
%{_libdir}/pg_store_plans.so
7777
%defattr(0644,root,root)
78-
%{_datadir}/extension/pg_store_plans--1.8.sql
78+
%{_datadir}/extension/pg_store_plans--1.9.sql
7979
%{_datadir}/extension/pg_store_plans.control
8080

8181
%files llvmjit
@@ -85,6 +85,8 @@ rm -rf %{buildroot}
8585

8686
# History of pg_store_plans.
8787
%changelog
88+
* Mon Jan 20 2025 Kyotaro Horiguchi
89+
- Version 1.9. Support PostgreSQL 17.
8890
* Fri Feb 02 2024 Kyotaro Horiguchi
8991
- Version 1.8. Support PostgreSQL 16.
9092
* Wed Dec 14 2022 Kyotaro Horiguchi

expected/store.out

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
SET client_min_messages = 'error';
22
CREATE EXTENSION IF NOT EXISTS pg_store_plans;
33
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
4-
SELECT pg_stat_statements_reset();
5-
pg_stat_statements_reset
6-
--------------------------
7-
4+
-- ignore the timestamp returned by pg_stat_statement_reset()
5+
SELECT FROM (SELECT pg_stat_statements_reset());
6+
--
87
(1 row)
98

109
SELECT pg_store_plans_reset();

pg_store_plans--1.8.sql renamed to pg_store_plans--1.9.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* pg_store_plans/pg_store_plans--1.8.sql */
1+
/* pg_store_plans/pg_store_plans--1.9.sql */
22

33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION pg_store_plans" to load this file. \quit
@@ -80,15 +80,17 @@ CREATE FUNCTION pg_store_plans(
8080
OUT local_blks_written int8,
8181
OUT temp_blks_read int8,
8282
OUT temp_blks_written int8,
83-
OUT blk_read_time float8,
84-
OUT blk_write_time float8,
83+
OUT shared_blk_read_time float8,
84+
OUT shared_blk_write_time float8,
85+
OUT local_blk_read_time float8,
86+
OUT local_blk_write_time float8,
8587
OUT temp_blk_read_time float8,
8688
OUT temp_blk_write_time float8,
8789
OUT first_call timestamptz,
8890
OUT last_call timestamptz
8991
)
9092
RETURNS SETOF record
91-
AS 'MODULE_PATHNAME', 'pg_store_plans_1_7'
93+
AS 'MODULE_PATHNAME', 'pg_store_plans_1_9'
9294
LANGUAGE C
9395
VOLATILE PARALLEL SAFE;
9496

pg_store_plans.c

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ typedef enum pgspVersion
101101
{
102102
PGSP_V1_5 = 0,
103103
PGSP_V1_6,
104-
PGSP_V1_7
104+
PGSP_V1_7,
105+
/* PGSP_V1_7 interface is used for v1.8 */
106+
PGSP_V1_9
105107
} pgspVersion;
106108

107109
/*
@@ -142,8 +144,19 @@ typedef struct Counters
142144
int64 local_blks_written; /* # of local disk blocks written */
143145
int64 temp_blks_read; /* # of temp blocks read */
144146
int64 temp_blks_written; /* # of temp blocks written */
147+
#if PG_VERSION_NUM >= 170000
148+
double shared_blk_read_time; /* time spent reading shared bloks,
149+
in msec */
150+
double shared_blk_write_time; /* time spent writing shared blocks,
151+
in msec */
152+
double local_blk_read_time; /* time spent reading local blocks,
153+
in msec */
154+
double local_blk_write_time; /* time spent writing local blocks,
155+
in msec */
156+
#else
145157
double blk_read_time; /* time spent reading, in msec */
146158
double blk_write_time; /* time spent writing, in msec */
159+
#endif
147160
double temp_blk_read_time; /* time spent reading temp blocks,
148161
in msec */
149162
double temp_blk_write_time;/* time spent writing temp blocks,
@@ -321,6 +334,7 @@ PG_FUNCTION_INFO_V1(pg_store_plans_hash_query);
321334
PG_FUNCTION_INFO_V1(pg_store_plans);
322335
PG_FUNCTION_INFO_V1(pg_store_plans_1_6);
323336
PG_FUNCTION_INFO_V1(pg_store_plans_1_7);
337+
PG_FUNCTION_INFO_V1(pg_store_plans_1_9);
324338
PG_FUNCTION_INFO_V1(pg_store_plans_shorten);
325339
PG_FUNCTION_INFO_V1(pg_store_plans_normalize);
326340
PG_FUNCTION_INFO_V1(pg_store_plans_jsonplan);
@@ -1356,9 +1370,22 @@ pgsp_store(char *plan, queryid_t queryId,
13561370
e->counters.temp_blks_read += bufusage->temp_blks_read;
13571371
e->counters.temp_blks_written += bufusage->temp_blks_written;
13581372

1359-
e->counters.blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_read_time);
1360-
e->counters.blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_write_time);
1361-
1373+
#if PG_VERSION_NUM >= 170000
1374+
e->counters.shared_blk_read_time +=
1375+
INSTR_TIME_GET_MILLISEC(bufusage->shared_blk_read_time);
1376+
e->counters.shared_blk_write_time +=
1377+
INSTR_TIME_GET_MILLISEC(bufusage->shared_blk_write_time);
1378+
e->counters.local_blk_read_time +=
1379+
INSTR_TIME_GET_MILLISEC(bufusage->local_blk_read_time);
1380+
e->counters.local_blk_write_time +=
1381+
INSTR_TIME_GET_MILLISEC(bufusage->local_blk_write_time);
1382+
#else
1383+
e->counters.blk_read_time +=
1384+
INSTR_TIME_GET_MILLISEC(bufusage->blk_read_time);
1385+
e->counters.blk_write_time +=
1386+
INSTR_TIME_GET_MILLISEC(bufusage->blk_write_time);
1387+
#endif
1388+
13621389
#if PG_VERSION_NUM >= 150000
13631390
e->counters.temp_blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->temp_blk_read_time);
13641391
e->counters.temp_blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->temp_blk_write_time);
@@ -1395,11 +1422,20 @@ pg_store_plans_reset(PG_FUNCTION_ARGS)
13951422
#define PG_STORE_PLANS_COLS_V1_5 27
13961423
#define PG_STORE_PLANS_COLS_V1_6 26
13971424
#define PG_STORE_PLANS_COLS_V1_7 28
1398-
#define PG_STORE_PLANS_COLS 28 /* maximum of above */
1425+
#define PG_STORE_PLANS_COLS_V1_9 30
1426+
#define PG_STORE_PLANS_COLS 30 /* maximum of above */
13991427

14001428
/*
14011429
* Retrieve statement statistics.
14021430
*/
1431+
Datum
1432+
pg_store_plans_1_9(PG_FUNCTION_ARGS)
1433+
{
1434+
pg_store_plans_internal(fcinfo, PGSP_V1_9);
1435+
1436+
return (Datum) 0;
1437+
}
1438+
14031439
Datum
14041440
pg_store_plans_1_7(PG_FUNCTION_ARGS)
14051441
{
@@ -1658,8 +1694,14 @@ pg_store_plans_internal(FunctionCallInfo fcinfo,
16581694
values[i++] = Int64GetDatumFast(tmp.local_blks_written);
16591695
values[i++] = Int64GetDatumFast(tmp.temp_blks_read);
16601696
values[i++] = Int64GetDatumFast(tmp.temp_blks_written);
1661-
values[i++] = Float8GetDatumFast(tmp.blk_read_time);
1662-
values[i++] = Float8GetDatumFast(tmp.blk_write_time);
1697+
values[i++] = Float8GetDatumFast(tmp.shared_blk_read_time);
1698+
values[i++] = Float8GetDatumFast(tmp.shared_blk_write_time);
1699+
1700+
if (api_version >= PGSP_V1_9)
1701+
{
1702+
values[i++] = Float8GetDatumFast(tmp.local_blk_read_time);
1703+
values[i++] = Float8GetDatumFast(tmp.local_blk_write_time);
1704+
}
16631705

16641706
if (api_version >= PGSP_V1_7)
16651707
{
@@ -1673,15 +1715,18 @@ pg_store_plans_internal(FunctionCallInfo fcinfo,
16731715
Assert(i == (api_version == PGSP_V1_5 ? PG_STORE_PLANS_COLS_V1_5 :
16741716
api_version == PGSP_V1_6 ? PG_STORE_PLANS_COLS_V1_6 :
16751717
api_version == PGSP_V1_7 ? PG_STORE_PLANS_COLS_V1_7 :
1718+
api_version == PGSP_V1_9 ? PG_STORE_PLANS_COLS_V1_9 :
16761719
-1 /* fail if you forget to update this assert */ ));
16771720

16781721
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
16791722
}
16801723

16811724
LWLockRelease(shared_state->lock);
16821725

1726+
#if PG_VERSION_NUM < 170000
16831727
/* clean up and return the tuplestore */
16841728
tuplestore_donestoring(tupstore);
1729+
#endif
16851730
}
16861731

16871732
/* Number of output arguments (columns) for pg_stat_statements_info */

pg_store_plans.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pg_store_plans extension
22
comment = 'track plan statistics of all SQL statements executed'
3-
default_version = '1.8'
3+
default_version = '1.9'
44
module_pathname = '$libdir/pg_store_plans'
55
relocatable = true

pgsp_json.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#else
2424
#include "common/jsonapi.h"
2525
#endif
26+
#if PG_VERSION_NUM >= 170000
27+
#include "mb/pg_wchar.h"
28+
#endif
2629
#include "pgsp_json.h"
2730
#include "pgsp_json_int.h"
2831

@@ -42,6 +45,20 @@ enum pgsptokentype
4245
XCONST = 264, /* XCONST */
4346
Op = 265, /* Op */
4447
ICONST = 266, /* ICONST */
48+
#if PG_VERSION_NUM >= 170000
49+
CURRENT_CATALOG = 359, /* CURRENT_CATALOG */
50+
CURRENT_DATE = 360, /* CURRENT_DATE */
51+
CURRENT_ROLE = 361, /* CURRENT_ROLE */
52+
CURRENT_SCHEMA = 362, /* CURRENT_SCHEMA */
53+
CURRENT_TIME = 363, /* CURRENT_TIME */
54+
CURRENT_TIMESTAMP = 364, /* CURRENT_TIMESTAMP */
55+
CURRENT_USER = 365, /* CURRENT_USER */
56+
FALSE_P = 418, /* FALSE_P */
57+
LOCALTIME = 512, /* LOCALTIME */
58+
LOCALTIMESTAMP = 513, /* LOCALTIMESTAMP */
59+
NULL_P = 552, /* NULL_P */
60+
TRUE_P = 708, /* TRUE_P */
61+
#else
4562
CURRENT_CATALOG = 358, /* CURRENT_CATALOG */
4663
CURRENT_DATE = 359, /* CURRENT_DATE */
4764
CURRENT_ROLE = 360, /* CURRENT_ROLE */
@@ -54,6 +71,7 @@ enum pgsptokentype
5471
LOCALTIMESTAMP = 503, /* LOCALTIMESTAMP */
5572
NULL_P = 540, /* NULL_P */
5673
TRUE_P = 689, /* TRUE_P */
74+
#endif
5775
};
5876
#define JSONACTION_RETURN_SUCCESS() return JSON_SUCCESS
5977
#endif
@@ -1344,10 +1362,15 @@ run_pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
13441362
void
13451363
init_json_lex_context(JsonLexContext *lex, char *json)
13461364
{
1365+
#if PG_VERSION_NUM >= 170000
1366+
makeJsonLexContextCstringLen(lex, json, strlen(json),
1367+
GetDatabaseEncoding(), true);
1368+
#else
13471369
lex->input = lex->token_terminator = lex->line_start = json;
13481370
lex->line_number = 1;
13491371
lex->input_length = strlen(json);
13501372
lex->strval = makeStringInfo();
1373+
#endif
13511374
}
13521375

13531376
static void

sql/store.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
SET client_min_messages = 'error';
22
CREATE EXTENSION IF NOT EXISTS pg_store_plans;
33
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
4-
SELECT pg_stat_statements_reset();
4+
-- ignore the timestamp returned by pg_stat_statement_reset()
5+
SELECT FROM (SELECT pg_stat_statements_reset());
56
SELECT pg_store_plans_reset();
67

78
DROP TABLE IF EXISTS t1;

0 commit comments

Comments
 (0)