Skip to content

Commit

Permalink
Fix planner distributed table count
Browse files Browse the repository at this point in the history
The check for a distributed hypertable was done after ht had been
changed to the compressed hypertable potentially leading to miscount
or even segfault when the cache lookup for the compressed hypertable
returned NULL.

(cherry picked from commit 727a027)
  • Loading branch information
svenklemm authored and timescale-automation committed Sep 26, 2023
1 parent ec99b00 commit b8abf94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .unreleased/pr_6113
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixes: #6113 Fix planner distributed table count

Thanks: @symbx for reporting a crash when selecting from empty hypertables
13 changes: 6 additions & 7 deletions src/planner/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,18 @@ preprocess_query(Node *node, PreprocessQueryContext *context)
query->rowMarks == NIL && rte->inh)
rte_mark_for_expansion(rte);

if (hypertable_is_distributed(ht))
{
context->num_distributed_tables++;
}

if (TS_HYPERTABLE_HAS_COMPRESSION_TABLE(ht))
{
int compr_htid = ht->fd.compressed_hypertable_id;

/* Also warm the cache with the compressed
* companion hypertable */
ht = ts_hypertable_cache_get_entry_by_id(hcache, compr_htid);
Assert(ht != NULL);
}

if (hypertable_is_distributed(ht))
{
context->num_distributed_tables++;
ts_hypertable_cache_get_entry_by_id(hcache, compr_htid);
}
}
else
Expand Down

0 comments on commit b8abf94

Please sign in to comment.