pg_query 6.0.0 → 6.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -1
  3. data/README.md +1 -1
  4. data/Rakefile +5 -4
  5. data/ext/pg_query/ext_symbols_freebsd_with_ruby_abi_version.sym +2 -0
  6. data/ext/pg_query/ext_symbols_openbsd.sym +1 -0
  7. data/ext/pg_query/ext_symbols_openbsd_with_ruby_abi_version.sym +2 -0
  8. data/ext/pg_query/ext_symbols_with_ruby_abi_version.sym +2 -0
  9. data/ext/pg_query/extconf.rb +21 -7
  10. data/ext/pg_query/include/pg_query.h +32 -2
  11. data/ext/pg_query/include/postgres/access/amapi.h +5 -1
  12. data/ext/pg_query/include/postgres/access/genam.h +9 -0
  13. data/ext/pg_query/include/postgres/access/slru.h +4 -7
  14. data/ext/pg_query/include/postgres/access/tableam.h +13 -5
  15. data/ext/pg_query/include/postgres/access/transam.h +43 -0
  16. data/ext/pg_query/include/postgres/access/xlog.h +1 -0
  17. data/ext/pg_query/include/postgres/access/xlogdefs.h +2 -1
  18. data/ext/pg_query/include/postgres/c.h +1 -1
  19. data/ext/pg_query/include/postgres/catalog/objectaddress.h +4 -0
  20. data/ext/pg_query/include/postgres/commands/defrem.h +1 -1
  21. data/ext/pg_query/include/postgres/commands/event_trigger.h +6 -0
  22. data/ext/pg_query/include/postgres/commands/trigger.h +18 -0
  23. data/ext/pg_query/include/postgres/common/hashfn_unstable.h +6 -52
  24. data/ext/pg_query/include/postgres/datatype/timestamp.h +1 -1
  25. data/ext/pg_query/include/postgres/executor/execdesc.h +1 -1
  26. data/ext/pg_query/include/postgres/executor/executor.h +4 -0
  27. data/ext/pg_query/include/postgres/libpq/libpq-be.h +6 -3
  28. data/ext/pg_query/include/postgres/mb/pg_wchar.h +3 -0
  29. data/ext/pg_query/include/postgres/miscadmin.h +12 -3
  30. data/ext/pg_query/include/postgres/nodes/execnodes.h +9 -8
  31. data/ext/pg_query/include/postgres/nodes/pathnodes.h +3 -1
  32. data/ext/pg_query/include/postgres/nodes/pg_list.h +1 -1
  33. data/ext/pg_query/include/postgres/nodes/primnodes.h +9 -5
  34. data/ext/pg_query/include/postgres/parser/parse_coerce.h +3 -0
  35. data/ext/pg_query/include/postgres/pg_config.h +32 -23
  36. data/ext/pg_query/include/postgres/pg_config_manual.h +2 -0
  37. data/ext/pg_query/include/postgres/port/atomics/generic-gcc.h +10 -2
  38. data/ext/pg_query/include/postgres/port/pg_iovec.h +11 -5
  39. data/ext/pg_query/include/postgres/port/win32_port.h +0 -2
  40. data/ext/pg_query/include/postgres/port.h +32 -1
  41. data/ext/pg_query/include/postgres/replication/reorderbuffer.h +38 -27
  42. data/ext/pg_query/include/postgres/replication/slot.h +7 -1
  43. data/ext/pg_query/include/postgres/storage/lockdefs.h +2 -0
  44. data/ext/pg_query/include/postgres/storage/proc.h +13 -16
  45. data/ext/pg_query/include/postgres/storage/smgr.h +5 -2
  46. data/ext/pg_query/include/postgres/utils/catcache.h +1 -0
  47. data/ext/pg_query/include/postgres/utils/elog.h +1 -0
  48. data/ext/pg_query/include/postgres/utils/guc.h +1 -1
  49. data/ext/pg_query/include/postgres/utils/guc_hooks.h +0 -2
  50. data/ext/pg_query/include/postgres/utils/pg_locale.h +5 -0
  51. data/ext/pg_query/include/postgres/utils/pgstat_internal.h +19 -0
  52. data/ext/pg_query/include/postgres/utils/portal.h +1 -1
  53. data/ext/pg_query/include/postgres/utils/syscache.h +5 -0
  54. data/ext/pg_query/include/postgres_deparse.h +34 -0
  55. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +673 -516
  56. data/ext/pg_query/pg_query.pb-c.c +488 -0
  57. data/ext/pg_query/pg_query_deparse.c +148 -15
  58. data/ext/pg_query/pg_query_internal.h +9 -8
  59. data/ext/pg_query/pg_query_is_utility_stmt.c +70 -0
  60. data/ext/pg_query/pg_query_normalize.c +3 -0
  61. data/ext/pg_query/pg_query_raw_tree_walker_supports.c +117 -0
  62. data/ext/pg_query/pg_query_ruby.c +150 -0
  63. data/ext/pg_query/pg_query_summary.c +941 -0
  64. data/ext/pg_query/pg_query_summary.h +109 -0
  65. data/ext/pg_query/pg_query_summary_statement_type.c +797 -0
  66. data/ext/pg_query/pg_query_summary_truncate.c +530 -0
  67. data/ext/pg_query/postgres_deparse.c +4531 -3879
  68. data/ext/pg_query/src_backend_catalog_namespace.c +29 -0
  69. data/ext/pg_query/src_backend_nodes_bitmapset.c +84 -1
  70. data/ext/pg_query/src_backend_nodes_list.c +60 -1
  71. data/ext/pg_query/src_backend_parser_gram.c +740 -733
  72. data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +2 -2
  73. data/ext/pg_query/src_backend_utils_error_elog.c +11 -0
  74. data/ext/pg_query/src_backend_utils_mb_mbutils.c +43 -4
  75. data/ext/pg_query/src_backend_utils_mmgr_alignedalloc.c +22 -7
  76. data/ext/pg_query/src_backend_utils_mmgr_aset.c +3 -3
  77. data/ext/pg_query/src_backend_utils_mmgr_bump.c +1 -1
  78. data/ext/pg_query/src_common_stringinfo.c +20 -0
  79. data/ext/pg_query/src_common_wchar.c +93 -7
  80. data/ext/pg_query/src_port_snprintf.c +14 -17
  81. data/lib/pg_query/deparse.rb +29 -8
  82. data/lib/pg_query/fingerprint.rb +3 -5
  83. data/lib/pg_query/param_refs.rb +1 -1
  84. data/lib/pg_query/parse.rb +24 -7
  85. data/lib/pg_query/parse_error.rb +1 -0
  86. data/lib/pg_query/pg_query_pb.rb +8 -24
  87. data/lib/pg_query/scan.rb +1 -0
  88. data/lib/pg_query/split.rb +20 -0
  89. data/lib/pg_query/treewalker.rb +11 -13
  90. data/lib/pg_query/truncate.rb +17 -19
  91. data/lib/pg_query/version.rb +1 -1
  92. data/lib/pg_query.rb +1 -0
  93. metadata +23 -81
  94. data/ext/pg_query/postgres_deparse.h +0 -9
  95. /data/ext/pg_query/{pg_query_ruby.sym → ext_symbols.sym} +0 -0
  96. /data/ext/pg_query/{pg_query_ruby_freebsd.sym → ext_symbols_freebsd.sym} +0 -0
