Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc6be1f4

Browse files
committed
Make INSERT/UPDATE queries depend on their specific target columns.
We have always created a whole-table dependency for the target relation,but that's not really good enough, as it doesn't prevent scenarios suchas dropping an individual target column or altering its type. So wehave to create an individual dependency for each target column, as well.Per report from Bill MacArthur of a rule containing UPDATE breakingafter such an alteration. Note that this patch doesn't try to makesuch cases work, only to ensure that the attempted ALTER TABLE throwsan error telling you it can't cope with adjusting the rule.This is a long-standing bug, but given the lack of prior reportsI'm not going to risk back-patching it. A back-patch wouldn't doanything to fix existing rules' dependency lists, anyway.
1 parent8142166 commitc6be1f4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎src/backend/catalog/dependency.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,37 @@ find_expr_references_walker(Node *node,
17431743
}
17441744
}
17451745

1746+
/*
1747+
* If the query is an INSERT or UPDATE, we should create a dependency
1748+
* on each target column, to prevent the specific target column from
1749+
* being dropped. Although we will visit the TargetEntry nodes again
1750+
* during query_tree_walker, we won't have enough context to do this
1751+
* conveniently, so do it here.
1752+
*/
1753+
if (query->commandType==CMD_INSERT||
1754+
query->commandType==CMD_UPDATE)
1755+
{
1756+
RangeTblEntry*rte;
1757+
1758+
if (query->resultRelation <=0||
1759+
query->resultRelation>list_length(query->rtable))
1760+
elog(ERROR,"invalid resultRelation %d",
1761+
query->resultRelation);
1762+
rte=rt_fetch(query->resultRelation,query->rtable);
1763+
if (rte->rtekind==RTE_RELATION)
1764+
{
1765+
foreach(lc,query->targetList)
1766+
{
1767+
TargetEntry*tle= (TargetEntry*)lfirst(lc);
1768+
1769+
if (tle->resjunk)
1770+
continue;/* ignore junk tlist items */
1771+
add_object_address(OCLASS_CLASS,rte->relid,tle->resno,
1772+
context->addrs);
1773+
}
1774+
}
1775+
}
1776+
17461777
/*
17471778
* Add dependencies on constraints listed in query's constraintDeps
17481779
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp