Skip to content

Update to libpg_query 17-6.1.0 #134

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

Merged
merged 3 commits into from
Apr 3, 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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

* ...

## 6.1.0 2025-02-24

* Upgrade to libpg_query 17-6.1.0
- Update to Postgres 17.4, and add recent patches scheduled for Postgres 17.5 (not yet released)
- Notably, this pulls in support for macOS 15.4 which defines strchrnul
in its standard library, fixing builds on up-to-date macOS versions.
- Deparser improvements
- Add parenthesis around AT LOCAL / AT TIMEZONE if needed
- Correctness improvements related to expressions and function calls
* Allow vendoring pg_query_go with built-in "go mod vendor" command [(#131)](https://github.com/pganalyze/pg_query_go/pull/131)


## 6.0.0 2024-11-26

* Upgrade to libpg_query 17-6.0.0
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ benchmark:

# --- Below only needed for releasing new versions

LIB_PG_QUERY_TAG = 17-6.0.0
LIB_PG_QUERY_TAG = 17-6.1.0

root_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
LIB_TMPDIR = $(root_dir)/tmp
Expand Down
36 changes: 18 additions & 18 deletions parse_test.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions parser/include/pg_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ void pg_query_exit(void);

// Postgres version information
#define PG_MAJORVERSION "17"
#define PG_VERSION "17.0"
#define PG_VERSION_NUM 170000
#define PG_VERSION "17.4"
#define PG_VERSION_NUM 170004

// Deprecated APIs below

Expand Down
4 changes: 4 additions & 0 deletions parser/include/postgres/access/amapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ typedef enum IndexAMProperty
* opfamily. This allows ALTER OPERATOR FAMILY DROP, and causes that to
* happen automatically if the operator or support func is dropped. This
* is the right behavior for inessential ("loose") objects.
*
* We also make dependencies on lefttype/righttype, of the same strength as
* the dependency on the operator or support func, unless these dependencies
* are redundant with the dependency on the operator or support func.
*/
typedef struct OpFamilyMember
{
Expand Down
9 changes: 9 additions & 0 deletions parser/include/postgres/access/genam.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,14 @@ extern SysScanDesc systable_beginscan_ordered(Relation heapRelation,
extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan,
ScanDirection direction);
extern void systable_endscan_ordered(SysScanDesc sysscan);
extern void systable_inplace_update_begin(Relation relation,
Oid indexId,
bool indexOK,
Snapshot snapshot,
int nkeys, const ScanKeyData *key,
HeapTuple *oldtupcopy,
void **state);
extern void systable_inplace_update_finish(void *state, HeapTuple tuple);
extern void systable_inplace_update_cancel(void *state);

#endif /* GENAM_H */
9 changes: 3 additions & 6 deletions parser/include/postgres/access/slru.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ typedef struct SlruCtlData
{
SlruShared shared;

/*
* Bitmask to determine bank number from page number.
*/
bits16 bank_mask;
/* Number of banks in this SLRU. */
uint16 nbanks;

/*
* If true, use long segment file names. Otherwise, use short file names.
Expand Down Expand Up @@ -163,7 +161,6 @@ typedef struct SlruCtlData
* it's always the same, it doesn't need to be in shared memory.
*/
char Dir[64];

} SlruCtlData;

typedef SlruCtlData *SlruCtl;
Expand All @@ -179,7 +176,7 @@ SimpleLruGetBankLock(SlruCtl ctl, int64 pageno)
{
int bankno;

bankno = pageno & ctl->bank_mask;
bankno = pageno % ctl->nbanks;
return &(ctl->shared->bank_locks[bankno].lock);
}

Expand Down
3 changes: 2 additions & 1 deletion parser/include/postgres/access/tableam.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ typedef enum TU_UpdateIndexes
*
* xmax is the outdating transaction's XID. If the caller wants to visit the
* replacement tuple, it must check that this matches before believing the
* replacement is really a match.
* replacement is really a match. This is InvalidTransactionId if the target
* was !LP_NORMAL (expected only for a TID retrieved from syscache).
*
* cmax is the outdating command's CID, but only when the failure code is
* TM_SelfModified (i.e., something in the current transaction outdated the
Expand Down
43 changes: 43 additions & 0 deletions parser/include/postgres/access/transam.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,49 @@ FullTransactionIdNewer(FullTransactionId a, FullTransactionId b)
return b;
}

/*
* Compute FullTransactionId for the given TransactionId, assuming xid was
* between [oldestXid, nextXid] at the time when TransamVariables->nextXid was
* nextFullXid. When adding calls, evaluate what prevents xid from preceding
* oldestXid if SetTransactionIdLimit() runs between the collection of xid and
* the collection of nextFullXid.
*/
static inline FullTransactionId
FullTransactionIdFromAllowableAt(FullTransactionId nextFullXid,
TransactionId xid)
{
uint32 epoch;

/* Special transaction ID. */
if (!TransactionIdIsNormal(xid))
return FullTransactionIdFromEpochAndXid(0, xid);

Assert(TransactionIdPrecedesOrEquals(xid,
XidFromFullTransactionId(nextFullXid)));

/*
* The 64 bit result must be <= nextFullXid, since nextFullXid hadn't been
* issued yet when xid was in the past. The xid must therefore be from
* the epoch of nextFullXid or the epoch before. We know this because we
* must remove (by freezing) an XID before assigning the XID half an epoch
* ahead of it.
*
* The unlikely() branch hint is dubious. It's perfect for the first 2^32
* XIDs of a cluster's life. Right at 2^32 XIDs, misprediction shoots to
* 100%, then improves until perfection returns 2^31 XIDs later. Since
* current callers pass relatively-recent XIDs, expect >90% prediction
* accuracy overall. This favors average latency over tail latency.
*/
epoch = EpochFromFullTransactionId(nextFullXid);
if (unlikely(xid > XidFromFullTransactionId(nextFullXid)))
{
Assert(epoch != 0);
epoch--;
}

return FullTransactionIdFromEpochAndXid(epoch, xid);
}

#endif /* FRONTEND */

#endif /* TRANSAM_H */
2 changes: 1 addition & 1 deletion parser/include/postgres/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ typedef void (*pg_funcptr_t) (void);
* bool
* Boolean value, either true or false.
*
* We use stdbool.h if available and its bool has size 1. That's useful for
* We use stdbool.h if bool has size 1 after including it. That's useful for
* better compiler and debugger output and for compatibility with third-party
* libraries. But PostgreSQL currently cannot deal with bool of other sizes;
* there are static assertions around the code to prevent that.
Expand Down
4 changes: 4 additions & 0 deletions parser/include/postgres/catalog/objectaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ extern bool get_object_namensp_unique(Oid class_id);

extern HeapTuple get_catalog_object_by_oid(Relation catalog,
AttrNumber oidcol, Oid objectId);
extern HeapTuple get_catalog_object_by_oid_extended(Relation catalog,
AttrNumber oidcol,
Oid objectId,
bool locktup);

extern char *getObjectDescription(const ObjectAddress *object,
bool missing_ok);
Expand Down
6 changes: 6 additions & 0 deletions parser/include/postgres/commands/event_trigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ typedef struct EventTriggerData

extern PGDLLIMPORT bool event_triggers;

/*
* Reasons for relation rewrites.
*
* pg_event_trigger_table_rewrite_reason() uses these values, so make sure to
* update the documentation when changing this list.
*/
#define AT_REWRITE_ALTER_PERSISTENCE 0x01
#define AT_REWRITE_DEFAULT_VAL 0x02
#define AT_REWRITE_COLUMN_REWRITE 0x04
Expand Down
58 changes: 6 additions & 52 deletions parser/include/postgres/common/hashfn_unstable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#ifndef HASHFN_UNSTABLE_H
#define HASHFN_UNSTABLE_H

#include "port/pg_bitutils.h"
#include "port/pg_bswap.h"

/*
* fasthash is a modification of code taken from
Expand Down Expand Up @@ -219,13 +217,6 @@ fasthash_accum(fasthash_state *hs, const char *k, size_t len)
#define haszero64(v) \
(((v) - 0x0101010101010101) & ~(v) & 0x8080808080808080)

/* get first byte in memory order */
#ifdef WORDS_BIGENDIAN
#define firstbyte64(v) ((v) >> 56)
#else
#define firstbyte64(v) ((v) & 0xFF)
#endif

/*
* all-purpose workhorse for fasthash_accum_cstring
*/
Expand Down Expand Up @@ -262,33 +253,20 @@ static inline size_t
fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
{
const char *const start = str;
uint64 chunk;
size_t remainder;
uint64 zero_byte_low;

Assert(PointerIsAligned(start, uint64));

/*
* For every chunk of input, check for zero bytes before mixing into the
* hash. The chunk with zeros must contain the NUL terminator. We arrange
* so that zero_byte_low tells us not only that a zero exists, but also
* where it is, so we can hash the remainder of the string.
*
* The haszero64 calculation will set bits corresponding to the lowest
* byte where a zero exists, so that suffices for little-endian machines.
* For big-endian machines, we would need bits set for the highest zero
* byte in the chunk, since the trailing junk past the terminator could
* contain additional zeros. haszero64 does not give us that, so we
* byteswap the chunk first.
* hash. The chunk with zeros must contain the NUL terminator.
*/
for (;;)
{
chunk = *(uint64 *) str;
uint64 chunk = *(uint64 *) str;

#ifdef WORDS_BIGENDIAN
zero_byte_low = haszero64(pg_bswap64(chunk));
#else
zero_byte_low = haszero64(chunk);
#endif
if (zero_byte_low)
break;

Expand All @@ -297,33 +275,9 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
str += FH_SIZEOF_ACCUM;
}

if (firstbyte64(chunk) != 0)
{
size_t remainder;
uint64 mask;

/*
* The byte corresponding to the NUL will be 0x80, so the rightmost
* bit position will be in the range 15, 23, ..., 63. Turn this into
* byte position by dividing by 8.
*/
remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;

/*
* Create a mask for the remaining bytes so we can combine them into
* the hash. This must have the same result as mixing the remaining
* bytes with fasthash_accum().
*/
#ifdef WORDS_BIGENDIAN
mask = ~UINT64CONST(0) << BITS_PER_BYTE * (FH_SIZEOF_ACCUM - remainder);
#else
mask = ~UINT64CONST(0) >> BITS_PER_BYTE * (FH_SIZEOF_ACCUM - remainder);
#endif
hs->accum = chunk & mask;
fasthash_combine(hs);

str += remainder;
}
/* mix in remaining bytes */
remainder = fasthash_accum_cstring_unaligned(hs, str);
str += remainder;

return str - start;
}
Expand Down
2 changes: 1 addition & 1 deletion parser/include/postgres/datatype/timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct pg_itm_in
/*
* We allow numeric timezone offsets up to 15:59:59 either way from Greenwich.
* Currently, the record holders for wackiest offsets in actual use are zones
* Asia/Manila, at -15:56:00 until 1844, and America/Metlakatla, at +15:13:42
* Asia/Manila, at -15:56:08 until 1844, and America/Metlakatla, at +15:13:42
* until 1867. If we were to reject such values we would fail to dump and
* restore old timestamptz values with these zone settings.
*/
Expand Down
2 changes: 1 addition & 1 deletion parser/include/postgres/executor/execdesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef struct QueryDesc
EState *estate; /* executor's query-wide state */
PlanState *planstate; /* tree of per-plan-node state */

/* This field is set by ExecutorRun */
/* This field is set by ExecutePlan */
bool already_executed; /* true if previously executed */

/* This is always set NULL by the core system, but plugins can change it */
Expand Down
9 changes: 6 additions & 3 deletions parser/include/postgres/libpq/libpq-be.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ typedef struct Port
/*
* If GSSAPI is supported and used on this connection, store GSSAPI
* information. Even when GSSAPI is not compiled in, store a NULL pointer
* to keep struct offsets the same (for extension ABI compatibility).
* to keep struct offsets of the "SSL structures" below the same (for
* extension ABI compatibility).
*/
pg_gssinfo *gss;
#else
Expand All @@ -206,8 +207,7 @@ typedef struct Port
bool alpn_used;

/*
* OpenSSL structures. (Keep these last so that the locations of other
* fields are the same whether or not you build with SSL enabled.)
* OpenSSL structures.
*/
#ifdef USE_OPENSSL
SSL *ssl;
Expand All @@ -222,6 +222,9 @@ typedef struct Port
* There's no API to "unread", the upper layer just places the data in the
* Port structure in raw_buf and sets raw_buf_remaining to the amount of
* bytes unread and raw_buf_consumed to 0.
*
* NB: the offsets of these fields depend on USE_OPENSSL. These should
* not be accessed in an extension because of the ABI incompatibility.
*/
char *raw_buf;
ssize_t raw_buf_consumed,
Expand Down
1 change: 1 addition & 0 deletions parser/include/postgres/mb/pg_wchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ extern int pg_valid_server_encoding_id(int encoding);
* (in addition to the ones just above). The constant tables declared
* earlier in this file are also available from libpgcommon.
*/
extern void pg_encoding_set_invalid(int encoding, char *dst);
extern int pg_encoding_mblen(int encoding, const char *mbstr);
extern int pg_encoding_mblen_bounded(int encoding, const char *mbstr);
extern int pg_encoding_dsplen(int encoding, const char *mbstr);
Expand Down
12 changes: 10 additions & 2 deletions parser/include/postgres/miscadmin.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ typedef enum BackendType

/*
* Auxiliary processes. These have PGPROC entries, but they are not
* attached to any particular database. There can be only one of each of
* these running at a time.
* attached to any particular database, and cannot run transactions or
* even take heavyweight locks. There can be only one of each of these
* running at a time.
*
* If you modify these, make sure to update NUM_AUXILIARY_PROCS and the
* glossary in the docs.
Expand All @@ -371,6 +372,7 @@ typedef enum BackendType

extern PGDLLIMPORT BackendType MyBackendType;

#define AmRegularBackendProcess() (MyBackendType == B_BACKEND)
#define AmAutoVacuumLauncherProcess() (MyBackendType == B_AUTOVAC_LAUNCHER)
#define AmAutoVacuumWorkerProcess() (MyBackendType == B_AUTOVAC_WORKER)
#define AmBackgroundWorkerProcess() (MyBackendType == B_BG_WORKER)
Expand All @@ -384,6 +386,10 @@ extern PGDLLIMPORT BackendType MyBackendType;
#define AmWalSummarizerProcess() (MyBackendType == B_WAL_SUMMARIZER)
#define AmWalWriterProcess() (MyBackendType == B_WAL_WRITER)

#define AmSpecialWorkerProcess() \
(AmAutoVacuumLauncherProcess() || \
AmLogicalSlotSyncWorkerProcess())

extern const char *GetBackendTypeDesc(BackendType backendType);

extern void SetDatabasePath(const char *path);
Expand All @@ -395,7 +401,9 @@ extern char *GetUserNameFromId(Oid roleid, bool noerr);
extern Oid GetUserId(void);
extern Oid GetOuterUserId(void);
extern Oid GetSessionUserId(void);
extern bool GetSessionUserIsSuperuser(void);
extern Oid GetAuthenticatedUserId(void);
extern void SetAuthenticatedUserId(Oid userid);
extern void GetUserIdAndSecContext(Oid *userid, int *sec_context);
extern void SetUserIdAndSecContext(Oid userid, int sec_context);
extern bool InLocalUserIdChange(void);
Expand Down
3 changes: 3 additions & 0 deletions parser/include/postgres/nodes/execnodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ typedef struct ResultRelInfo
/* Have the projection and the slots above been initialized? */
bool ri_projectNewInfoValid;

/* updates do LockTuple() before oldtup read; see README.tuplock */
bool ri_needLockTagTuple;

/* triggers to be fired, if any */
TriggerDesc *ri_TrigDesc;

Expand Down
Loading
Loading