| From 8cf647f2995afbd594d67abb1e6556b97096a1c6 Mon Sep 17 00:00:00 2001 |
| From: Sven Klemm <sven@timescale.com> |
| Date: Thu, 24 Sep 2020 04:42:45 +0200 |
| Subject: [PATCH] Adjust hypertable expansion to PG13 changes |
| |
| PG13 merges setup_append_rel_array into setup_simple_rel_arrays |
| which we use to build the append_rel_array. |
| |
| https://github.com/postgres/postgres/commit/1661a40505 |
| |
| Signed-off-by: Maxim Kochetkov <fido_max@inbox.ru> |
| Fetch from: https://github.com/timescale/timescaledb/pull/2735/commits/e6e2711d8e00958cb0a35c23f4e81a75f273113a.patch |
| --- |
| src/plan_expand_hypertable.c | 30 ++++++++++++++++++++++++++++-- |
| 1 file changed, 28 insertions(+), 2 deletions(-) |
| |
| diff --git a/src/plan_expand_hypertable.c b/src/plan_expand_hypertable.c |
| index 2b99c93b..4baa1b4c 100644 |
| --- a/src/plan_expand_hypertable.c |
| +++ b/src/plan_expand_hypertable.c |
| @@ -95,6 +95,24 @@ is_time_bucket_function(Expr *node) |
| return false; |
| } |
| |
| +#if PG13_GE |
| +/* PG13 merged setup_append_rel_array with setup_simple_rel_arrays */ |
| +static void |
| +setup_append_rel_array(PlannerInfo *root) |
| +{ |
| + root->append_rel_array = |
| + repalloc(root->append_rel_array, root->simple_rel_array_size * sizeof(AppendRelInfo *)); |
| + ListCell *lc; |
| + foreach (lc, root->append_rel_list) |
| + { |
| + AppendRelInfo *appinfo = lfirst_node(AppendRelInfo, lc); |
| + int child_relid = appinfo->child_relid; |
| + |
| + root->append_rel_array[child_relid] = appinfo; |
| + } |
| +} |
| +#endif |
| + |
| /* |
| * Pre-check to determine if an expression is eligible for constification. |
| * A more thorough check is in constify_timestamptz_op_interval. |
| @@ -1146,7 +1164,6 @@ ts_plan_expand_hypertable_chunks(Hypertable *ht, PlannerInfo *root, RelOptInfo * |
| .join_conditions = NIL, |
| .propagate_conditions = NIL, |
| }; |
| - Size old_rel_array_len; |
| Index first_chunk_index = 0; |
| #if PG12_GE |
| Index i; |
| @@ -1178,6 +1195,11 @@ ts_plan_expand_hypertable_chunks(Hypertable *ht, PlannerInfo *root, RelOptInfo * |
| propagate_join_quals(root, rel, &ctx); |
| |
| inh_oids = get_chunk_oids(&ctx, root, rel, ht); |
| + |
| + /* nothing to do here if we have no chunks and no data nodes */ |
| + if (list_length(inh_oids) + list_length(ht->data_nodes) == 0) |
| + return; |
| + |
| oldrelation = table_open(parent_oid, NoLock); |
| |
| /* |
| @@ -1185,7 +1207,10 @@ ts_plan_expand_hypertable_chunks(Hypertable *ht, PlannerInfo *root, RelOptInfo * |
| * children to them. We include potential data node rels we might need to |
| * create in case of a distributed hypertable. |
| */ |
| - old_rel_array_len = root->simple_rel_array_size; |
| +#if PG12_GE |
| + expand_planner_arrays(root, list_length(inh_oids) + list_length(ht->data_nodes)); |
| +#else |
| + Size old_rel_array_len = root->simple_rel_array_size; |
| root->simple_rel_array_size += (list_length(inh_oids) + list_length(ht->data_nodes)); |
| root->simple_rel_array = |
| repalloc(root->simple_rel_array, root->simple_rel_array_size * sizeof(RelOptInfo *)); |
| @@ -1200,6 +1225,7 @@ ts_plan_expand_hypertable_chunks(Hypertable *ht, PlannerInfo *root, RelOptInfo * |
| memset(root->simple_rte_array + old_rel_array_len, |
| 0, |
| list_length(inh_oids) * sizeof(*root->simple_rte_array)); |
| +#endif |
| |
| /* Adding partition info will make PostgreSQL consider the inheritance |
| * children as part of a partitioned relation. This will enable |
| -- |
| 2.29.2 |
| |