Skip to content

Commit 053a913

Browse files
committed
Adjust to PG18 PathKey changes
PG18 changes the field for ordering operation from int16 to CompareType and also changes the field name in PathKey from pk_strategy to pk_cmptype. Additionally BTLessStrategyNumber is renamed to COMPARE_LT and BTGreaterStrategyNumber is renamed to COMPARE_GT. This patch adds compatibility macros so we can use the PG18 naming everywhere. postgres/postgres@8123e91f Convert PathKey to use CompareType
1 parent 9ea7980 commit 053a913

7 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/compat/compat.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,3 +729,14 @@ initReadOnlyStringInfo(StringInfo str, char *data, int len)
729729
#if PG18_LT
730730
#define ec_derives_list ec_derives
731731
#endif
732+
733+
/* PG18 introduces new CompareType for ordering operations
734+
* Add macros so we can use the new naming for older versions.
735+
* https://github.com/postgres/postgres/commit/8123e91f
736+
*/
737+
#if PG18_LT
738+
#define CompareType int16
739+
#define COMPARE_LT BTLessStrategyNumber
740+
#define COMPARE_GT BTGreaterStrategyNumber
741+
#define pk_cmptype pk_strategy
742+
#endif

src/import/planner.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,11 @@ ts_prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys, Relids relids,
609609
sortop = get_opfamily_member(pathkey->pk_opfamily,
610610
pk_datatype,
611611
pk_datatype,
612-
pathkey->pk_strategy);
612+
pathkey->pk_cmptype);
613613
if (!OidIsValid(sortop)) /* should not happen */
614614
elog(ERROR,
615615
"missing operator %d(%u,%u) in opfamily %u",
616-
pathkey->pk_strategy,
616+
pathkey->pk_cmptype,
617617
pk_datatype,
618618
pk_datatype,
619619
pathkey->pk_opfamily);

