diff --git a/src/chunk_append/chunk_append.c b/src/chunk_append/chunk_append.c index e464b9d8b..e1e37de24 100644 --- a/src/chunk_append/chunk_append.c +++ b/src/chunk_append/chunk_append.c @@ -203,45 +203,37 @@ ts_chunk_append_path_create(PlannerInfo *root, RelOptInfo *rel, Hypertable *ht, foreach (lc_oid, current_oids) { /* postgres may have pruned away some children already */ - if (lfirst_oid(lc_oid) == - root->simple_rte_array[((Path *) lfirst(flat))->parent->relid]->relid) + Path *child = (Path *) lfirst(flat); + Oid parent_relid = child->parent->relid; + bool is_not_pruned = + lfirst_oid(lc_oid) == root->simple_rte_array[parent_relid]->relid; +#if PG12_LT + Assert(is_not_pruned); +#endif + if (is_not_pruned) { - Assert(lfirst_oid(lc_oid) == - root->simple_rte_array[((Path *) lfirst(flat))->parent->relid]->relid); - merge_childs = lappend(merge_childs, lfirst(flat)); + merge_childs = lappend(merge_childs, child); flat = lnext(flat); } } if (list_length(merge_childs) > 1) { -#if PG96 - append = create_merge_append_path(root, - rel, - merge_childs, - path->cpath.path.pathkeys, - PATH_REQ_OUTER(subpath)); -#else - append = create_merge_append_path(root, - rel, - merge_childs, - path->cpath.path.pathkeys, - PATH_REQ_OUTER(subpath), - NIL); -#endif + append = create_merge_append_path_compat(root, + rel, + merge_childs, + path->cpath.path.pathkeys, + PATH_REQ_OUTER(subpath)); nested_children = lappend(nested_children, append); } -#if PG12_GE - else if (list_length(merge_childs) == 0) - { - /* nop */ - } -#endif - else + else if (list_length(merge_childs) == 1) { has_scan_childs = true; nested_children = lappend(nested_children, linitial(merge_childs)); } +#if PG12_LT + Assert(list_length(merge_childs) > 0); +#endif } Assert(flat == NULL); diff --git a/src/chunk_append/chunk_append.h b/src/chunk_append/chunk_append.h index eab90d9d4..d09543378 100644 --- a/src/chunk_append/chunk_append.h +++ b/src/chunk_append/chunk_append.h @@ -7,14 +7,6 @@ #define TIMESCALEDB_CHUNK_APPEND_H #include -#include - -#include "compat.h" -#if PG12_LT -#include -#else -#include -#endif #include "hypertable.h" diff --git a/src/compat.h b/src/compat.h index af4bd73bf..33c8ccd78 100644 --- a/src/compat.h +++ b/src/compat.h @@ -784,6 +784,15 @@ extern int oid_cmp(const void *p1, const void *p2); WaitLatch(latch, wakeEvents, timeout, PG_WAIT_EXTENSION) #endif +/* create_merge_append_path */ +#if PG96 +#define create_merge_append_path_compat(root, rel, merge_childs, pathkeys, subpath) \ + create_merge_append_path(root, rel, merge_childs, pathkeys, subpath) +#else +#define create_merge_append_path_compat(root, rel, merge_childs, pathkeys, subpath) \ + create_merge_append_path(root, rel, merge_childs, pathkeys, subpath, NIL) +#endif + /* pq_sendint is deprecated in PG11, so create pq_sendint32 in 9.6 and 10 */ #if PG11_LT #define pq_sendint32(buf, i) pq_sendint(buf, i, 4)