Skip to content

Commit

Permalink
Fix OSM build failure
Browse files Browse the repository at this point in the history
The commit timescale#6513 removed some restricted chunk operations, enabling
adding constraints to OSM chunks directly. This operation is blocked
on OSM chunks. The present commit ensures that adding a constraint
directly on an OSM chunk is blocked.
  • Loading branch information
konskov committed Jan 23, 2024
1 parent 80f1b23 commit ba48471
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/process_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ check_chunk_alter_table_operation_allowed(Oid relid, AlterTableStmt *stmt)

switch (cmd->subtype)
{
case AT_AddConstraint:
case AT_SetOptions:
case AT_ResetOptions:
case AT_SetRelOptions:
Expand All @@ -162,6 +161,18 @@ check_chunk_alter_table_operation_allowed(Oid relid, AlterTableStmt *stmt)
#endif
/* allowed on chunks */
break;
case AT_AddConstraint:
{
/* if this is an OSM chunk, block the operation */
Chunk *chunk = ts_chunk_get_by_relid(relid, false /* fail_if_not_found */);
if (chunk && chunk->fd.osm_chunk)
{
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("operation not supported on OSM chunk tables")));
}
break;
}
default:
/* disable by default */
all_allowed = false;
Expand Down
21 changes: 21 additions & 0 deletions tsl/test/expected/chunk_utils_internal.out
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,27 @@ SELECT * FROM test_chunkapp ORDER BY 1;
Thu Jan 02 01:00:00 2020 PST | 2
(2 rows)

\set ON_ERROR_STOP 0
-- test adding constraint directly on OSM chunk is blocked
ALTER TABLE test_chunkapp_fdw_child ADD CHECK (a > 0); -- non-dimensional
ERROR: operation not supported on OSM chunk tables
ALTER TABLE test_chunkapp_fdw_child ADD CHECK (time > '1600-01-01'::timestamptz); -- dimensional
ERROR: operation not supported on OSM chunk tables
-- but on hypertable, it is allowed
ALTER TABLE test_chunkapp ADD CHECK (a > 0);
\d+ test_chunkapp_fdw_child
Foreign table "public.test_chunkapp_fdw_child"
Column | Type | Collation | Nullable | Default | FDW options | Storage | Stats target | Description
--------+--------------------------+-----------+----------+---------+-------------+---------+--------------+-------------
time | timestamp with time zone | | not null | | | plain | |
a | integer | | | | | plain | |
Check constraints:
"test_chunkapp_a_check" CHECK (a > 0)
Server: s3_server
FDW options: (schema_name 'public', table_name 'test_chunkapp_fdw')
Inherits: test_chunkapp

\set ON_ERROR_STOP 1
-- test error is triggered when time dimension not found
CREATE TABLE test2(time timestamptz not null, a int);
SELECT create_hypertable('test2', 'time');
Expand Down
9 changes: 9 additions & 0 deletions tsl/test/sql/chunk_utils_internal.sql
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,15 @@ SELECT _timescaledb_functions.hypertable_osm_range_update('test_chunkapp', NULL:
EXPLAIN SELECT * FROM test_chunkapp ORDER BY 1;
SELECT * FROM test_chunkapp ORDER BY 1;

\set ON_ERROR_STOP 0
-- test adding constraint directly on OSM chunk is blocked
ALTER TABLE test_chunkapp_fdw_child ADD CHECK (a > 0); -- non-dimensional
ALTER TABLE test_chunkapp_fdw_child ADD CHECK (time > '1600-01-01'::timestamptz); -- dimensional
-- but on hypertable, it is allowed
ALTER TABLE test_chunkapp ADD CHECK (a > 0);
\d+ test_chunkapp_fdw_child
\set ON_ERROR_STOP 1

-- test error is triggered when time dimension not found
CREATE TABLE test2(time timestamptz not null, a int);
SELECT create_hypertable('test2', 'time');
Expand Down

0 comments on commit ba48471

Please sign in to comment.