Refactor chunk append

Improve readability of code, which takes care of pruned children in
PG12. Abstract away difference in a function cardinality between PG96
and later.
This commit is contained in:
Ruslan Fomkin 2020-02-11 15:03:59 +01:00 committed by Erik Nordström
parent 2c7b42d044
commit 9a3211f3aa
3 changed files with 27 additions and 34 deletions

View File

@ -203,45 +203,37 @@ ts_chunk_append_path_create(PlannerInfo *root, RelOptInfo *rel, Hypertable *ht,
foreach (lc_oid, current_oids) foreach (lc_oid, current_oids)
{ {
/* postgres may have pruned away some children already */ /* postgres may have pruned away some children already */
if (lfirst_oid(lc_oid) == Path *child = (Path *) lfirst(flat);
root->simple_rte_array[((Path *) lfirst(flat))->parent->relid]->relid) 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) == merge_childs = lappend(merge_childs, child);
root->simple_rte_array[((Path *) lfirst(flat))->parent->relid]->relid);
merge_childs = lappend(merge_childs, lfirst(flat));
flat = lnext(flat); flat = lnext(flat);
} }
} }
if (list_length(merge_childs) > 1) if (list_length(merge_childs) > 1)
{ {
#if PG96 append = create_merge_append_path_compat(root,
append = create_merge_append_path(root, rel,
rel, merge_childs,
merge_childs, path->cpath.path.pathkeys,
path->cpath.path.pathkeys, PATH_REQ_OUTER(subpath));
PATH_REQ_OUTER(subpath));
#else
append = create_merge_append_path(root,
rel,
merge_childs,
path->cpath.path.pathkeys,
PATH_REQ_OUTER(subpath),
NIL);
#endif
nested_children = lappend(nested_children, append); nested_children = lappend(nested_children, append);
} }
#if PG12_GE else if (list_length(merge_childs) == 1)
else if (list_length(merge_childs) == 0)
{
/* nop */
}
#endif
else
{ {
has_scan_childs = true; has_scan_childs = true;
nested_children = lappend(nested_children, linitial(merge_childs)); nested_children = lappend(nested_children, linitial(merge_childs));
} }
#if PG12_LT
Assert(list_length(merge_childs) > 0);
#endif
} }
Assert(flat == NULL); Assert(flat == NULL);

View File

@ -7,14 +7,6 @@
#define TIMESCALEDB_CHUNK_APPEND_H #define TIMESCALEDB_CHUNK_APPEND_H
#include <postgres.h> #include <postgres.h>
#include <nodes/primnodes.h>
#include "compat.h"
#if PG12_LT
#include <nodes/relation.h>
#else
#include <nodes/pathnodes.h>
#endif
#include "hypertable.h" #include "hypertable.h"

View File

@ -784,6 +784,15 @@ extern int oid_cmp(const void *p1, const void *p2);
WaitLatch(latch, wakeEvents, timeout, PG_WAIT_EXTENSION) WaitLatch(latch, wakeEvents, timeout, PG_WAIT_EXTENSION)
#endif #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 */ /* pq_sendint is deprecated in PG11, so create pq_sendint32 in 9.6 and 10 */
#if PG11_LT #if PG11_LT
#define pq_sendint32(buf, i) pq_sendint(buf, i, 4) #define pq_sendint32(buf, i) pq_sendint(buf, i, 4)