@@ -210,6 +210,10 @@ extern void standard_ExecutorEnd(QueryDesc *queryDesc);
210
210
  extern void ExecutorRewind(QueryDesc *queryDesc);
211
211
  extern bool ExecCheckPermissions(List *rangeTable,
212
212
  List *rteperminfos, bool ereport_on_violation);
213
+ extern bool ExecCheckOneRelPerms(RTEPermissionInfo *perminfo);
214
+ extern void CheckValidResultRelNew(ResultRelInfo *resultRelInfo, CmdType operation,
215
+ OnConflictAction onConflictAction,
216
+ List *mergeActions);
213
217
  extern void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation,
214
218
  List *mergeActions);
215
219
  extern void InitResultRelInfo(ResultRelInfo *resultRelInfo,
@@ -189,7 +189,8 @@ typedef struct Port
189
189
  /*
190
190
  * If GSSAPI is supported and used on this connection, store GSSAPI
191
191
  * 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).
193
194
  */
194
195
  pg_gssinfo *gss;
195
196
  #else
@@ -206,8 +207,7 @@ typedef struct Port
206
207
  bool alpn_used;
207
208
 
208
209
  /*
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.
211
211
  */
212
212
  #ifdef USE_OPENSSL
213
213
  SSL *ssl;
@@ -222,6 +222,9 @@ typedef struct Port
222
222
  * There's no API to "unread", the upper layer just places the data in the
223
223
  * Port structure in raw_buf and sets raw_buf_remaining to the amount of
224
224
  * 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.
225
228
  */
226
229
  char *raw_buf;
227
230
  ssize_t raw_buf_consumed,
@@ -662,7 +662,10 @@ extern int pg_valid_server_encoding_id(int encoding);
662
662
  * (in addition to the ones just above). The constant tables declared
663
663
  * earlier in this file are also available from libpgcommon.
664
664
  */
665
+ extern void pg_encoding_set_invalid(int encoding, char *dst);
665
666
  extern int pg_encoding_mblen(int encoding, const char *mbstr);
667
+ extern int pg_encoding_mblen_or_incomplete(int encoding, const char *mbstr,
668
+ size_t remaining);
666
669
  extern int pg_encoding_mblen_bounded(int encoding, const char *mbstr);
667
670
  extern int pg_encoding_dsplen(int encoding, const char *mbstr);
668
671
  extern int pg_encoding_verifymbchar(int encoding, const char *mbstr, int len);
@@ -114,7 +114,8 @@ extern void ProcessInterrupts(void);
114
114
  (unlikely(InterruptPending))
115
115
  #else
116
116
  #define INTERRUPTS_PENDING_CONDITION() \
117
- (unlikely(UNBLOCKED_SIGNAL_QUEUE()) ? pgwin32_dispatch_queued_signals() : 0, \
117
+ (unlikely(UNBLOCKED_SIGNAL_QUEUE()) ? \
118
+ pgwin32_dispatch_queued_signals() : (void) 0, \
118
119
  unlikely(InterruptPending))
119
120
  #endif
120
121
 
@@ -346,8 +347,9 @@ typedef enum BackendType
346
347
 
347
348
  /*
348
349
  * 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.
350
+ * attached to any particular database, and cannot run transactions or
351
+ * even take heavyweight locks. There can be only one of each of these
352
+ * running at a time.
351
353
  *
352
354
  * If you modify these, make sure to update NUM_AUXILIARY_PROCS and the
353
355
  * glossary in the docs.
@@ -371,6 +373,7 @@ typedef enum BackendType
371
373
 
372
374
  extern PGDLLIMPORT BackendType MyBackendType;
373
375
 
376
+ #define AmRegularBackendProcess() (MyBackendType == B_BACKEND)
374
377
  #define AmAutoVacuumLauncherProcess() (MyBackendType == B_AUTOVAC_LAUNCHER)
375
378
  #define AmAutoVacuumWorkerProcess() (MyBackendType == B_AUTOVAC_WORKER)
376
379
  #define AmBackgroundWorkerProcess() (MyBackendType == B_BG_WORKER)
@@ -384,6 +387,10 @@ extern PGDLLIMPORT BackendType MyBackendType;
384
387
  #define AmWalSummarizerProcess() (MyBackendType == B_WAL_SUMMARIZER)
385
388
  #define AmWalWriterProcess() (MyBackendType == B_WAL_WRITER)
386
389
 
390
+ #define AmSpecialWorkerProcess() \
391
+ (AmAutoVacuumLauncherProcess() || \
392
+ AmLogicalSlotSyncWorkerProcess())
393
+
387
394
  extern const char *GetBackendTypeDesc(BackendType backendType);
388
395
 
389
396
  extern void SetDatabasePath(const char *path);
@@ -395,7 +402,9 @@ extern char *GetUserNameFromId(Oid roleid, bool noerr);
395
402
  extern Oid GetUserId(void);
396
403
  extern Oid GetOuterUserId(void);
397
404
  extern Oid GetSessionUserId(void);
405
+ extern bool GetSessionUserIsSuperuser(void);
398
406
  extern Oid GetAuthenticatedUserId(void);
407
+ extern void SetAuthenticatedUserId(Oid userid);
399
408
  extern void GetUserIdAndSecContext(Oid *userid, int *sec_context);
400
409
  extern void SetUserIdAndSecContext(Oid userid, int sec_context);
401
410
  extern bool InLocalUserIdChange(void);
@@ -164,7 +164,7 @@ typedef struct ExprState
164
164
  * UniqueProcs
165
165
  * UniqueStrats
166
166
  * Unique is it a unique index?
167
- * OpclassOptions opclass-specific options, or NULL if none
167
+ * NullsNotDistinct is NULLS NOT DISTINCT?
168
168
  * ReadyForInserts is it valid for inserts?
169
169
  * CheckedUnchanged IndexUnchanged status determined yet?
170
170
  * IndexUnchanged aminsert hint, cached for retail inserts
@@ -484,6 +484,9 @@ typedef struct ResultRelInfo
484
484
  /* Have the projection and the slots above been initialized? */
485
485
  bool ri_projectNewInfoValid;
486
486
 
487
+ /* updates do LockTuple() before oldtup read; see README.tuplock */
488
+ bool ri_needLockTagTuple;
489
+
487
490
  /* triggers to be fired, if any */
488
491
  TriggerDesc *ri_TrigDesc;
489
492
 
@@ -571,15 +574,13 @@ typedef struct ResultRelInfo
571
574
  bool ri_RootToChildMapValid;
572
575
 
573
576
  /*
574
- * Information needed by tuple routing target relations
577
+ * Other information needed by child result relations
575
578
  *
576
- * RootResultRelInfo gives the target relation mentioned in the query, if
577
- * it's a partitioned table. It is not set if the target relation
578
- * mentioned in the query is an inherited table, nor when tuple routing is
579
- * not needed.
579
+ * ri_RootResultRelInfo gives the target relation mentioned in the query.
580
+ * Used as the root for tuple routing and/or transition capture.
580
581
  *
581
- * PartitionTupleSlot is non-NULL if RootToChild conversion is needed and
582
- * the relation is a partition.
582
+ * ri_PartitionTupleSlot is non-NULL if the relation is a partition to
583
+ * route tuples into and ri_RootToChildMap conversion is needed.
583
584
  */
584
585
  struct ResultRelInfo *ri_RootResultRelInfo;
585
586
  TupleTableSlot *ri_PartitionTupleSlot;
@@ -1101,6 +1101,8 @@ typedef struct IndexOptInfo IndexOptInfo;
1101
1101
  #define HAVE_INDEXOPTINFO_TYPEDEF 1
1102
1102
  #endif
1103
1103
 
1104
+ struct IndexPath; /* forward declaration */
1105
+
1104
1106
  struct IndexOptInfo
1105
1107
  {
1106
1108
  pg_node_attr(no_copy_equal, no_read, no_query_jumble)
@@ -1200,7 +1202,7 @@ struct IndexOptInfo
1200
1202
  bool amcanmarkpos;
1201
1203
  /* AM's cost estimator */
1202
1204
  /* Rather than include amapi.h here, we declare amcostestimate like this */
1203
- void (*amcostestimate) () pg_node_attr(read_write_ignore);
1205
+ void (*amcostestimate) (struct PlannerInfo *, struct IndexPath *, double, Cost *, Cost *, Selectivity *, double *, double *) pg_node_attr(read_write_ignore);
1204
1206
  };
1205
1207
 
1206
1208
  /*
@@ -485,7 +485,7 @@ for_each_cell_setup(const List *lst, const ListCell *initcell)
485
485
  for (ForEachState var##__state = {(lst), 0}; \
486
486
  (var##__state.l != NIL && \
487
487
  var##__state.i < var##__state.l->length && \
488
- (var = func(&var##__state.l->elements[var##__state.i]), true)); \
488
+ (var = (type pointer) func(&var##__state.l->elements[var##__state.i]), true)); \
489
489
  var##__state.i++)
490
490
 
491
491
  /*
@@ -1669,15 +1669,19 @@ typedef struct JsonReturning
1669
1669
  * JsonValueExpr -
1670
1670
  * representation of JSON value expression (expr [FORMAT JsonFormat])
1671
1671
  *
1672
- * The actual value is obtained by evaluating formatted_expr. raw_expr is
1673
- * only there for displaying the original user-written expression and is not
1674
- * evaluated by ExecInterpExpr() and eval_const_expressions_mutator().
1672
+ * raw_expr is the user-specified value, while formatted_expr is the value
1673
+ * obtained by coercing raw_expr to the type required by either the FORMAT
1674
+ * clause or an enclosing node's RETURNING clause.
1675
+ *
1676
+ * When deparsing a JsonValueExpr, get_rule_expr() prints raw_expr. However,
1677
+ * during the evaluation of a JsonValueExpr, the value of formatted_expr
1678
+ * takes precedence over that of raw_expr.
1675
1679
  */
1676
1680
  typedef struct JsonValueExpr
1677
1681
  {
1678
1682
  NodeTag type;
1679
- Expr *raw_expr; /* raw expression */
1680
- Expr *formatted_expr; /* formatted expression */
1683
+ Expr *raw_expr; /* user-specified expression */
1684
+ Expr *formatted_expr; /* coerced formatted expression */
1681
1685
  JsonFormat *format; /* FORMAT clause, if specified */
1682
1686
  } JsonValueExpr;
1683
1687
 
@@ -63,6 +63,9 @@ extern Node *coerce_to_specific_type_typmod(ParseState *pstate, Node *node,
63
63
  Oid targetTypeId, int32 targetTypmod,
64
64
  const char *constructName);
65
65
 
66
+ extern Node *coerce_null_to_domain(Oid typid, int32 typmod, Oid collation,
67
+ int typlen, bool typbyval);
68
+
66
69
  extern int parser_coercion_errposition(ParseState *pstate,
67
70
  int coerce_location,
68
71
  Node *input_expr);
@@ -104,6 +104,10 @@
104
104
  `LLVMCreatePerfJITEventListener', and to 0 if you don't. */
105
105
  /* #undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER */
106
106
 
107
+ /* Define to 1 if you have the declaration of `memset_s', and to 0 if you
108
+ don't. */
109
+ #define HAVE_DECL_MEMSET_S 1
110
+
107
111
  /* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
108
112
  don't. */
109
113
  #define HAVE_DECL_POSIX_FADVISE 0
@@ -116,6 +120,10 @@
116
120
  don't. */
117
121
  #define HAVE_DECL_PWRITEV 1
118
122
 
123
+ /* Define to 1 if you have the declaration of `strchrnul', and to 0 if you
124
+ don't. */
125
+ #define HAVE_DECL_STRCHRNUL 0
126
+
119
127
  /* Define to 1 if you have the declaration of `strlcat', and to 0 if you
120
128
  don't. */
121
129
  #define HAVE_DECL_STRLCAT 1
@@ -298,9 +306,6 @@
298
306
  /* Define to 1 if you have the <memory.h> header file. */
299
307
  #define HAVE_MEMORY_H 1
300
308
 
301
- /* Define to 1 if you have the `memset_s' function. */
302
- #define HAVE_MEMSET_S 1
303
-
304
309
  /* Define to 1 if you have the `mkdtemp' function. */
305
310
  #define HAVE_MKDTEMP 1
306
311
 
@@ -388,18 +393,12 @@
388
393
  /* Define to 1 if you have the `SSL_CTX_set_num_tickets' function. */
389
394
  /* #undef HAVE_SSL_CTX_SET_NUM_TICKETS */
390
395
 
391
- /* Define to 1 if stdbool.h conforms to C99. */
392
- #define HAVE_STDBOOL_H 1
393
-
394
396
  /* Define to 1 if you have the <stdint.h> header file. */
395
397
  #define HAVE_STDINT_H 1
396
398
 
397
399
  /* Define to 1 if you have the <stdlib.h> header file. */
398
400
  #define HAVE_STDLIB_H 1
399
401
 
400
- /* Define to 1 if you have the `strchrnul' function. */
401
- /* #undef HAVE_STRCHRNUL */
402
-
403
402
  /* Define to 1 if you have the `strerror_r' function. */
404
403
  #define HAVE_STRERROR_R 1
405
404
 
@@ -520,9 +519,6 @@
520
519
  /* Define to 1 if you have XSAVE intrinsics. */
521
520
  /* #undef HAVE_XSAVE_INTRINSICS */
522
521
 
523
- /* Define to 1 if the system has the type `_Bool'. */
524
- #define HAVE__BOOL 1
525
-
526
522
  /* Define to 1 if your compiler understands __builtin_bswap16. */
527
523
  #define HAVE__BUILTIN_BSWAP16 1
528
524
 
@@ -578,7 +574,7 @@
578
574
  #define INT64_MODIFIER "l"
579
575
 
580
576
  /* Define to 1 if `locale_t' requires <xlocale.h>. */
581
- #define LOCALE_T_IN_XLOCALE 1
577
+ /* #undef LOCALE_T_IN_XLOCALE */
582
578
 
583
579
  /* Define as the maximum alignment requirement of any C data type. */
584
580
  #define MAXIMUM_ALIGNOF 8
@@ -597,7 +593,7 @@
597
593
  #define PACKAGE_NAME "PostgreSQL"
598
594
 
599
595
  /* Define to the full name and version of this package. */
600
- #define PACKAGE_STRING "PostgreSQL 17.0"
596
+ #define PACKAGE_STRING "PostgreSQL 17.7"
601
597
 
602
598
  /* Define to the one symbol short name of this package. */
603
599
  #define PACKAGE_TARNAME "postgresql"
@@ -606,7 +602,7 @@
606
602
  #define PACKAGE_URL "https://www.postgresql.org/"
607
603
 
608
604
  /* Define to the version of this package. */
609
- #define PACKAGE_VERSION "17.0"
605
+ #define PACKAGE_VERSION "17.7"
610
606
 
611
607
  /* Define to the name of a signed 128-bit integer type. */
612
608
  #define PG_INT128_TYPE __int128
@@ -625,7 +621,7 @@
625
621
  #define PG_MAJORVERSION_NUM 17
626
622
 
627
623
  /* PostgreSQL minor version number */
628
- #define PG_MINORVERSION_NUM 0
624
+ #define PG_MINORVERSION_NUM 7
629
625
 
630
626
  /* Define to best printf format archetype, usually gnu_printf if available. */
631
627
  #define PG_PRINTF_ATTRIBUTE printf
@@ -634,13 +630,13 @@
634
630
  #define PG_USE_STDBOOL 1
635
631
 
636
632
  /* PostgreSQL version as a string */
637
- #define PG_VERSION "17.0"
633
+ #define PG_VERSION "17.7"
638
634
 
639
635
  /* PostgreSQL version as a number */
640
- #define PG_VERSION_NUM 170000
636
+ #define PG_VERSION_NUM 170007
641
637
 
642
638
  /* A string containing the version number, platform, and C compiler */
643
- #define PG_VERSION_STR "PostgreSQL 17.0 (libpg_query)"
639
+ #define PG_VERSION_STR "PostgreSQL 17.7 (libpg_query)"
644
640
 
645
641
  /* Define to 1 to allow profiling output to be saved separately for each
646
642
  process. */
@@ -825,9 +821,14 @@
825
821
 
826
822
  /* Define to how the compiler spells `typeof'. */
827
823
  /* #undef typeof */
828
- /* This causes compatibility problems on some Linux distros, with "xlocale.h" not being available */
829
- #ifndef __APPLE__
824
+ /*
825
+ * Assume we don't have xlocale.h on non-MacOS, as not all Linux distros have "xlocale.h" available.
826
+ *
827
+ * Note this is required on older MacOS to avoid "unknown type name 'locale_t'"
828
+ */
830
829
  #undef LOCALE_T_IN_XLOCALE
830
+ #ifdef __APPLE__
831
+ #define LOCALE_T_IN_XLOCALE 1
831
832
  #endif
832
833
  #undef WCSTOMBS_L_IN_XLOCALE
833
834
 
@@ -848,10 +849,18 @@
848
849
  #undef USE_ARMV8_CRC32C
849
850
  #undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK
850
851
 
851
- /* Ensure we do not fail on systems that have strchrnul support (FreeBSD, NetBSD and newer glibc) */
852
+ /*
853
+ * Ensure we use built-in strchrnul on systems that have strchrnul support (FreeBSD, NetBSD and newer glibc)
854
+ *
855
+ * Note MacOS 15.4+ also has strchrnul implemented, but is complex to handle correctly, and the code works
856
+ * around the double define.
857
+ */
852
858
  #include <stdlib.h>
859
+ #undef HAVE_DECL_STRCHRNUL
853
860
  #if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) || __GLIBC__ > 2))
854
- #define HAVE_STRCHRNUL
861
+ #define HAVE_DECL_STRCHRNUL 1
862
+ #else
863
+ #define HAVE_DECL_STRCHRNUL 0
855
864
  #endif
856
865
 
857
866
  /* 32-bit */
@@ -26,7 +26,9 @@
26
26
  *
27
27
  * Changing this requires an initdb.
28
28
  */
29
+ #ifndef NAMEDATALEN
29
30
  #define NAMEDATALEN 64
31
+ #endif
30
32
 
31
33
  /*
32
34
  * Maximum number of arguments to a function.
@@ -44,12 +44,20 @@
44
44
 
45
45
  #if !defined(pg_read_barrier_impl) && defined(HAVE_GCC__ATOMIC_INT32_CAS)
46
46
  /* acquire semantics include read barrier semantics */
47
- # define pg_read_barrier_impl() __atomic_thread_fence(__ATOMIC_ACQUIRE)
47
+ # define pg_read_barrier_impl() do \
48
+ { \
49
+ pg_compiler_barrier_impl(); \
50
+ __atomic_thread_fence(__ATOMIC_ACQUIRE); \
51
+ } while (0)
48
52
  #endif
49
53
 
50
54
  #if !defined(pg_write_barrier_impl) && defined(HAVE_GCC__ATOMIC_INT32_CAS)
51
55
  /* release semantics include write barrier semantics */
52
- # define pg_write_barrier_impl() __atomic_thread_fence(__ATOMIC_RELEASE)
56
+ # define pg_write_barrier_impl() do \
57
+ { \
58
+ pg_compiler_barrier_impl(); \
59
+ __atomic_thread_fence(__ATOMIC_RELEASE); \
60
+ } while (0)
53
61
  #endif
54
62
 
55
63
 
@@ -21,9 +21,6 @@
21
21
 
22
22
  #else
23
23
 
24
- /* POSIX requires at least 16 as a maximum iovcnt. */
25
- #define IOV_MAX 16
26
-
27
24
  /* Define our own POSIX-compatible iovec struct. */
28
25
  struct iovec
29
26
  {
@@ -33,6 +30,15 @@ struct iovec
33
30
 
34
31
  #endif
35
32
 
33
+ /*
34
+ * If <limits.h> didn't define IOV_MAX, define our own. X/Open requires at
35
+ * least 16. (GNU Hurd apparently feel that they're not bound by X/Open,
36
+ * because they don't define this symbol at all.)
37
+ */
38
+ #ifndef IOV_MAX
39
+ #define IOV_MAX 16
40
+ #endif
41
+
36
42
  /* Define a reasonable maximum that is safe to use on the stack. */
37
43
  #define PG_IOV_MAX Min(IOV_MAX, 32)
38
44
 
@@ -68,7 +74,7 @@ pg_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
68
74
  }
69
75
  sum += part;
70
76
  offset += part;
71
- if (part < iov[i].iov_len)
77
+ if ((size_t) part < iov[i].iov_len)
72
78
  return sum;
73
79
  }
74
80
  return sum;
@@ -107,7 +113,7 @@ pg_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
107
113
  }
