Skip to content

Commit e1c68ed

Browse files
author
Rahul Parande
committed
Added view repair hook in RTE, dependency check hook during Alter table
Signed-off-by: Rahul Parande <[email protected]>
1 parent 80eefd0 commit e1c68ed

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/backend/commands/tablecmds.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ InvokePreDropColumnHook_type InvokePreDropColumnHook = NULL;
138138
check_extended_attoptions_hook_type check_extended_attoptions_hook = NULL;
139139
find_attr_by_name_from_column_def_list_hook_type
140140
find_attr_by_name_from_column_def_list_hook = NULL;
141+
object_dependency_hook_type object_dependency_hook = NULL;
141142

142143
/*
143144
* State information for ALTER TABLE
@@ -13678,12 +13679,21 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype,
1367813679
* function bodies. FIXME someday.
1367913680
*/
1368013681
if (subtype == AT_AlterColumnType)
13682+
{
13683+
ObjectAddress columnAddr;
13684+
columnAddr.classId = RelationRelationId;
13685+
columnAddr.objectId = RelationGetRelid(rel);
13686+
columnAddr.objectSubId = attnum;
13687+
13688+
if (object_dependency_hook && (*object_dependency_hook)(&foundObject, &columnAddr))
13689+
continue;
1368113690
ereport(ERROR,
1368213691
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1368313692
errmsg("cannot alter type of a column used by a view or rule"),
1368413693
errdetail("%s depends on column \"%s\"",
1368513694
getObjectDescription(&foundObject, false),
1368613695
colName)));
13696+
}
1368713697
break;
1368813698

1368913699
case TriggerRelationId:

src/backend/parser/parse_relation.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static bool rte_visible_if_lateral(ParseState *pstate, RangeTblEntry *rte);
107107
static bool rte_visible_if_qualified(ParseState *pstate, RangeTblEntry *rte);
108108
static bool isQueryUsingTempRelation_walker(Node *node, void *context);
109109

110+
range_table_entry_hook_type range_table_entry_hook = NULL;
110111

111112
/*
112113
* refnameNamespaceItem
@@ -1522,6 +1523,9 @@ addRangeTableEntry(ParseState *pstate,
15221523
rte->rtekind = RTE_RELATION;
15231524
rte->alias = alias;
15241525

1526+
if (range_table_entry_hook)
1527+
(*range_table_entry_hook)(pstate, relation, rte);
1528+
15251529
/*
15261530
* Identify the type of lock we'll need on this relation. It's not the
15271531
* query's target table (that case is handled elsewhere), so we need

src/include/commands/tablecmds.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,9 @@ typedef int (*find_attr_by_name_from_column_def_list_hook_type) (
122122
extern PGDLLEXPORT find_attr_by_name_from_column_def_list_hook_type
123123
find_attr_by_name_from_column_def_list_hook;
124124

125+
typedef bool (*object_dependency_hook_type)(const ObjectAddress *depender,
126+
const ObjectAddress *referenced);
127+
128+
extern PGDLLEXPORT object_dependency_hook_type object_dependency_hook;
129+
125130
#endif /* TABLECMDS_H */

src/include/parser/parse_relation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,11 @@ typedef int (*find_attr_by_name_from_relation_hook_type) (
131131
extern PGDLLEXPORT find_attr_by_name_from_relation_hook_type
132132
find_attr_by_name_from_relation_hook;
133133

134+
typedef void (*range_table_entry_hook_type)(ParseState *pstate,
135+
RangeVar *relation,
136+
RangeTblEntry *rte);
137+
138+
/* Hook for plugins to take action after relation open */
139+
extern PGDLLEXPORT range_table_entry_hook_type range_table_entry_hook;
140+
134141
#endif /* PARSE_RELATION_H */

0 commit comments

Comments
 (0)