Skip to content

Commit f219796

Browse files
committed
Refresh to 17.4 patch release + subsequent changes planned for 17.5
This pulls in the strchrnul compatibility patch directly from upstream, instead of applying it manually. Other updates since 17.0 are minor and should not affect parser behaviour.
1 parent 6528a7a commit f219796

Some content is hidden

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

77 files changed

+1078
-225
lines changed

Diff for: Makefile

+14-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ TARGET = pg_query
55
ARLIB = lib$(TARGET).a
66
PGDIR = $(root_dir)/tmp/postgres
77
PGDIRBZ2 = $(root_dir)/tmp/postgres.tar.bz2
8+
PGDIRZIP = $(root_dir)/tmp/postgres.zip
89

9-
PG_VERSION = 17.0
10+
PG_VERSION = 17.4
1011
PG_VERSION_MAJOR = $(call word-dot,$(PG_VERSION),1)
11-
PG_VERSION_NUM = 170000
12+
PG_VERSION_NUM = 170004
13+
PG_BRANCH = REL_17_STABLE
1214
PROTOC_VERSION = 25.1
1315

1416
VERSION = 5.1.0
@@ -64,7 +66,7 @@ endif
6466

6567
CLEANLIBS = $(ARLIB)
6668
CLEANOBJS = $(OBJ_FILES)
67-
CLEANFILES = $(PGDIRBZ2)
69+
CLEANFILES = $(PGDIRBZ2) $(PGDIRZIP)
6870

6971
AR ?= ar
7072
AR := $(AR) rs
@@ -109,14 +111,19 @@ build_shared: $(SOLIB)
109111
clean:
110112
-@ $(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) $(EXAMPLES) $(TESTS)
111113
-@ $(RM) -rf {test,examples}/*.dSYM
112-
-@ $(RM) -r $(PGDIR) $(PGDIRBZ2)
114+
-@ $(RM) -r $(PGDIR) $(PGDIRBZ2) $(PGDIRZIP)
113115

114116
.PHONY: all clean build build_shared extract_source examples test install
115117

116118
$(PGDIR):
117-
curl -o $(PGDIRBZ2) https://ftp.postgresql.org/pub/source/v$(PG_VERSION)/postgresql-$(PG_VERSION).tar.bz2
118-
tar -xjf $(PGDIRBZ2)
119-
mv $(root_dir)/postgresql-$(PG_VERSION) $(PGDIR)
119+
# We temporarily build off REL_17_STABLE to pull in https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=6da2ba1d8a031984eb016fed6741bb2ac945f19d
120+
# TODO: Go back to upstream tarball once 17.5 is released
121+
# tar -xjf $(PGDIRBZ2)
122+
# curl -o $(PGDIRBZ2) https://ftp.postgresql.org/pub/source/v$(PG_VERSION)/postgresql-$(PG_VERSION).tar.bz2
123+
# mv $(root_dir)/postgresql-$(PG_VERSION) $(PGDIR)
124+
curl -L -o $(PGDIRZIP) https://github.com/postgres/postgres/archive/refs/heads/$(PG_BRANCH).zip
125+
unzip $(PGDIRZIP)
126+
mv $(root_dir)/postgres-$(PG_BRANCH) $(PGDIR)
120127
cd $(PGDIR); patch -p1 < $(root_dir)/patches/01_parser_additional_param_ref_support.patch
121128
cd $(PGDIR); patch -p1 < $(root_dir)/patches/03_lexer_track_yyllocend.patch
122129
cd $(PGDIR); patch -p1 < $(root_dir)/patches/04_lexer_comments_as_tokens.patch

Diff for: pg_query.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ void pg_query_exit(void);
133133

134134
// Postgres version information
135135
#define PG_MAJORVERSION "17"
136-
#define PG_VERSION "17.0"
137-
#define PG_VERSION_NUM 170000
136+
#define PG_VERSION "17.4"
137+
#define PG_VERSION_NUM 170004
138138

139139
// Deprecated APIs below
140140

Diff for: scripts/pg_config_overrides.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@
2121
#undef USE_ARMV8_CRC32C
2222
#undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK
2323

24-
/* Ensure we do not fail on systems that have strchrnul support (FreeBSD, NetBSD and newer glibc) */
24+
/*
25+
* Ensure we use built-in strchrnul on systems that have strchrnul support (FreeBSD, NetBSD and newer glibc)
26+
*
27+
* Note MacOS 15.4+ also has strchrnul implemented, but is complex to handle correctly, and the code works
28+
* around the double define.
29+
*/
2530
#include <stdlib.h>
31+
#undef HAVE_DECL_STRCHRNUL
2632
#if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) || __GLIBC__ > 2))
27-
#define HAVE_STRCHRNUL
33+
#define HAVE_DECL_STRCHRNUL 1
34+
#else
35+
#define HAVE_DECL_STRCHRNUL 0
2836
#endif
2937