108
114
  sum += part;
109
115
  offset += part;
110
- if (part < iov[i].iov_len)
116
+ if ((size_t) part < iov[i].iov_len)
111
117
  return sum;
112
118
  }
113
119
  return sum;
@@ -79,8 +79,6 @@
79
79
  /* Must be here to avoid conflicting with prototype in windows.h */
80
80
  #define mkdir(a,b) mkdir(a)
81
81
 
82
- #define ftruncate(a,b) chsize(a,b)
83
-
84
82
  /* Windows doesn't have fsync() as such, use _commit() */
85
83
  #define fsync(fd) _commit(fd)
86
84
 
@@ -53,6 +53,7 @@ extern char *first_path_var_separator(const char *pathlist);
53
53
  extern void join_path_components(char *ret_path,
54
54
  const char *head, const char *tail);
55
55
  extern void canonicalize_path(char *path);
56
+ extern void canonicalize_path_enc(char *path, int encoding);
56
57
  extern void make_native_path(char *filename);
57
58
  extern void cleanup_path(char *path);
58
59
  extern bool path_contains_parent_reference(const char *path);
@@ -306,6 +307,33 @@ extern bool rmtree(const char *path, bool rmtopdir);
306
307
 
307
308
  #if defined(WIN32) && !defined(__CYGWIN__)
