Skip to content

Commit 7fdb0f3

Browse files
committed
bump pg_query
1 parent 38c866d commit 7fdb0f3

40 files changed

+513
-332
lines changed

Diff for: Makefile

+1-1
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.0.0
19+
LIB_PG_QUERY_TAG = f2197968161ac7cf72dbaaef713c4051bd3585f5
2020

2121
root_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2222
LIB_TMPDIR = $(root_dir)/tmp

Diff for: parse_test.go

+18-18
Large diffs are not rendered by default.

Diff for: parser/include/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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: parser/include/postgres/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);

Diff for: parser/include/postgres/miscadmin.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,9 @@ typedef enum BackendType
346346

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

372373
extern PGDLLIMPORT BackendType MyBackendType;
373374

375+
#define AmRegularBackendProcess() (MyBackendType == B_BACKEND)
374376
#define AmAutoVacuumLauncherProcess() (MyBackendType == B_AUTOVAC_LAUNCHER)
375377
#define AmAutoVacuumWorkerProcess() (MyBackendType == B_AUTOVAC_WORKER)
376378
#define AmBackgroundWorkerProcess() (MyBackendType == B_BG_WORKER)
@@ -384,6 +386,10 @@ extern PGDLLIMPORT BackendType MyBackendType;
384386
#define AmWalSummarizerProcess() (MyBackendType == B_WAL_SUMMARIZER)
385387
#define AmWalWriterProcess() (MyBackendType == B_WAL_WRITER)
386388

389+
#define AmSpecialWorkerProcess() \
390+
(AmAutoVacuumLauncherProcess() || \
391+
AmLogicalSlotSyncWorkerProcess())
392+
387393
extern const char *GetBackendTypeDesc(BackendType backendType);
388394

389395
extern void SetDatabasePath(const char *path);
@@ -395,7 +401,9 @@ extern char *GetUserNameFromId(Oid roleid, bool noerr);
395401
extern Oid GetUserId(void);
396402
extern Oid GetOuterUserId(void);
397403
extern Oid GetSessionUserId(void);
404+
extern bool GetSessionUserIsSuperuser(void);
398405
extern Oid GetAuthenticatedUserId(void);
406+
extern void SetAuthenticatedUserId(Oid userid);
399407
extern void GetUserIdAndSecContext(Oid *userid, int *sec_context);
400408
extern void SetUserIdAndSecContext(Oid userid, int sec_context);
401409
extern bool InLocalUserIdChange(void);

Diff for: parser/include/postgres/nodes/execnodes.h

+3
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ typedef struct ResultRelInfo
484484
/* Have the projection and the slots above been initialized? */
485485
bool ri_projectNewInfoValid;
486486

487+
/* updates do LockTuple() before oldtup read; see README.tuplock */
488+
bool ri_needLockTagTuple;
489+
487490
/* triggers to be fired, if any */
488491
TriggerDesc *ri_TrigDesc;
489492

Diff for: parser/include/postgres/nodes/pathnodes.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,9 @@ typedef struct IndexOptInfo IndexOptInfo;
11011101
#define HAVE_INDEXOPTINFO_TYPEDEF 1
11021102
#endif
11031103

1104+
struct IndexPath; /* avoid including pathnodes.h here */
1105+
struct PlannerInfo; /* avoid including pathnodes.h here */
1106+
11041107
struct IndexOptInfo
11051108
{
11061109
pg_node_attr(no_copy_equal, no_read, no_query_jumble)
@@ -1200,7 +1203,7 @@ struct IndexOptInfo
12001203
bool amcanmarkpos;
12011204
/* AM's cost estimator */
12021205
/* Rather than include amapi.h here, we declare amcostestimate like this */
1203-
void (*amcostestimate) () pg_node_attr(read_write_ignore);
1206+
void (*amcostestimate) (struct PlannerInfo *, struct IndexPath *, double, Cost *, Cost *, Selectivity *, double *, double *) pg_node_attr(read_write_ignore);
12041207
};
12051208

12061209
/*

0 commit comments

Comments
 (0)