Skip to content

Commit 7572e08

Browse files
committed
Propagate schema changes to child Iceberg tables in inheritance hierarchies
Signed-off-by: PJ <[email protected]>
1 parent 8bd5c90 commit 7572e08

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pg_lake_table/src/ddl/alter_table.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "catalog/heap.h"
2424
#include "catalog/namespace.h"
2525
#include "catalog/pg_class.h"
26+
#include "catalog/pg_inherits.h"
2627
#include "catalog/pg_type.h"
2728
#include "commands/defrem.h"
2829
#include "commands/tablecmds.h"
@@ -113,6 +114,7 @@ typedef struct PgLakeDDL
113114
static bool Allowed(Node *arg);
114115
static bool Disallowed(Node *arg);
115116
static bool DisallowedAddColumnWithUnsupportedConstraints(Node *arg);
117+
static void PropagateSchemaChangesToChildren(Oid parentRelationId, List *schemaDDLOperations);
116118

117119
PgLakeAlterTableHookType PgLakeAlterTableHook = NULL;
118120
PgLakeAlterTableRenameColumnHookType PgLakeAlterTableRenameColumnHook = NULL;
@@ -327,6 +329,9 @@ ProcessAlterTable(ProcessUtilityParams * processUtilityParams, void *arg)
327329

328330
ApplyDDLChanges(relationId, schemaDDLOperations);
329331

332+
if (list_length(schemaDDLOperations) > 0)
333+
PropagateSchemaChangesToChildren(relationId, schemaDDLOperations);
334+
330335
if (PgLakeAlterTableHook)
331336
PgLakeAlterTableHook(relationId, alterStmt);
332337

@@ -335,6 +340,27 @@ ProcessAlterTable(ProcessUtilityParams * processUtilityParams, void *arg)
335340
}
336341

337342

343+
static void
344+
PropagateSchemaChangesToChildren(Oid parentRelationId, List *schemaDDLOperations)
345+
{
346+
List *children = find_all_inheritors(parentRelationId, NoLock, NULL);
347+
ListCell *lc;
348+
349+
foreach(lc, children)
350+
{
351+
Oid childOid = lfirst_oid(lc);
352+
353+
if (childOid == parentRelationId)
354+
continue;
355+
356+
if (!IsPgLakeIcebergForeignTableById(childOid))
357+
continue;
358+
359+
ApplyDDLChanges(childOid, schemaDDLOperations);
360+
}
361+
}
362+
363+
338364
/*
339365
* CreateDDLOperationsForAlterTable is used to create column operations
340366
* for an ALTER TABLE command. The operation is used to update the column mappings

0 commit comments

Comments
 (0)