308
309
 
310
+ /*
311
+ * We want the 64-bit variant of lseek().
312
+ *
313
+ * For Visual Studio, this must be after <io.h> to avoid messing up its
314
+ * lseek() and _lseeki64() function declarations.
315
+ *
316
+ * For MinGW there is already a macro, so we have to undefine it (depending on
317
+ * _FILE_OFFSET_BITS, it may point at its own lseek64, but we don't want to
318
+ * count on that being set).
319
+ */
320
+ #undef lseek
321
+ #define lseek(a,b,c) _lseeki64((a),(b),(c))
322
+
323
+ /*
324
+ * We want the 64-bit variant of chsize(). It sets errno and also returns it,
325
+ * so convert non-zero result to -1 to match POSIX.
326
+ *
327
+ * Prevent MinGW from declaring functions, and undefine its macro before we
328
+ * define our own.
329
+ */
330
+ #ifndef _MSC_VER
331
+ #define FTRUNCATE_DEFINED
332
+ #include <unistd.h>
333
+ #undef ftruncate
334
+ #endif
335
+ #define ftruncate(a,b) (_chsize_s((a),(b)) == 0 ? 0 : -1)
336
+
309
337
  /*
310
338
  * open() and fopen() replacements to allow deletion of open files and
311
339
  * passing of other special options.
@@ -488,7 +516,10 @@ extern int pg_check_dir(const char *dir);
488
516
  /* port/pgmkdirp.c */
