级联更新始终在引用表所有者的安全上下文中运行(
test.table
在您的示例中)。
看见
ri_PerformCheck
在里面
src/backend/utils/adt/ri_triggers.c
:
/*
* Use the query type code to determine whether the query is run against
* the PK or FK table; we'll do the check as that table's owner
*/
if (qkey->constr_queryno <= RI_PLAN_LAST_ON_PK)
query_rel = pk_rel;
else
query_rel = fk_rel;
...
/* Switch to proper UID to perform check as */
GetUserIdAndSecContext(&save_userid, &save_sec_context);
SetUserIdAndSecContext(RelationGetForm(query_rel)->relowner,
save_sec_context | SECURITY_LOCAL_USERID_CHANGE |
SECURITY_NOFORCE_RLS);
我试图遵循代码的起源,而行为似乎起源于提交
465cf168eb6151275016486fe2d2c629fed967ca
。
在黑客档案中搜索相关讨论,我发现
this
。
因此,据我所知,这种行为试图避免以下情况:
-
使用者
A
拥有
atable
和赠款
REFERENCES
在该表上发送给用户
B
。
-
使用者
B
拥有
btable
并将外键添加到
A表格
具有
ON UPDATE OR DELETE CASCADE
使用者
A.
对没有权限
B表格
。
-
使用者
A.
尝试更新或删除中的行
A表格
这将级联到
B表格
并失败,出现“权限被拒绝”错误。
我个人不确定目前的行为是好是坏,但我可以看到这一点,这将是令人惊讶的
A.
'无法修改她拥有的表。