forked from timescale/timescaledb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompat.h
More file actions
936 lines (862 loc) · 45.4 KB
/
Copy pathcompat.h
File metadata and controls
936 lines (862 loc) · 45.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
/*
* This file and its contents are licensed under the Apache License 2.0.
* Please see the included NOTICE for copyright information and
* LICENSE-APACHE for a copy of the license.
*/
#pragma once
#include <postgres.h>
#include <commands/cluster.h>
#include <commands/defrem.h>
#include <commands/explain.h>
#include <commands/trigger.h>
#include <commands/vacuum.h>
#include <executor/executor.h>
#include <executor/tuptable.h>
#include <nodes/execnodes.h>
#include <nodes/nodes.h>
#include <optimizer/restrictinfo.h>
#include <pgstat.h>
#include <storage/lmgr.h>
#include <utils/jsonb.h>
#include <utils/lsyscache.h>
#include <utils/rel.h>
#include "export.h"
#define PG_MAJOR_MIN 15
/*
* Prevent building against upstream versions that had ABI breaking change (15.9, 16.5, 17.1)
* that was reverted in the following release.
*/
#define is_supported_pg_version_15(version) ((version >= 150010) && (version < 160000))
#define is_supported_pg_version_16(version) ((version >= 160006) && (version < 170000))
#define is_supported_pg_version_17(version) ((version >= 170002) && (version < 180000))
#define is_supported_pg_version_18(version) ((version >= 180000) && (version < 190000))
/*
* To compile with an unsupported version, use -DEXPERIMENTAL=ON with cmake.
* (Useful when testing with unreleased versions)
*/
#define is_supported_pg_version(version) \
(is_supported_pg_version_15(version) || is_supported_pg_version_16(version) || \
is_supported_pg_version_17(version) || is_supported_pg_version_18(version))
#define PG15 is_supported_pg_version_15(PG_VERSION_NUM)
#define PG16 is_supported_pg_version_16(PG_VERSION_NUM)
#define PG17 is_supported_pg_version_17(PG_VERSION_NUM)
#define PG18 is_supported_pg_version_18(PG_VERSION_NUM)
#define PG15_LT (PG_VERSION_NUM < 150000)
#define PG15_GE (PG_VERSION_NUM >= 150000)
#define PG16_LT (PG_VERSION_NUM < 160000)
#define PG16_GE (PG_VERSION_NUM >= 160000)
#define PG17_LT (PG_VERSION_NUM < 170000)
#define PG17_GE (PG_VERSION_NUM >= 170000)
#define PG18_LT (PG_VERSION_NUM < 180000)
#define PG18_GE (PG_VERSION_NUM >= 180000)
#if !(is_supported_pg_version(PG_VERSION_NUM))
#error "Unsupported PostgreSQL version"
#endif
#if ((PG_VERSION_NUM >= 150009 && PG_VERSION_NUM < 160000) || \
(PG_VERSION_NUM >= 160005 && PG_VERSION_NUM < 170000) || (PG_VERSION_NUM >= 170001))
/*
* The above versions introduced a fix for potentially losing updates to
* pg_class and pg_database due to inplace updates done to those catalog
* tables by PostgreSQL. The fix requires taking a lock on the tuple via
* SearchSysCacheLocked1(). For older PG versions, we just map the new
* function to the unlocked version and the unlocking of the tuple is a noop.
*
* https://github.com/postgres/postgres/commit/3b7a689e1a805c4dac2f35ff14fd5c9fdbddf150
*
* Here's an excerpt from README.tuplock that explains the need for additional
* tuple locks:
*
* If IsInplaceUpdateRelation() returns true for a table, the table is a
* system catalog that receives systable_inplace_update_begin() calls.
* Preparing a heap_update() of these tables follows additional locking rules,
* to ensure we don't lose the effects of an inplace update. In particular,
* consider a moment when a backend has fetched the old tuple to modify, not
* yet having called heap_update(). Another backend's inplace update starting
* then can't conclude until the heap_update() places its new tuple in a
* buffer. We enforce that using locktags as follows. While DDL code is the
* main audience, the executor follows these rules to make e.g. "MERGE INTO
* pg_class" safer. Locking rules are per-catalog:
*
* pg_class heap_update() callers: before copying the tuple to modify, take a
* lock on the tuple, a ShareUpdateExclusiveLock on the relation, or a
* ShareRowExclusiveLock or stricter on the relation.
*/
#define SYSCACHE_TUPLE_LOCK_NEEDED 1
#define AssertSufficientPgClassUpdateLockHeld(relid) \
Assert(CheckRelationOidLockedByMe(relid, ShareUpdateExclusiveLock, false) || \
CheckRelationOidLockedByMe(relid, ShareRowExclusiveLock, true));
#define UnlockSysCacheTuple(rel, tid) UnlockTuple(rel, tid, InplaceUpdateTupleLock);
#else
#define SearchSysCacheLockedCopy1(rel, datum) SearchSysCacheCopy1(rel, datum)
#define UnlockSysCacheTuple(rel, tid)
#define AssertSufficientPgClassUpdateLockHeld(relid)
#endif
/*
* The following are compatibility functions for different versions of
* PostgreSQL. Each compatibility function (or group) has its own logic for
* which versions get different behavior and is separated from others by a
* comment with its name and any clarifying notes about supported behavior. Each
* compatibility define is separated out by function so that it is easier to see
* what changed about its behavior, and at what version, but closely related
* functions that changed at the same time may be grouped together into a single
* block. Compatibility functions are organized in alphabetical order.
*
* Wherever reasonable, we try to achieve forwards compatibility so that we can
* take advantage of features added in newer PG versions. This avoids some
* future tech debt, though may not always be possible.
*
* We append "compat" to the name of the function or define if we change the behavior
* of something that existed in a previous version. If we are merely backpatching
* behavior from a later version to an earlier version and not changing the
* behavior of the new version we simply adopt the new version's name.
*/
#if PG16_LT
#define ExecInsertIndexTuplesCompat(rri, \
slot, \
estate, \
update, \
noDupErr, \
specConflict, \
arbiterIndexes, \
onlySummarizing) \
ExecInsertIndexTuples(rri, slot, estate, update, noDupErr, specConflict, arbiterIndexes)
#else
#define ExecInsertIndexTuplesCompat(rri, \
slot, \
estate, \
update, \
noDupErr, \
specConflict, \
arbiterIndexes, \
onlySummarizing) \
ExecInsertIndexTuples(rri, \
slot, \
estate, \
update, \
noDupErr, \
specConflict, \
arbiterIndexes, \
onlySummarizing)
#endif
/*
* PG16 removed outerjoin_delayed, nullable_relids arguments from make_restrictinfo
* https://github.com/postgres/postgres/commit/b448f1c8d8
*
* PG16 adds three new parameter - has_clone, is_clone and incompatible_relids, as a
* part of fixing the filtering of "cloned" outer-join quals
* https://github.com/postgres/postgres/commit/991a3df227
*/
#if PG16_LT
#define make_restrictinfo_compat(root, \
clause, \
is_pushed_down, \
has_clone, \
is_clone, \
outerjoin_delayed, \
pseudoconstant, \
security_level, \
required_relids, \
incompatible_relids, \
outer_relids, \
nullable_relids) \
make_restrictinfo(root, \
clause, \
is_pushed_down, \
outerjoin_delayed, \
pseudoconstant, \
security_level, \
required_relids, \
outer_relids, \
nullable_relids)
#else
#define make_restrictinfo_compat(root, \
clause, \
is_pushed_down, \
has_clone, \
is_clone, \
outerjoin_delayed, \
pseudoconstant, \
security_level, \
required_relids, \
incompatible_relids, \
outer_relids, \
nullable_relids) \
make_restrictinfo(root, \
clause, \
is_pushed_down, \
has_clone, \
is_clone, \
pseudoconstant, \
security_level, \
required_relids, \
incompatible_relids, \
outer_relids)
#endif
/* fmgr
* In a9c35cf postgres changed how it calls SQL functions so that the number of
* argument-slots allocated is chosen dynamically, instead of being fixed. This
* change was ABI-breaking, so we cannot backport this optimization, however,
* we do backport the interface, so that all our code will be compatible with
* new versions.
*/
/* convenience macro to allocate FunctionCallInfoData on the heap */
#define HEAP_FCINFO(nargs) palloc(SizeForFunctionCallInfo(nargs))
/* getting arguments has a different API, so these macros unify the versions */
#define FC_ARG(fcinfo, n) ((fcinfo)->args[(n)].value)
#define FC_NULL(fcinfo, n) ((fcinfo)->args[(n)].isnull)
#define FC_FN_OID(fcinfo) ((fcinfo)->flinfo->fn_oid)
/* convenience setters */
#define FC_SET_ARG(fcinfo, n, val) \
do \
{ \
short _n = (n); \
FunctionCallInfo _fcinfo = (fcinfo); \
FC_ARG(_fcinfo, _n) = (val); \
FC_NULL(_fcinfo, _n) = false; \
} while (0)
#define FC_SET_NULL(fcinfo, n) \
do \
{ \
short _n = (n); \
FunctionCallInfo _fcinfo = (fcinfo); \
FC_ARG(_fcinfo, _n) = 0; \
FC_NULL(_fcinfo, _n) = true; \
} while (0)
/* create this function for symmetry with pq_sendint32 */
#define pq_getmsgint32(buf) pq_getmsgint(buf, 4)
#define ts_tuptableslot_set_table_oid(slot, table_oid) (slot)->tts_tableOid = table_oid
static inline ClusterParams *
get_cluster_options(const ClusterStmt *stmt)
{
ListCell *lc;
ClusterParams *params = palloc0(sizeof(ClusterParams));
bool verbose = false;
/* Parse option list */
foreach (lc, stmt->params)
{
DefElem *opt = (DefElem *) lfirst(lc);
if (strcmp(opt->defname, "verbose") == 0)
{
verbose = defGetBoolean(opt);
}
else
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("unrecognized CLUSTER option \"%s\"", opt->defname),
parser_errposition(NULL, opt->location)));
}
}
params->options = (verbose ? CLUOPT_VERBOSE : 0);
return params;
}
#include <catalog/index.h>
static inline int
get_reindex_options(ReindexStmt *stmt)
{
ListCell *lc;
bool concurrently = false;
bool verbose = false;
/* Parse option list */
foreach (lc, stmt->params)
{
DefElem *opt = (DefElem *) lfirst(lc);
if (strcmp(opt->defname, "verbose") == 0)
{
verbose = defGetBoolean(opt);
}
else if (strcmp(opt->defname, "concurrently") == 0)
{
concurrently = defGetBoolean(opt);
}
else
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("unrecognized REINDEX option \"%s\"", opt->defname),
parser_errposition(NULL, opt->location)));
}
}
return (verbose ? REINDEXOPT_VERBOSE : 0) | (concurrently ? REINDEXOPT_CONCURRENTLY : 0);
}
/*
* define some list macros for convenience
*/
#define lfifth(l) lfirst(list_nth_cell(l, 4))
#define lfifth_int(l) lfirst_int(list_nth_cell(l, 4))
#if PG16_LT
/*
* PG15 consolidate VACUUM xid cutoff logic.
*
* https://github.com/postgres/postgres/commit/efa4a946
*
* PG16 introduced VacuumCutoffs so define here for previous PG versions.
*/
struct VacuumCutoffs
{
TransactionId relfrozenxid;
MultiXactId relminmxid;
TransactionId OldestXmin;
MultiXactId OldestMxact;
TransactionId FreezeLimit;
MultiXactId MultiXactCutoff;
};
static inline bool
vacuum_get_cutoffs(Relation rel, const VacuumParams *params, struct VacuumCutoffs *cutoffs)
{
return vacuum_set_xid_limits(rel,
0,
0,
0,
0,
&cutoffs->OldestXmin,
&cutoffs->OldestMxact,
&cutoffs->FreezeLimit,
&cutoffs->MultiXactCutoff);
}
#endif
/*
* PG16 adds TMResult argument to ExecBRUpdateTriggers
* https://github.com/postgres/postgres/commit/7103ebb7
* this was backported to PG15 in
* https://github.com/postgres/postgres/commit/7d9a75713ab9
*/
#if PG15
#define ExecBRUpdateTriggers(estate, \
epqstate, \
resultRelInfo, \
tupleid, \
oldtuple, \
slot, \
result, \
tmfdp) \
ExecBRUpdateTriggersNew(estate, epqstate, resultRelInfo, tupleid, oldtuple, slot, result, tmfdp)
#endif
/*
* PG16 adds TMResult argument to ExecBRDeleteTriggers
* https://github.com/postgres/postgres/commit/9321c79c
* this was backported to PG15 in
* https://github.com/postgres/postgres/commit/7d9a75713ab9
*/
#if PG15
#define ExecBRDeleteTriggers(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd) \
ExecBRDeleteTriggersNew(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd)
#endif
#if PG16_GE
#define pgstat_get_local_beentry_by_index_compat(idx) pgstat_get_local_beentry_by_index(idx)
#else
#define pgstat_get_local_beentry_by_index_compat(idx) pgstat_fetch_stat_local_beentry(idx)
#endif
/*
* PG16 adds a new parameter to DefineIndex, total_parts, that takes
* in the total number of direct and indirect partitions of the relation.
*
* https://github.com/postgres/postgres/commit/27f5c712
*/
#if PG16_LT
#define DefineIndexCompat(relationId, \
stmt, \
indexRelationId, \
parentIndexId, \
parentConstraintId, \
total_parts, \
is_alter_table, \
check_rights, \
check_not_in_use, \
skip_build, \
quiet) \
DefineIndex(relationId, \
stmt, \
indexRelationId, \
parentIndexId, \
parentConstraintId, \
is_alter_table, \
check_rights, \
check_not_in_use, \
skip_build, \
quiet)
#else
#define DefineIndexCompat(relationId, \
stmt, \
indexRelationId, \
parentIndexId, \
parentConstraintId, \
total_parts, \
is_alter_table, \
check_rights, \
check_not_in_use, \
skip_build, \
quiet) \
DefineIndex(relationId, \
stmt, \
indexRelationId, \
parentIndexId, \
parentConstraintId, \
total_parts, \
is_alter_table, \
check_rights, \
check_not_in_use, \
skip_build, \
quiet)
#endif
#if PG16_LT
#include <catalog/pg_database_d.h>
#include <catalog/pg_foreign_server_d.h>
#include <catalog/pg_namespace_d.h>
#include <catalog/pg_proc_d.h>
#include <catalog/pg_tablespace_d.h>
#include <utils/acl.h>
/*
* PG16 replaces most aclcheck functions with a common object_aclcheck() function
* https://github.com/postgres/postgres/commit/c727f511
*/
static inline AclResult
object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
{
switch (classid)
{
case DatabaseRelationId:
return pg_database_aclcheck(objectid, roleid, mode);
case ForeignServerRelationId:
return pg_foreign_server_aclcheck(objectid, roleid, mode);
case NamespaceRelationId:
return pg_namespace_aclcheck(objectid, roleid, mode);
case ProcedureRelationId:
return pg_proc_aclcheck(objectid, roleid, mode);
case TableSpaceRelationId:
return pg_tablespace_aclcheck(objectid, roleid, mode);
default:
Assert(false);
}
return ACLCHECK_NOT_OWNER;
}
/*
* PG16 replaces pg_foo_ownercheck() functions with a common object_ownercheck() function
* https://github.com/postgres/postgres/commit/afbfc029
*/
static inline bool
object_ownercheck(Oid classid, Oid objectid, Oid roleid)
{
switch (classid)
{
case RelationRelationId:
return pg_class_ownercheck(objectid, roleid);
default:
Assert(false);
}
return false;
}
#endif
#if PG17_LT
/*
* Backport of RestrictSearchPath() from PG17
*
* We skip the check for IsBootstrapProcessingMode() since it creates problems
* on Windows builds and we don't need it for our use case.
*/
#include <utils/guc.h>
static inline void
RestrictSearchPath(void)
{
set_config_option("search_path",
"pg_catalog, pg_temp",
PGC_USERSET,
PGC_S_SESSION,
GUC_ACTION_SAVE,
true,
0,
false);
}
/*
* murmurhash64 was added to common/hashfn.h in PG17 (954e43564d9).
*/
static inline uint64
murmurhash64(uint64 data)
{
uint64 h = data;
h ^= h >> 33;
h *= 0xff51afd7ed558ccd;
h ^= h >> 33;
h *= 0xc4ceb9fe1a85ec53;
h ^= h >> 33;
return h;
}
#endif
#if PG17_LT
/* This macro was renamed in PG17, see 414f6c0fb79a */
#define WAIT_EVENT_MESSAGE_QUEUE_INTERNAL WAIT_EVENT_MQ_INTERNAL
/* 'flush' argument was added in 173b56f1ef59 */
#define LogLogicalMessageCompat(prefix, message, size, transactional, flush) \
LogLogicalMessage(prefix, message, size, transactional)
/* 'stmt' argument was added in f21848de2013 */
#define reindex_relation_compat(stmt, relid, flags, params) reindex_relation(relid, flags, params)
/* 'vacuum_is_relation_owner' was renamed to 'vacuum_is_permitted_for_relation' in ecb0fd33720f */
#define vacuum_is_permitted_for_relation_compat(relid, reltuple, options) \
vacuum_is_relation_owner(relid, reltuple, options)
/*
* 'BackendIdGetProc' was renamed to 'ProcNumberGetProc' in 024c52111757.
* Also 'backendId' was renamed to 'procNumber'
*/
#define VirtualTransactionGetProcCompat(vxid) BackendIdGetProc((vxid)->backendId)
/*
* 'opclassOptions' argument was added in 784162357130.
* Previously indexInfo->ii_OpclassOptions was used instead.
* On top of that 'stattargets' argument was added in 6a004f1be87d.
*/
#define index_create_compat(heapRelation, \
indexRelationName, \
indexRelationId, \
parentIndexRelid, \
parentConstraintId, \
relFileNumber, \
indexInfo, \
indexColNames, \
accessMethodId, \
tableSpaceId, \
collationIds, \
opclassIds, \
opclassOptions, \
coloptions, \
stattargets, \
reloptions, \
flags, \
constr_flags, \
allow_system_table_mods, \
is_internal, \
constraintId) \
index_create(heapRelation, \
indexRelationName, \
indexRelationId, \
parentIndexRelid, \
parentConstraintId, \
relFileNumber, \
indexInfo, \
indexColNames, \
accessMethodId, \
tableSpaceId, \
collationIds, \
opclassIds, \
coloptions, \
reloptions, \
flags, \
constr_flags, \
allow_system_table_mods, \
is_internal, \
constraintId)
#else /* PG17_GE */
#define LogLogicalMessageCompat(prefix, message, size, transactional, flush) \
LogLogicalMessage(prefix, message, size, transactional, flush)
#define reindex_relation_compat(stmt, relid, flags, params) \
reindex_relation(stmt, relid, flags, params)
#define vacuum_is_permitted_for_relation_compat(relid, reltuple, options) \
vacuum_is_permitted_for_relation(relid, reltuple, options)
#define VirtualTransactionGetProcCompat(vxid) ProcNumberGetProc(vxid->procNumber)
#define index_create_compat(heapRelation, \
indexRelationName, \
indexRelationId, \
parentIndexRelid, \
parentConstraintId, \
relFileNumber, \
indexInfo, \
indexColNames, \
accessMethodId, \
tableSpaceId, \
collationIds, \
opclassIds, \
opclassOptions, \
coloptions, \
stattargets, \
reloptions, \
flags, \
constr_flags, \
allow_system_table_mods, \
is_internal, \
constraintId) \
index_create(heapRelation, \
indexRelationName, \
indexRelationId, \
parentIndexRelid, \
parentConstraintId, \
relFileNumber, \
indexInfo, \
indexColNames, \
accessMethodId, \
tableSpaceId, \
collationIds, \
opclassIds, \
opclassOptions, \
coloptions, \
stattargets, \
reloptions, \
flags, \
constr_flags, \
allow_system_table_mods, \
is_internal, \
constraintId)
#endif
#if PG17_LT
/* 'mergeActions' argument was added in 5f2e179bd31e */
#define CheckValidResultRelCompat(resultRelInfo, operation, onConflictAction, mergeActions) \
CheckValidResultRel(resultRelInfo, operation)
#elif PG18_LT
#define CheckValidResultRelCompat(resultRelInfo, operation, onConflictAction, mergeActions) \
CheckValidResultRel(resultRelInfo, operation, mergeActions)
#else
#define CheckValidResultRelCompat(resultRelInfo, operation, onConflictAction, mergeActions) \
CheckValidResultRel(resultRelInfo, operation, onConflictAction, mergeActions)
#endif
#if PG17_LT
/*
* Overflow-aware comparison functions to be used in qsort. Introduced in PG
* 17 and included here for older PG versions.
*/
static inline int
pg_cmp_u32(uint32 a, uint32 b)
{
return (a > b) - (a < b);
}
#endif
#if PG16_LT
/*
* Similarly, wrappers around labs()/llabs() matching our int64.
*
* Introduced on PG16:
* https://github.com/postgres/postgres/commit/357cfefb09115292cfb98d504199e6df8201c957
*/
#ifdef HAVE_LONG_INT_64
#define i64abs(i) labs(i)
#else
#define i64abs(i) llabs(i)
#endif
#endif
/*
* PG18 adds IndexScanInstrumentation parameter to index_beginscan
* https://github.com/postgres/postgres/commit/0fbceae8
*/
#if PG18_LT
#define index_beginscan_compat(heapRelation, \
indexRelation, \
snapshot, \
instrument, \
nkeys, \
norderbys) \
index_beginscan(heapRelation, indexRelation, snapshot, nkeys, norderbys)
#else
#define index_beginscan_compat(heapRelation, \
indexRelation, \
snapshot, \
instrument, \
nkeys, \
norderbys) \
index_beginscan(heapRelation, indexRelation, snapshot, instrument, nkeys, norderbys)
#endif
#if PG16_LT
#define make_range_compat(typcache, lower, upper, empty, escontext) \
make_range(typcache, lower, upper, empty)
#else
#define make_range_compat(typcache, lower, upper, empty, escontext) \
make_range(typcache, lower, upper, empty, escontext)
#endif
/* Copied from PG17. We can remove it once we deprecate older versions. */
#if PG17_LT
static inline void
initReadOnlyStringInfo(StringInfo str, char *data, int len)
{
str->data = data;
str->len = len;
str->maxlen = 0; /* read-only */
str->cursor = 0;
}
#endif
/*
* PG18 renames ri_ConstraintExprs to ri_CheckConstraintExprs
* Add macros so we can use the new naming for older versions.
* https://github.com/postgres/postgres/commit/9a9ead11
*/
#if PG18_LT
#define ri_CheckConstraintExprs ri_ConstraintExprs
#endif
/*
* PG18 renames ec_derives to ec_derives_list
* Add macros so we can use the new naming for older versions.
* https://github.com/postgres/postgres/commit/88f55bc9
*/
#if PG18_LT
#define ec_derives_list ec_derives
#endif
/* PG18 introduces new CompareType for ordering operations
* Add macros so we can use the new naming for older versions.
* https://github.com/postgres/postgres/commit/8123e91f
*/
#if PG18_LT
#define CompareType int16
#define COMPARE_LT BTLessStrategyNumber
#define COMPARE_GT BTGreaterStrategyNumber
#define pk_cmptype pk_strategy
#endif
/* PG18 adds is_merge_delete param to ExecBR{Delete|Update}Triggers function.
* This has been backported to 17.6 but with a new name (ExecBR{Delete|Update}TriggersNew)j
* Add compat function to cover 3 versions (pre 17.6, 17.6 - 18, post 18)
* https://github.com/postgres/postgres/commit/5022ff25
*/
#if PG_VERSION_NUM < 170006
#define ExecBRDeleteTriggersCompat(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete) \
ExecBRDeleteTriggers(estate, epqstate, relinfo, tupleid, fdw_trigtuple, epqslot, tmresult, tmfd)
#define ExecBRUpdateTriggersCompat(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete) \
ExecBRUpdateTriggers(estate, epqstate, relinfo, tupleid, fdw_trigtuple, epqslot, tmresult, tmfd)
#endif
#if PG_VERSION_NUM >= 170006 && PG_VERSION_NUM < 180000
#define ExecBRDeleteTriggersCompat(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete) \
ExecBRDeleteTriggersNew(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete)
#define ExecBRUpdateTriggersCompat(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete) \
ExecBRUpdateTriggersNew(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete)
#endif
#if PG18_GE
#define ExecBRDeleteTriggersCompat(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete) \
ExecBRDeleteTriggers(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete)
#define ExecBRUpdateTriggersCompat(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete) \
ExecBRUpdateTriggers(estate, \
epqstate, \
relinfo, \
tupleid, \
fdw_trigtuple, \
epqslot, \
tmresult, \
tmfd, \
is_merge_delete)
#endif
/* PG16 removes create_new_ph parameter from add_vars_to_targetlist
* https://github.com/postgres/postgres/commit/2489d76c4906 */
#if PG16_LT
#define add_vars_to_targetlist_compat(root, vars, where_needed) \
add_vars_to_targetlist(root, vars, where_needed, false)
#else
#define add_vars_to_targetlist_compat(root, vars, where_needed) \
add_vars_to_targetlist(root, vars, where_needed)
#endif
/* PG16 consolidates ItemPointer to datum functions so backported it to PG15
* https://github.com/postgres/postgres/commit/bd944884e92a */
#if PG16_LT
static inline ItemPointer
DatumGetItemPointer(Datum X)
{
return (ItemPointer) DatumGetPointer(X);
}
static inline Datum
ItemPointerGetDatum(const ItemPointerData *X)
{
return PointerGetDatum(X);
}
#endif
#if PG17_LT
/*
* PG17 added the 'orstronger' parameter to LockHeldByMe. On older versions
* we use LockOrStrongerHeldByMe when orstronger is true.
*/
static inline bool
LockHeldByMeCompat(const LOCKTAG *locktag, LOCKMODE lockmode, bool orstronger)
{
if (orstronger)
{
return LockOrStrongerHeldByMe(locktag, lockmode);
}
return LockHeldByMe(locktag, lockmode);
}
#else
#define LockHeldByMeCompat(locktag, lockmode, orstronger) \
LockHeldByMe(locktag, lockmode, orstronger)
#endif
/* PG18 introduced PG_MODULE_MAGIC_EXT macro
https://github.com/postgres/postgres/commit/9324c8c580655800331b0582b770e88c01b7a5c4 */
#ifdef PG_MODULE_MAGIC_EXT
#define TS_MODULE_MAGIC(extname) \
PG_MODULE_MAGIC_EXT(.name = extname, .version = TIMESCALEDB_VERSION_MOD)
#else
#define TS_MODULE_MAGIC(extname) PG_MODULE_MAGIC
#endif