489
517
  extern int pg_mkdir_p(char *path, int omode);
490
518
 
491
- /* port/pqsignal.c */
519
+ /* port/pqsignal.c (see also interfaces/libpq/legacy-pqsignal.c) */
520
+ #ifdef FRONTEND
521
+ #define pqsignal pqsignal_fe
522
+ #endif
492
523
  typedef void (*pqsigfunc) (SIGNAL_ARGS);
493
524
  extern pqsigfunc pqsignal(int signo, pqsigfunc func);
494
525
 
@@ -159,15 +159,16 @@ typedef struct ReorderBufferChange
159
159
  } ReorderBufferChange;
160
160
 
161
161
  /* ReorderBufferTXN txn_flags */
162
- #define RBTXN_HAS_CATALOG_CHANGES 0x0001
163
- #define RBTXN_IS_SUBXACT 0x0002
164
- #define RBTXN_IS_SERIALIZED 0x0004
165
- #define RBTXN_IS_SERIALIZED_CLEAR 0x0008
166
- #define RBTXN_IS_STREAMED 0x0010
167
- #define RBTXN_HAS_PARTIAL_CHANGE 0x0020
168
- #define RBTXN_PREPARE 0x0040
169
- #define RBTXN_SKIPPED_PREPARE 0x0080
170
- #define RBTXN_HAS_STREAMABLE_CHANGE 0x0100
162
+ #define RBTXN_HAS_CATALOG_CHANGES 0x0001
163
+ #define RBTXN_IS_SUBXACT 0x0002
164
+ #define RBTXN_IS_SERIALIZED 0x0004
165
+ #define RBTXN_IS_SERIALIZED_CLEAR 0x0008
166
+ #define RBTXN_IS_STREAMED 0x0010
167
+ #define RBTXN_HAS_PARTIAL_CHANGE 0x0020
168
+ #define RBTXN_PREPARE 0x0040
169
+ #define RBTXN_SKIPPED_PREPARE 0x0080
170
+ #define RBTXN_HAS_STREAMABLE_CHANGE 0x0100
171
+ #define RBTXN_DISTR_INVAL_OVERFLOWED 0x0200
171
172
 