src/sort_transform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ ts_sort_transform_get_pathkeys(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry
454454
new_pk = make_canonical_pathkey(root,
455455
transformed,
456456
last_pk->pk_opfamily,
457-
last_pk->pk_strategy,
457+
last_pk->pk_cmptype,
458458
last_pk->pk_nulls_first);
459459

460460
/*

tsl/src/continuous_aggs/planner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ cagg_sort_pushdown(Query *parse, int *cursor_opts)
437437
linitial_node(SortGroupClause, mat_rte->subquery->sortClause)->tleSortGroupRef;
438438

439439
Oid placeholder;
440-
int16 strategy;
440+
CompareType strategy;
441441
get_ordering_op_properties(sort->sortop, &placeholder, &placeholder, &strategy);
442442

443443
/*

tsl/src/nodes/decompress_chunk/decompress_chunk.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ append_ec_for_seqnum(PlannerInfo *root, const CompressionInfo *info, const SortI
8989
MemoryContext oldcontext = MemoryContextSwitchTo(root->planner_cxt);
9090

9191
Oid opfamily, opcintype, equality_op;
92-
int16 strategy;
92+
CompareType strategy;
9393
List *opfamilies;
9494
EquivalenceClass *newec = makeNode(EquivalenceClass);
9595
EquivalenceMember *em = makeNode(EquivalenceMember);
@@ -276,7 +276,7 @@ build_compressed_scan_pathkeys(const SortInfo *sort_info, PlannerInfo *root, Lis
276276

277277
/* Find the operator in pg_amop --- failure shouldn't happen. */
278278
Oid opfamily, opcintype;
279-
int16 strategy;
279+
CompareType strategy;
280280
if (!get_ordering_op_properties(sortop, &opfamily, &opcintype, &strategy))
281281
elog(ERROR, "operator %u is not a valid ordering operator", sortop);
282282

@@ -314,7 +314,7 @@ build_compressed_scan_pathkeys(const SortInfo *sort_info, PlannerInfo *root, Lis
314314
ts_array_get_element_bool(info->settings->fd.orderby_nullsfirst, orderby_index);
315315

316316
bool nulls_first;
317-
int16 strategy;
317+
CompareType strategy;
318318

319319
if (sort_info->reverse)
320320
{
@@ -2197,11 +2197,11 @@ match_pathkeys_to_compression_orderby(List *pathkeys, List *chunk_em_exprs,
21972197
orderby_index);
21982198

21992199
/*
2200-
* pk_strategy is either BTLessStrategyNumber (for ASC) or
2201-
* BTGreaterStrategyNumber (for DESC)
2200+
* In PG18+: pk_cmptype is either COMPARE_LT (for ASC) or COMPARE_GT (for DESC)
2201+
* For previous PG versions we have compatibility macros to make these new names available.
22022202
*/
22032203
bool this_pathkey_reverse = false;
2204-
if (pk->pk_strategy == BTLessStrategyNumber)
2204+
if (pk->pk_cmptype == COMPARE_LT)
22052205
{
22062206
if (!orderby_desc && orderby_nullsfirst == pk->pk_nulls_first)
22072207
{
@@ -2216,7 +2216,7 @@ match_pathkeys_to_compression_orderby(List *pathkeys, List *chunk_em_exprs,
22162216
return false;
22172217
}
22182218
}
2219-
else if (pk->pk_strategy == BTGreaterStrategyNumber)
2219+
else if (pk->pk_cmptype == COMPARE_GT)
22202220
{
22212221
if (orderby_desc && orderby_nullsfirst == pk->pk_nulls_first)
22222222
{

tsl/src/nodes/decompress_chunk/planner.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,11 +1238,11 @@ decompress_chunk_plan_create(PlannerInfo *root, RelOptInfo *rel, CustomPath *pat
12381238
Oid sortop = get_opfamily_member(pk->pk_opfamily,
12391239
var->vartype,
12401240
var->vartype,
1241-
pk->pk_strategy);
1241+
pk->pk_cmptype);
12421242
if (!OidIsValid(sortop)) /* should not happen */
12431243
elog(ERROR,
12441244
"missing operator %d(%u,%u) in opfamily %u",
1245-
pk->pk_strategy,
1245+
pk->pk_cmptype,
12461246
var->vartype,
12471247
var->vartype,
12481248
pk->pk_opfamily);
@@ -1279,7 +1279,7 @@ decompress_chunk_plan_create(PlannerInfo *root, RelOptInfo *rel, CustomPath *pat
12791279

12801280
/* Find the operator in pg_amop --- failure shouldn't happen */
12811281
Oid opfamily, opcintype;
1282-
int16 strategy;
1282+
CompareType strategy;
12831283
if (!get_ordering_op_properties(list_nth_oid(sort_ops, i),
12841284
&opfamily,
12851285
&opcintype,

tsl/src/nodes/gapfill/gapfill_plan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ gapfill_correct_order(PlannerInfo *root, Path *subpath, FuncExpr *func)
142142
EquivalenceMember *em = linitial(pk->pk_eclass->ec_members);
143143

144144
/* time_bucket_gapfill is last element */
145-
if (BTLessStrategyNumber == pk->pk_strategy && IsA(em->em_expr, FuncExpr) &&
145+
if (pk->pk_cmptype == COMPARE_LT && IsA(em->em_expr, FuncExpr) &&
146146
((FuncExpr *) em->em_expr)->funcid == func->funcid)
147147
{
148148
int i;
@@ -376,7 +376,7 @@ gapfill_path_create(PlannerInfo *root, Path *subpath, FuncExpr *func)
376376
if (!pk_func && IsA(em->em_expr, FuncExpr) &&
377377
((FuncExpr *) em->em_expr)->funcid == func->funcid)
378378
{
379-
if (BTLessStrategyNumber == pk->pk_strategy)
379+
if (pk->pk_cmptype == COMPARE_LT)
380380
pk_func = pk;
381381
else
382382
pk_func = make_canonical_pathkey(root,

0 commit comments

Comments
 (0)