mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-25 07:40:48 +08:00
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:
parent
2c7b42d044
commit
9a3211f3aa
@ -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);
|
||||
|
@ -7,14 +7,6 @@
|
||||
#define TIMESCALEDB_CHUNK_APPEND_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"
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user