尝试时CREATE POLICY
出现以下错误:
ERROR: row is too big: size XXX, maximum size 8160
pg_policies表有大小限制吗?
可以扩大,还是用连接写这么多条件是不好的做法?
现在,我通过将查询更改为更少的字符来解决它,但是如何避免呢?
几乎太长的政策示例。
CREATE POLICY check_out_insert ON check_out FOR INSERT
WITH CHECK (
(user_id = current_setting('app.current_user_id')::bigint AND
file_version_id = ANY(ARRAY(
SELECT file_version.id fv_id FROM file_version
INNER JOIN "file" ON (file_version.file_id = "file".id)
INNER JOIN "file_user" ON ("file".id = "file_user".file_id AND file_user.deleted_at IS NULL)
WHERE file_user.user_id = current_setting('app.current_user_id')::bigint)
)
OR
true = ANY(
ARRAY(SELECT is_owner
FROM "group"
WHERE id = current_setting('app.current_user_group_id')::bigint
LIMIT 1
)
)
OR
file_version_id = ANY(
ARRAY(SELECT DISTINCT file_version.id fv_id FROM file_version
INNER JOIN "file" ON (file_version.file_id = "file".id)
INNER JOIN "sub_folder" ON (file.sub_folder_id = "sub_folder".id)
INNER JOIN "folder" ON (sub_folder.folder_id = "folder".id)
INNER JOIN "folder_group" ON (folder_group.folder_id = "folder".id AND folder_group.group_id = current_setting('app.current_user_group_id')::bigint)
INNER JOIN "project_user" ON (folder.project_id = "project_user".project_id AND "project_user".user_id = current_setting('app.current_user_id')::bigint)
WHERE folder.type = 'nda'
)
)
)
);`);
您可能正在运行早于 v12 的 PostgreSQL 版本,因为
pg_policy
自 v12 以来就有一个 TOAST 表,因此可以将超大的属性存储在行外。在此之前,您仅限于
pg_policy
行适合单个表块的策略。您的策略文本小于该值,但 PostgreSQL 存储了解析的查询树,它可能大于文本。升级到更高版本的 PostgreSQL 或使用多个
PERMISSIVE
策略,这些策略将与OR
.