Skip to content

Commit 7473394

Browse files
committed
Block inheriting from a hypertable with ALTER TABLE INHERIT
Hypertable children that are not actual chunks will not be included in queries when using our hypertable expansion. Fixes: #9975
1 parent 81914af commit 7473394

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

.unreleased/pr_9982

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #9982 Reject ALTER TABLE ... INHERIT when the parent is a hypertable

src/process_utility.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4921,6 +4921,22 @@ process_altertable_start_table(ProcessUtilityArgs *args)
49214921
}
49224922
break;
49234923
}
4924+
case AT_AddInherit:
4925+
{
4926+
/* A plain table cannot inherit from a hypertable, since the
4927+
* child would not be a chunk and its rows would be hidden from
4928+
* queries on the hypertable. */
4929+
RangeVar *parent = castNode(RangeVar, cmd->def);
4930+
Oid parent_relid = RangeVarGetRelid(parent, NoLock, true);
4931+
4932+
if (OidIsValid(parent_relid) && ts_is_hypertable(parent_relid))
4933+
{
4934+
ereport(ERROR,
4935+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4936+
errmsg("hypertables do not support inheritance")));
4937+
}
4938+
break;
4939+
}
49244940

49254941
case AT_SetRelOptions:
49264942
{

test/expected/ddl_errors.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ CREATE TABLE PUBLIC."Hyper_Child" () INHERITS ("Hypertable_1");
6060
ERROR: hypertables do not support inheritance
6161
CREATE TABLE PUBLIC."Hyper_Child" (extra int) INHERITS (PUBLIC."Hypertable_1", PUBLIC."Parent");
6262
ERROR: hypertables do not support inheritance
63+
-- a plain table cannot inherit from a hypertable
64+
CREATE TABLE PUBLIC."Inherit_Child" (LIKE "Hypertable_1");
65+
ALTER TABLE PUBLIC."Inherit_Child" INHERIT "Hypertable_1";
66+
ERROR: hypertables do not support inheritance
6367
\set ON_ERROR_STOP 1
6468
CREATE TABLE PUBLIC."Child" () INHERITS ("Parent");
6569
\set ON_ERROR_STOP 0

test/sql/ddl_errors.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ ALTER TABLE _timescaledb_internal._hyper_1_1_chunk INHERIT "Parent";
5353
ALTER TABLE _timescaledb_internal._hyper_1_1_chunk NO INHERIT "Parent";
5454
CREATE TABLE PUBLIC."Hyper_Child" () INHERITS ("Hypertable_1");
5555
CREATE TABLE PUBLIC."Hyper_Child" (extra int) INHERITS (PUBLIC."Hypertable_1", PUBLIC."Parent");
56+
-- a plain table cannot inherit from a hypertable
57+
CREATE TABLE PUBLIC."Inherit_Child" (LIKE "Hypertable_1");
58+
ALTER TABLE PUBLIC."Inherit_Child" INHERIT "Hypertable_1";
5659
\set ON_ERROR_STOP 1
5760

5861
CREATE TABLE PUBLIC."Child" () INHERITS ("Parent");

0 commit comments

Comments
 (0)