3038
/* 32-bit */

Diff for: src/postgres/include/access/amapi.h

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ typedef enum IndexAMProperty
7676
* opfamily. This allows ALTER OPERATOR FAMILY DROP, and causes that to
7777
* happen automatically if the operator or support func is dropped. This
7878
* is the right behavior for inessential ("loose") objects.
79+
*
80+
* We also make dependencies on lefttype/righttype, of the same strength as
81+
* the dependency on the operator or support func, unless these dependencies
82+
* are redundant with the dependency on the operator or support func.
7983
*/
8084
typedef struct OpFamilyMember
8185
{

Diff for: src/postgres/include/access/genam.h

+9
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,14 @@ extern SysScanDesc systable_beginscan_ordered(Relation heapRelation,
233233
extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan,
234234
ScanDirection direction);
235235
extern void systable_endscan_ordered(SysScanDesc sysscan);
236+
extern void systable_inplace_update_begin(Relation relation,
237+
Oid indexId,
238+
bool indexOK,
239+
Snapshot snapshot,
240+
int nkeys, const ScanKeyData *key,
241+
HeapTuple *oldtupcopy,
242+
void **state);
243+
extern void systable_inplace_update_finish(void *state, HeapTuple tuple);
244+
extern void systable_inplace_update_cancel(void *state);
236245

237246
#endif /* GENAM_H */

Diff for: src/postgres/include/access/slru.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ typedef struct SlruCtlData
128128
{
129129
SlruShared shared;
130130

131-
/*
132-
* Bitmask to determine bank number from page number.
133-
*/
134-
bits16 bank_mask;
131+
/* Number of banks in this SLRU. */
132+
uint16 nbanks;
135133

136134
/*
137135
* If true, use long segment file names. Otherwise, use short file names.
@@ -163,7 +161,6 @@ typedef struct SlruCtlData
163161
* it's always the same, it doesn't need to be in shared memory.
164162
*/
165163
char Dir[64];
166-
167164
} SlruCtlData;
168165

169166
typedef SlruCtlData *SlruCtl;
@@ -179,7 +176,7 @@ SimpleLruGetBankLock(SlruCtl ctl, int64 pageno)
179176
{
180177
int bankno;
181178

182-
bankno = pageno & ctl->bank_mask;
179+
bankno = pageno % ctl->nbanks;
183180
return &(ctl->shared->bank_locks[bankno].lock);
184181
}
185182

Diff for: src/postgres/include/access/tableam.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ typedef enum TU_UpdateIndexes
137137
*
138138
* xmax is the outdating transaction's XID. If the caller wants to visit the
139139
* replacement tuple, it must check that this matches before believing the
140-
* replacement is really a match.
140+
* replacement is really a match. This is InvalidTransactionId if the target
141+
* was !LP_NORMAL (expected only for a TID retrieved from syscache).
141142
*
142143
* cmax is the outdating command's CID, but only when the failure code is
143144
* TM_SelfModified (i.e., something in the current transaction outdated the

Diff for: src/postgres/include/access/transam.h

+43
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,49 @@ FullTransactionIdNewer(FullTransactionId a, FullTransactionId b)
370370
return b;
371371
}
372372

373+
/*
374+
* Compute FullTransactionId for the given TransactionId, assuming xid was
375+
* between [oldestXid, nextXid] at the time when TransamVariables->nextXid was
376+
* nextFullXid. When adding calls, evaluate what prevents xid from preceding
377+
* oldestXid if SetTransactionIdLimit() runs between the collection of xid and
378+
* the collection of nextFullXid.
379+
*/
380+
static inline FullTransactionId
381+
FullTransactionIdFromAllowableAt(FullTransactionId nextFullXid,
382+
TransactionId xid)
383+
{
384+
uint32 epoch;
385+
386+
/* Special transaction ID. */
387+
if (!TransactionIdIsNormal(xid))
388+
return FullTransactionIdFromEpochAndXid(0, xid);
389+
390+
Assert(TransactionIdPrecedesOrEquals(xid,
391+
XidFromFullTransactionId(nextFullXid)));
392+
393+
/*
394+
* The 64 bit result must be <= nextFullXid, since nextFullXid hadn't been
395+
* issued yet when xid was in the past. The xid must therefore be from
396+
* the epoch of nextFullXid or the epoch before. We know this because we
397+
* must remove (by freezing) an XID before assigning the XID half an epoch
398+
* ahead of it.
399+
*
400+
* The unlikely() branch hint is dubious. It's perfect for the first 2^32
401+
* XIDs of a cluster's life. Right at 2^32 XIDs, misprediction shoots to
402+
* 100%, then improves until perfection returns 2^31 XIDs later. Since
403+
* current callers pass relatively-recent XIDs, expect >90% prediction
404+
* accuracy overall. This favors average latency over tail latency.
405+
*/
406+
epoch = EpochFromFullTransactionId(nextFullXid);
407+
if (unlikely(xid > XidFromFullTransactionId(nextFullXid)))
408+
{
409+
Assert(epoch != 0);
410+
epoch--;
411+
}
412+
413+
return FullTransactionIdFromEpochAndXid(epoch, xid);
414+
}
415+
373416
#endif /* FRONTEND */
374417

375418
#endif /* TRANSAM_H */

Diff for: src/postgres/include/c.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ typedef void (*pg_funcptr_t) (void);
435435
* bool
436436
* Boolean value, either true or false.
437437
*
438-
* We use stdbool.h if available and its bool has size 1. That's useful for
438+
* We use stdbool.h if bool has size 1 after including it. That's useful for
439439
* better compiler and debugger output and for compatibility with third-party
440440
* libraries. But PostgreSQL currently cannot deal with bool of other sizes;
441441
* there are static assertions around the code to prevent that.

Diff for: src/postgres/include/catalog/objectaddress.h

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ extern bool get_object_namensp_unique(Oid class_id);
6969

7070
extern HeapTuple get_catalog_object_by_oid(Relation catalog,
7171
AttrNumber oidcol, Oid objectId);
72+
extern HeapTuple get_catalog_object_by_oid_extended(Relation catalog,
73+
AttrNumber oidcol,
74+
Oid objectId,
75+
bool locktup);
7276

7377
extern char *getObjectDescription(const ObjectAddress *object,
7478
bool missing_ok);

Diff for: src/postgres/include/commands/event_trigger.h

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ typedef struct EventTriggerData
3131

3232
extern PGDLLIMPORT bool event_triggers;
3333

34+
/*
35+
* Reasons for relation rewrites.
36+
*
37+
* pg_event_trigger_table_rewrite_reason() uses these values, so make sure to
38+
* update the documentation when changing this list.
39+
*/
3440
#define AT_REWRITE_ALTER_PERSISTENCE 0x01
3541
#define AT_REWRITE_DEFAULT_VAL 0x02
3642
#define AT_REWRITE_COLUMN_REWRITE 0x04

Diff for: src/postgres/include/common/hashfn_unstable.h

+6-52
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#ifndef HASHFN_UNSTABLE_H
1515
#define HASHFN_UNSTABLE_H
1616

17-
#include "port/pg_bitutils.h"
18-
#include "port/pg_bswap.h"
1917

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

222-
/* get first byte in memory order */
223-
#ifdef WORDS_BIGENDIAN
224-
#define firstbyte64(v) ((v) >> 56)
225-
#else
226-
#define firstbyte64(v) ((v) & 0xFF)
227-
#endif
228-
229220
/*
230221
* all-purpose workhorse for fasthash_accum_cstring
231222
*/
@@ -262,33 +253,20 @@ static inline size_t
262253
fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
263254
{
264255
const char *const start = str;
265-
uint64 chunk;
256+
size_t remainder;
266257
uint64 zero_byte_low;
267258

268259
Assert(PointerIsAligned(start, uint64));
269260

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

287-
#ifdef WORDS_BIGENDIAN
288-
zero_byte_low = haszero64(pg_bswap64(chunk));
289-
#else
290269
zero_byte_low = haszero64(chunk);
291-
#endif
292270
if (zero_byte_low)
293271
break;
294272

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

300-
if (firstbyte64(chunk) != 0)
301-
{
302-
size_t remainder;
303-
uint64 mask;
304-
305-
/*
306-
* The byte corresponding to the NUL will be 0x80, so the rightmost
307-
* bit position will be in the range 15, 23, ..., 63. Turn this into
308-
* byte position by dividing by 8.
309-
*/
310-
remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;
311-
312-
/*
313-
* Create a mask for the remaining bytes so we can combine them into
314-
* the hash. This must have the same result as mixing the remaining
315-
* bytes with fasthash_accum().
316-
*/
317-
#ifdef WORDS_BIGENDIAN
318-
mask = ~UINT64CONST(0) << BITS_PER_BYTE * (FH_SIZEOF_ACCUM - remainder);
319-
#else
320-
mask = ~UINT64CONST(0) >> BITS_PER_BYTE * (FH_SIZEOF_ACCUM - remainder);
321-
#endif
322-
hs->accum = chunk & mask;
323-
fasthash_combine(hs);
324-
325-
str += remainder;
326-
}
278+
/* mix in remaining bytes */
279+
remainder = fasthash_accum_cstring_unaligned(hs, str);
280+
str += remainder;
327281

328282
return str - start;
329283
}

Diff for: src/postgres/include/datatype/timestamp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ struct pg_itm_in
136136
/*
137137
* We allow numeric timezone offsets up to 15:59:59 either way from Greenwich.
138138
* Currently, the record holders for wackiest offsets in actual use are zones
139-
* Asia/Manila, at -15:56:00 until 1844, and America/Metlakatla, at +15:13:42
139+
* Asia/Manila, at -15:56:08 until 1844, and America/Metlakatla, at +15:13:42
140140
* until 1867. If we were to reject such values we would fail to dump and
141141
* restore old timestamptz values with these zone settings.
142142
*/

Diff for: src/postgres/include/executor/execdesc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct QueryDesc
4848
EState *estate; /* executor's query-wide state */
4949
PlanState *planstate; /* tree of per-plan-node state */
5050

51-
/* This field is set by ExecutorRun */
51+
/* This field is set by ExecutePlan */
5252
bool already_executed; /* true if previously executed */
5353

5454
/* This is always set NULL by the core system, but plugins can change it */

Diff for: src/postgres/include/libpq/libpq-be.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ typedef struct Port
189189
/*
190190
* If GSSAPI is supported and used on this connection, store GSSAPI
191191
* information. Even when GSSAPI is not compiled in, store a NULL pointer
192-
* to keep struct offsets the same (for extension ABI compatibility).
192+
* to keep struct offsets of the "SSL structures" below the same (for
193+
* extension ABI compatibility).
193194
*/
194195
pg_gssinfo *gss;
195196
#else
@@ -206,8 +207,7 @@ typedef struct Port
206207
bool alpn_used;
207208

208209
/*
209-
* OpenSSL structures. (Keep these last so that the locations of other
210-
* fields are the same whether or not you build with SSL enabled.)
210+
* OpenSSL structures.
211211
*/
212212
#ifdef USE_OPENSSL
213213
SSL *ssl;
@@ -222,6 +222,9 @@ typedef struct Port
222222
* There's no API to "unread", the upper layer just places the data in the
223223
* Port structure in raw_buf and sets raw_buf_remaining to the amount of
224224
* bytes unread and raw_buf_consumed to 0.
225+
*
226+
* NB: the offsets of these fields depend on USE_OPENSSL. These should
227+
* not be accessed in an extension because of the ABI incompatibility.
225228
*/
226229
char *raw_buf;
227230
ssize_t raw_buf_consumed,

Diff for: src/postgres/include/mb/pg_wchar.h

+1
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ extern int pg_valid_server_encoding_id(int encoding);
662662
* (in addition to the ones just above). The constant tables declared
663663
* earlier in this file are also available from libpgcommon.
664664
*/
665+
extern void pg_encoding_set_invalid(int encoding, char *dst);
665666
extern int pg_encoding_mblen(int encoding, const char *mbstr);
666667
extern int pg_encoding_mblen_bounded(int encoding, const char *mbstr);
667668
extern int pg_encoding_dsplen(int encoding, const char *mbstr);

0 commit comments

Comments
 (0)