172
173
  /* Does the transaction have catalog changes? */
173
174
  #define rbtxn_has_catalog_changes(txn) \
@@ -231,6 +232,12 @@ typedef struct ReorderBufferChange
231
232
  ((txn)->txn_flags & RBTXN_SKIPPED_PREPARE) != 0 \
232
233
  )
233
234
 
235
+ /* Is the array of distributed inval messages overflowed? */
236
+ #define rbtxn_distr_inval_overflowed(txn) \
237
+ ( \
238
+ ((txn)->txn_flags & RBTXN_DISTR_INVAL_OVERFLOWED) != 0 \
239
+ )
240
+
234
241
  /* Is this a top-level transaction? */
235
242
  #define rbtxn_is_toptxn(txn) \
236
243
  ( \
@@ -422,6 +429,12 @@ typedef struct ReorderBufferTXN
422
429
  * Private data pointer of the output plugin.
423
430
  */
424
431
  void *output_plugin_private;
432
+
433
+ /*
434
+ * Stores cache invalidation messages distributed by other transactions.
435
+ */
436
+ uint32 ninvalidations_distributed;
437
+ SharedInvalidationMessage *invalidations_distributed;
425
438
  } ReorderBufferTXN;
426
439
 
427
440
  /* so we can define the callbacks used inside struct ReorderBuffer itself */
