perf(rls): wrap current_setting() in org-isolation policies so it evaluates once per statement (InitPlan)
This commit is contained in:
parent
938a7da095
commit
5eff502fa1
1 changed files with 2 additions and 2 deletions
|
|
@ -229,14 +229,14 @@ Each table has two policies:
|
|||
```sql
|
||||
CREATE POLICY org_isolation ON "lead"
|
||||
FOR ALL
|
||||
USING (org_id::text = NULLIF(current_setting('app.current_org', true), ''));
|
||||
USING (org_id::text = (select NULLIF(current_setting('app.current_org', true), '')));
|
||||
```
|
||||
|
||||
2. **Insert Check Policy**:
|
||||
```sql
|
||||
CREATE POLICY org_insert_check ON "lead"
|
||||
FOR INSERT
|
||||
WITH CHECK (org_id::text = NULLIF(current_setting('app.current_org', true), ''));
|
||||
WITH CHECK (org_id::text = (select NULLIF(current_setting('app.current_org', true), '')));
|
||||
```
|
||||
|
||||
The `NULLIF(..., '')` ensures **no rows are returned** when context is not set (fail-safe).
|
||||
|
|
|
|||
Loading…
Reference in a new issue