diff --git a/hypopg.c b/hypopg.c index 4ab76b7..fe8be62 100644 --- a/hypopg.c +++ b/hypopg.c @@ -140,22 +140,22 @@ hypo_getNewOid(Oid relid) char relpersistence; /* Open the relation on which we want a new OID */ - relation = heap_open(relid, AccessShareLock); + relation = table_open(relid, AccessShareLock); reltablespace = relation->rd_rel->reltablespace; relpersistence = relation->rd_rel->relpersistence; /* Close the relation and release the lock now */ - heap_close(relation, AccessShareLock); + table_close(relation, AccessShareLock); /* Open pg_class to aks a new OID */ - pg_class = heap_open(RelationRelationId, RowExclusiveLock); + pg_class = table_open(RelationRelationId, RowExclusiveLock); /* ask for a new relfilenode */ newoid = GetNewRelFileNode(reltablespace, pg_class, relpersistence); /* Close pg_class and release the lock now */ - heap_close(pg_class, RowExclusiveLock); + table_close(pg_class, RowExclusiveLock); return newoid; } @@ -297,7 +297,7 @@ hypo_get_relation_info_hook(PlannerInfo *root, Relation relation; /* Open the current relation */ - relation = heap_open(relationObjectId, AccessShareLock); + relation = table_open(relationObjectId, AccessShareLock); if (relation->rd_rel->relkind == RELKIND_RELATION #if PG_VERSION_NUM >= 90300 @@ -324,7 +324,7 @@ hypo_get_relation_info_hook(PlannerInfo *root, } /* Close the relation release the lock now */ - heap_close(relation, AccessShareLock); + table_close(relation, AccessShareLock); } if (prev_get_relation_info_hook) diff --git a/hypopg_index.c b/hypopg_index.c index db119e1..7a1d18a 100644 --- a/hypopg_index.c +++ b/hypopg_index.c @@ -1396,7 +1396,7 @@ hypopg_get_indexdef(PG_FUNCTION_ARGS) if (indexpr_item == NULL) elog(ERROR, "too few entries in indexprs list"); indexkey = (Node *) lfirst(indexpr_item); - indexpr_item = lnext(indexpr_item); + indexpr_item = lnext(entry->indexprs, indexpr_item); /* Deparse */ str = deparse_expression(indexkey, context, false, false); @@ -1546,7 +1546,7 @@ hypo_estimate_index_simple(hypoIndex * entry, BlockNumber *pages, double *tuples rel = makeNode(RelOptInfo); /* Open the hypo index' relation */ - relation = heap_open(entry->relid, AccessShareLock); + relation = table_open(entry->relid, AccessShareLock); if (!RelationNeedsWAL(relation) && RecoveryInProgress()) ereport(ERROR, @@ -1567,7 +1567,7 @@ hypo_estimate_index_simple(hypoIndex * entry, BlockNumber *pages, double *tuples &rel->pages, &rel->tuples, &rel->allvisfrac); /* Close the relation and release the lock now */ - heap_close(relation, AccessShareLock); + table_close(relation, AccessShareLock); hypo_estimate_index(entry, rel); *pages = entry->pages; diff --git a/import/hypopg_import_index.c b/import/hypopg_import_index.c index d482f30..e6b6a2c 100644 --- a/import/hypopg_import_index.c +++ b/import/hypopg_import_index.c @@ -91,7 +91,7 @@ build_index_tlist(PlannerInfo *root, IndexOptInfo *index, if (indexpr_item == NULL) elog(ERROR, "wrong number of index expressions"); indexvar = (Expr *) lfirst(indexpr_item); - indexpr_item = lnext(indexpr_item); + indexpr_item = lnext(index->indexprs, indexpr_item); } tlist = lappend(tlist, diff --git a/include/hypopg.h b/include/hypopg.h index 5fab96d..9043264 100644 --- a/include/hypopg.h +++ b/include/hypopg.h @@ -22,6 +22,24 @@ #include "include/hypopg_import.h" +/* Provide backward compatibility macros for table.c API on pre v12 versions */ +#if PG_VERSION_NUM < 120000 +#define table_open(r, l) heap_open(r, l) +#define table_close(r, l) heap_close(r, l) +#endif + +/* + * Hacky macro to provide backward compatibility with either 1 or 2 arg lnext() + * on pre v13 versions + */ +#if PG_VERSION_NUM < 130000 +#define LNEXT(_1, _2, NAME, ...) NAME +#undef lnext +#define lnext(...) LNEXT(__VA_ARGS__, LNEXT2, LNEXT1) (__VA_ARGS__) +#define LNEXT1(lc) ((lc)->next) +#define LNEXT2(list, lc) ((lc)->next) +#endif + extern bool isExplain; /* GUC for enabling / disabling hypopg during EXPLAIN */