Skip to content

Commit d64beeb

Browse files
authored
Update libpg_query to 17-6.2.2 (#143)
1 parent 6042d40 commit d64beeb

56 files changed

Lines changed: 12704 additions & 7774 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,35 @@
22

33
## Unreleased
44

5-
* ...
5+
* Upgrade to libpg_query 17-6.2.2
6+
- Add pg_query_is_utility_stmt function to determine if query text contains utility statements [#313](https://github.com/pganalyze/libpg_query/pull/313)
7+
- This is a fast check for callers that don't actually need the parse tree itself
8+
- Add fast summary information function (pg_query_summary)
9+
- This allows gathering certain information, for example which tables are referenced in a
10+
statement, without requiring a Protobuf serialization step in a higher level library
11+
- Additionally this can also be used to perform "smart truncation" of a query by
12+
omitting deeply nested information (e.g. a CTE definition, or a target list) whilst
13+
preserving more essential parts like the FROM clause
14+
- pg_query_normalize: Fix handling of special strings in DefElem
15+
- This avoids a crash when running the normalize function on certain utility statements
16+
- Deparser:
17+
- Introduce pretty printing / formatting
18+
- Introduces a new optional pretty print mode that emits a human readable
19+
output. A detailed explanation of the mechanism can be found at the start
20+
of the deparser file.
21+
- Rework handling of expressions inside typecasts
22+
- Prefer (..)::type syntax, unless we are already in a function call.
23+
- Use lowercase keywords in xmlroot functions
24+
- This matches other XML functions as well as the Postgres documentation,
25+
since these are closer to function argument names than regular keywords.
26+
- Fix deparse of ALTER TABLE a ALTER b SET STATISTICS DEFAULT
27+
- Fix the null pointer dereference when handling identity columns
28+
- Allow alternate definitions of NAMEDATALEN identifier limit
29+
- This allows building libpg_query with an override of the built-time limit of
30+
Postgres identifiers (typically 63 characters)
31+
- Normalization: Add support for CALL statements
32+
- Bump Postgres to 17.7 and switch back to release tarballs
33+
634

735
## 6.1.0 2025-02-24
836

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ benchmark:
1616

1717
# --- Below only needed for releasing new versions
1818

19-
LIB_PG_QUERY_TAG = 17-6.1.0
19+
LIB_PG_QUERY_TAG = 17-6.2.2
2020

2121
root_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2222
LIB_TMPDIR = $(root_dir)/tmp
@@ -40,7 +40,7 @@ update_source: clean $(LIBDIR)
4040
rm parser/pg_query_outfuncs_protobuf_cpp.cc
4141
mv parser/postgres/* parser/
4242
rmdir parser/postgres
43-
cp -a $(LIBDIR)/pg_query.h parser/include
43+
cp -a $(LIBDIR)/{pg_query.h,postgres_deparse.h} parser/include
4444
# Protobuf definitions
4545
mkdir -p $(PWD)/bin
4646
GOBIN=$(PWD)/bin go install google.golang.org/protobuf/cmd/protoc-gen-go

parse_test.go

Lines changed: 18 additions & 18 deletions
Large diffs are not rendered by default.

parser/COPYRIGHT

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
PostgreSQL Database Management System
2+
(also known as Postgres, formerly known as Postgres95)
3+
4+
Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
5+
6+
Portions Copyright (c) 1994, The Regents of the University of California
7+
8+
Permission to use, copy, modify, and distribute this software and its
9+
documentation for any purpose, without fee, and without a written agreement
10+
is hereby granted, provided that the above copyright notice and this
11+
paragraph and the following two paragraphs appear in all copies.
12+
13+
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
14+
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
15+
LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
16+
DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
17+
POSSIBILITY OF SUCH DAMAGE.
18+
19+
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
20+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21+
AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22+
ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
23+
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

parser/build_cgo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ import (
3434
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port"
3535
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/atomics"
3636
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32"
37+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32_msvc"
38+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32_msvc/sys"
3739
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32/arpa"
3840
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32/netinet"
3941
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32/sys"
40-
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32_msvc"
41-
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32_msvc/sys"
4242
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/portability"
4343
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/postmaster"
4444
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/regex"

parser/include/pg_query.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#ifndef PG_QUERY_H
22
#define PG_QUERY_H
33

4+
#include <stdbool.h>
45
#include <stdint.h>
56
#include <sys/types.h>
67

8+
#include "postgres_deparse.h"
9+
710
typedef struct {
811
char* message; // exception message
912
char* funcname; // source function of exception (e.g. SearchSysCache)
@@ -13,6 +16,12 @@ typedef struct {
1316
char* context; // additional context (optional, can be NULL)
1417
} PgQueryError;
1518

19+
typedef struct {
20+
int length;
21+
bool *items;
22+
PgQueryError* error;
23+
} PgQueryIsUtilityResult;
24+
1625
typedef struct {
1726
size_t len;
1827
char* data;
@@ -53,6 +62,12 @@ typedef struct {
5362
PgQueryError* error;
5463
} PgQueryDeparseResult;
5564

65+
typedef struct {
66+
PostgresDeparseComment **comments;
67+
size_t comment_count;
68+
PgQueryError* error;
69+
} PgQueryDeparseCommentsResult;
70+
5671
typedef struct {
5772
char* plpgsql_funcs;
5873
PgQueryError* error;
@@ -70,6 +85,12 @@ typedef struct {
7085
PgQueryError* error;
7186
} PgQueryNormalizeResult;
7287

88+
typedef struct {
89+
PgQueryProtobuf summary;
90+
char* stderr_buffer;
91+
PgQueryError* error;
92+
} PgQuerySummaryParseResult;
93+
7394
// Postgres parser options (parse mode and GUCs that affect parsing)
7495

7596
typedef enum
@@ -118,23 +139,32 @@ PgQuerySplitResult pg_query_split_with_scanner(const char *input);
118139
PgQuerySplitResult pg_query_split_with_parser(const char *input);
119140

120141
PgQueryDeparseResult pg_query_deparse_protobuf(PgQueryProtobuf parse_tree);
142+
PgQueryDeparseResult pg_query_deparse_protobuf_opts(PgQueryProtobuf parse_tree, struct PostgresDeparseOpts opts);
143+
PgQueryDeparseCommentsResult pg_query_deparse_comments_for_query(const char *query);
144+
145+
PgQueryIsUtilityResult pg_query_is_utility_stmt(const char *query);
146+
147+
PgQuerySummaryParseResult pg_query_summary(const char* input, int parser_options, int truncate_limit);
121148

122149
void pg_query_free_normalize_result(PgQueryNormalizeResult result);
123150
void pg_query_free_scan_result(PgQueryScanResult result);
124151
void pg_query_free_parse_result(PgQueryParseResult result);
125152
void pg_query_free_split_result(PgQuerySplitResult result);
126153
void pg_query_free_deparse_result(PgQueryDeparseResult result);
154+
void pg_query_free_deparse_comments_result(PgQueryDeparseCommentsResult result);
127155
void pg_query_free_protobuf_parse_result(PgQueryProtobufParseResult result);
128156
void pg_query_free_plpgsql_parse_result(PgQueryPlpgsqlParseResult result);
129157
void pg_query_free_fingerprint_result(PgQueryFingerprintResult result);
158+
void pg_query_free_is_utility_result(PgQueryIsUtilityResult result);
159+
void pg_query_free_summary_parse_result(PgQuerySummaryParseResult result);
130160

131161
// Optional, cleans up the top-level memory context (automatically done for threads that exit)
132162
void pg_query_exit(void);
133163

134164
// Postgres version information
135165
#define PG_MAJORVERSION "17"
136-
#define PG_VERSION "17.4"
137-
#define PG_VERSION_NUM 170004
166+
#define PG_VERSION "17.7"
167+
#define PG_VERSION_NUM 170007
138168

139169
// Deprecated APIs below
140170

parser/include/postgres/access/amapi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ typedef struct IndexAmRoutine
271271
ambuild_function ambuild;
272272
ambuildempty_function ambuildempty;
273273
aminsert_function aminsert;
274-
aminsertcleanup_function aminsertcleanup;
274+
aminsertcleanup_function aminsertcleanup; /* can be NULL */
275275
ambulkdelete_function ambulkdelete;
276276
amvacuumcleanup_function amvacuumcleanup;
277277
amcanreturn_function amcanreturn; /* can be NULL */

parser/include/postgres/access/slru.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ typedef enum
5555
/*
5656
* Shared-memory state
5757
*
58-
* ControlLock is used to protect access to the other fields, except
58+
* SLRU bank locks are used to protect access to the other fields, except
5959
* latest_page_number, which uses atomics; see comment in slru.c.
6060
*/
6161
typedef struct SlruSharedData

parser/include/postgres/access/tableam.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ typedef enum TU_UpdateIndexes
129129
/*
130130
* When table_tuple_update, table_tuple_delete, or table_tuple_lock fail
131131
* because the target tuple is already outdated, they fill in this struct to
132-
* provide information to the caller about what happened.
132+
* provide information to the caller about what happened. When those functions
133+
* succeed, the contents of this struct should not be relied upon, except for
134+
* `traversed`, which may be set in both success and failure cases.
133135
*
134136
* ctid is the target's ctid link: it is the same as the target's TID if the
135137
* target was deleted, or the location of the replacement tuple if the target
@@ -145,6 +147,9 @@ typedef enum TU_UpdateIndexes
145147
* tuple); otherwise cmax is zero. (We make this restriction because
146148
* HeapTupleHeaderGetCmax doesn't work for tuples outdated in other
147149
* transactions.)
150+
*
151+
* traversed indicates if an update chain was followed in order to try to lock
152+
* the target tuple. (This may be set in both success and failure cases.)
148153
*/
149154
typedef struct TM_FailureData
150155
{
@@ -1549,7 +1554,7 @@ table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
15491554
*
15501555
* Input parameters:
15511556
* relation: relation containing tuple (caller must hold suitable lock)
1552-
* tid: TID of tuple to lock
1557+
* tid: TID of tuple to lock (updated if an update chain was followed)
15531558
* snapshot: snapshot to use for visibility determinations
15541559
* cid: current command ID (used for visibility test, and stored into
15551560
* tuple's cmax if lock is successful)
@@ -1574,8 +1579,10 @@ table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
15741579
* TM_WouldBlock: lock couldn't be acquired and wait_policy is skip
15751580
*
15761581
* In the failure cases other than TM_Invisible and TM_Deleted, the routine
1577-
* fills *tmfd with the tuple's t_ctid, t_xmax, and, if possible, t_cmax. See
1578-
* comments for struct TM_FailureData for additional info.
1582+
* fills *tmfd with the tuple's t_ctid, t_xmax, and, if possible, t_cmax.
1583+
* Additionally, in both success and failure cases, tmfd->traversed is set if
1584+
* an update chain was followed. See comments for struct TM_FailureData for
1585+
* additional info.
15791586
*/
15801587
static inline TM_Result
15811588
table_tuple_lock(Relation rel, ItemPointer tid, Snapshot snapshot,

parser/include/postgres/access/xlog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ extern void SwitchIntoArchiveRecovery(XLogRecPtr EndRecPtr, TimeLineID replayTLI
265265
extern void ReachedEndOfBackup(XLogRecPtr EndRecPtr, TimeLineID tli);
266266
extern void SetInstallXLogFileSegmentActive(void);
267267
extern bool IsInstallXLogFileSegmentActive(void);
268+
extern void ResetInstallXLogFileSegmentActive(void);
268269
extern void XLogShutdownWalRcv(void);
269270

270271
/*

0 commit comments

Comments
 (0)