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

Makefile

Lines changed: 14 additions & 7 deletions
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

pg_query.h

Lines changed: 2 additions & 2 deletions
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

scripts/pg_config_overrides.h

Lines changed: 10 additions & 2 deletions
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 */

src/postgres/include/access/amapi.h

Lines changed: 4 additions & 0 deletions
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
{

src/postgres/include/access/genam.h

Lines changed: 9 additions & 0 deletions
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 */

src/postgres/include/access/slru.h

Lines changed: 3 additions & 6 deletions
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

src/postgres/include/access/tableam.h

Lines changed: 2 additions & 1 deletion
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

src/postgres/include/access/transam.h

Lines changed: 43 additions & 0 deletions
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 */

src/postgres/include/c.h

Lines changed: 1 addition & 1 deletion
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.

src/postgres/include/catalog/objectaddress.h

Lines changed: 4 additions & 0 deletions
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);

0 commit comments

Comments
 (0)