Skip to content

Commit

Permalink
Correctly determine relation type of OSM chunk as standalone table (t…
Browse files Browse the repository at this point in the history
…imescale#6840)

Previously we only handled the case of OSM chunk expanded as a child of
hypertable, so in the case of direct select it segfaulted while trying
to access an fdw_private which is managed by OSM.
  • Loading branch information
akuzm authored Apr 18, 2024
1 parent f4ec0f4 commit 069ccbe
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/planner/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,16 @@ ts_classify_relation(const PlannerInfo *root, const RelOptInfo *rel, Hypertable

RangeTblEntry *rte = planner_rt_fetch(rel->relid, root);

if (rte->relkind == RELKIND_FOREIGN_TABLE)
{
/*
* OSM chunk or other foreign chunk. We can't even access the
* fdw_private for it, because it's a foreign chunk managed by a
* different extension. Try to ignore it as much as possible.
*/
return TS_REL_OTHER;
}

if (!OidIsValid(rte->relid))
{
return TS_REL_OTHER;
Expand Down Expand Up @@ -797,16 +807,6 @@ ts_classify_relation(const PlannerInfo *root, const RelOptInfo *rel, Hypertable
*ht = entry->ht;
if (*ht)
{
if (rte->relkind == RELKIND_FOREIGN_TABLE)
{
/*
* OSM chunk or other foreign chunk. We can't even access the
* fdw_private for it, because it's a foreign chunk managed by a
* different extension. Try to ignore it as much as possible.
*/
return TS_REL_OTHER;
}

return TS_REL_CHUNK_CHILD;
}

Expand Down
4 changes: 3 additions & 1 deletion test/test-defs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ endif()
# This variable is set differently in CI. We use it to save the logs outside the
# tmp instance, because it is deleted by pg_regress on successful test
# completion, and we want to run some additional checks on the logs in any case.
option(TEST_PG_LOG_DIRECTORY "Log directory for regression tests" "log")
set(TEST_PG_LOG_DIRECTORY
"log"
CACHE STRING "Log directory for regression tests")

if(USE_TELEMETRY)
set(TELEMETRY_DEFAULT_SETTING "timescaledb.telemetry_level=off")
Expand Down
15 changes: 15 additions & 0 deletions tsl/test/expected/chunk_utils_internal.out
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,13 @@ SELECT * FROM ht_try ORDER BY 1;
Thu May 05 01:00:00 2022 PDT | 222 | 222
(2 rows)

-- Check that the direct select from OSM chunk doesn't lead to bad effects.
SELECT * FROM child_fdw_table;
timec | acq_id | value
------------------------------+--------+-------
Wed Jan 01 01:00:00 2020 PST | 100 | 1000
(1 row)

SELECT relname, relowner::regrole FROM pg_class
WHERE relname in ( select chunk_name FROM chunk_view
WHERE hypertable_name = 'ht_try' )
Expand Down Expand Up @@ -800,6 +807,14 @@ BEGIN
WHERE acq_id = 10 AND timec > now() - '15 years'::interval INTO r;
END
$$ LANGUAGE plpgsql;
-- Check that the direct select from OSM chunk doesn't lead to bad effects in
-- presence of compression.
SELECT * FROM child_fdw_table;
timec | acq_id | value
------------------------------+--------+-------
Wed Jan 01 01:00:00 2020 PST | 100 | 1000
(1 row)

--TEST insert into a OSM chunk fails. actually any insert will fail. But we just need
-- to mock the hook and make sure the timescaledb code works correctly.
SELECT ts_setup_osm_hook();
Expand Down
7 changes: 7 additions & 0 deletions tsl/test/sql/chunk_utils_internal.sql
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ ORDER BY chunk_name;

SELECT * FROM ht_try ORDER BY 1;

-- Check that the direct select from OSM chunk doesn't lead to bad effects.
SELECT * FROM child_fdw_table;

SELECT relname, relowner::regrole FROM pg_class
WHERE relname in ( select chunk_name FROM chunk_view
WHERE hypertable_name = 'ht_try' )
Expand Down Expand Up @@ -429,6 +432,10 @@ BEGIN
END
$$ LANGUAGE plpgsql;

-- Check that the direct select from OSM chunk doesn't lead to bad effects in
-- presence of compression.
SELECT * FROM child_fdw_table;

--TEST insert into a OSM chunk fails. actually any insert will fail. But we just need
-- to mock the hook and make sure the timescaledb code works correctly.

Expand Down

0 comments on commit 069ccbe

Please sign in to comment.