@@ -478,45 +491,38 @@ typedef void (*ReorderBufferRollbackPreparedCB) (ReorderBuffer *rb,
478
491
  TimestampTz prepare_time);
479
492
 
480
493
  /* start streaming transaction callback signature */
481
- typedef void (*ReorderBufferStreamStartCB) (
482
- ReorderBuffer *rb,
494
+ typedef void (*ReorderBufferStreamStartCB) (ReorderBuffer *rb,
483
495
  ReorderBufferTXN *txn,
484
496
  XLogRecPtr first_lsn);
485
497
 
486
498
  /* stop streaming transaction callback signature */
487
- typedef void (*ReorderBufferStreamStopCB) (
488
- ReorderBuffer *rb,
499
+ typedef void (*ReorderBufferStreamStopCB) (ReorderBuffer *rb,
489
500
  ReorderBufferTXN *txn,
490
501
  XLogRecPtr last_lsn);
491
502
 
492
503
  /* discard streamed transaction callback signature */
493
- typedef void (*ReorderBufferStreamAbortCB) (
494
- ReorderBuffer *rb,
504
+ typedef void (*ReorderBufferStreamAbortCB) (ReorderBuffer *rb,
495
505
  ReorderBufferTXN *txn,
496
506
  XLogRecPtr abort_lsn);
497
507
 
498
508
  /* prepare streamed transaction callback signature */
499
- typedef void (*ReorderBufferStreamPrepareCB) (
500
- ReorderBuffer *rb,
509
+ typedef void (*ReorderBufferStreamPrepareCB) (ReorderBuffer *rb,
501
510
  ReorderBufferTXN *txn,
502
511
  XLogRecPtr prepare_lsn);
503
512
 
504
513
  /* commit streamed transaction callback signature */
505
- typedef void (*ReorderBufferStreamCommitCB) (
506
- ReorderBuffer *rb,
514
+ typedef void (*ReorderBufferStreamCommitCB) (ReorderBuffer *rb,
507
515
  ReorderBufferTXN *txn,
508
516
  XLogRecPtr commit_lsn);
509
517
 
510
518
  /* stream change callback signature */
511
- typedef void (*ReorderBufferStreamChangeCB) (
512
- ReorderBuffer *rb,
519
+ typedef void (*ReorderBufferStreamChangeCB) (ReorderBuffer *rb,
513
520
  ReorderBufferTXN *txn,
514
521
  Relation relation,
515
522
  ReorderBufferChange *change);
516
523
 
517
524
  /* stream message callback signature */
518
- typedef void (*ReorderBufferStreamMessageCB) (
519
- ReorderBuffer *rb,
525
+ typedef void (*ReorderBufferStreamMessageCB) (ReorderBuffer *rb,
520
526
  ReorderBufferTXN *txn,
521
527
  XLogRecPtr message_lsn,
522
528
  bool transactional,
@@ -524,16 +530,14 @@ typedef void (*ReorderBufferStreamMessageCB) (
524
530
  const char *message);
525
531
 
526
532
  /* stream truncate callback signature */
527
- typedef void (*ReorderBufferStreamTruncateCB) (
528
- ReorderBuffer *rb,
533
+ typedef void (*ReorderBufferStreamTruncateCB) (ReorderBuffer *rb,
529
534
  ReorderBufferTXN *txn,
530
535
  int nrelations,
531
536
  Relation relations[],
532
537
  ReorderBufferChange *change);
533
538
 
534
539
  /* update progress txn callback signature */
535
- typedef void (*ReorderBufferUpdateProgressTxnCB) (
536
- ReorderBuffer *rb,
540
+ typedef void (*ReorderBufferUpdateProgressTxnCB) (ReorderBuffer *rb,
537
541
  ReorderBufferTXN *txn,
538
542
  XLogRecPtr lsn);
539
543
 
@@ -718,6 +722,9 @@ extern void ReorderBufferAddNewTupleCids(ReorderBuffer *rb, TransactionId xid,
718
722
  CommandId cmin, CommandId cmax, CommandId combocid);
719
723
  extern void ReorderBufferAddInvalidations(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn,
720
724
  Size nmsgs, SharedInvalidationMessage *msgs);
725
+ extern void ReorderBufferAddDistributedInvalidations(ReorderBuffer *rb, TransactionId xid,
726
+ XLogRecPtr lsn, Size nmsgs,
727
+ SharedInvalidationMessage *msgs);
721
728
  extern void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations,
722
729
  SharedInvalidationMessage *invalidations);
723
730
  extern void ReorderBufferProcessXid(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn);
@@ -738,6 +745,10 @@ extern TransactionId *ReorderBufferGetCatalogChangesXacts(ReorderBuffer *rb);
738
745
 
739
746
  extern void ReorderBufferSetRestartPoint(ReorderBuffer *rb, XLogRecPtr ptr);
740
747
 
748
+ extern uint32 ReorderBufferGetInvalidations(ReorderBuffer *rb,
749
+ TransactionId xid,
750
+ SharedInvalidationMessage **msgs);
751
+
741
752
  extern void StartupReorderBuffer(void);
742
753
 
743
754
  #endif
@@ -202,7 +202,11 @@ typedef struct ReplicationSlot
202
202
  */
203
203
  XLogRecPtr last_saved_confirmed_flush;
204
204
 
205
- /* The time since the slot has become inactive */
205
+ /*
206
+ * The time when the slot became inactive. For synced slots on a standby
207
+ * server, it represents the time when slot synchronization was most
208
+ * recently stopped.
209
+ */
206
210
  TimestampTz inactive_since;
207
211
  } ReplicationSlot;
208
212
 
@@ -254,6 +258,8 @@ extern void ReplicationSlotMarkDirty(void);
254
258
  /* misc stuff */
255
259
  extern void ReplicationSlotInitialize(void);
256
260
  extern bool ReplicationSlotValidateName(const char *name, int elevel);
261
+ extern bool ReplicationSlotValidateNameInternal(const char *name,
262
+ int *err_code, char **err_msg, char **err_hint);
257
263
  extern void ReplicationSlotReserveWal(void);
258
264
  extern void ReplicationSlotsComputeRequiredXmin(bool already_locked);
259
265
  extern void ReplicationSlotsComputeRequiredLSN(void);