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

Commit78a030a

Browse files
committed
Fix confusion about number of subplans in partitioned INSERT setup.
ExecInitModifyTable() thought there was a plan per partition, but no,there's only one. The problem had escaped detection so far because therewould only be visible misbehavior if there were a SubPlan (not an InitPlan)in the quals being duplicated for each partition. However, valgrinddetected a bogus memory access in test cases added by commit4f7a95b,and investigation of that led to discovery of the bug. The additionaltest case added here crashes without the patch.Patch by Amit Langote, test case by me.Discussion:https://postgr.es/m/10974.1497227727@sss.pgh.pa.us
1 parent791ef00 commit78a030a

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

‎src/backend/executor/nodeModifyTable.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,10 +1841,21 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
18411841
if (node->withCheckOptionLists!=NIL&&mtstate->mt_num_partitions>0)
18421842
{
18431843
List*wcoList;
1844+
PlanState*plan;
18441845

1845-
Assert(operation==CMD_INSERT);
1846-
resultRelInfo=mtstate->mt_partitions;
1846+
/*
1847+
* In case of INSERT on partitioned tables, there is only one plan.
1848+
* Likewise, there is only one WITH CHECK OPTIONS list, not one per
1849+
* partition. We make a copy of the WCO qual for each partition; note
1850+
* that, if there are SubPlans in there, they all end up attached to
1851+
* the one parent Plan node.
1852+
*/
1853+
Assert(operation==CMD_INSERT&&
1854+
list_length(node->withCheckOptionLists)==1&&
1855+
mtstate->mt_nplans==1);
18471856
wcoList=linitial(node->withCheckOptionLists);
1857+
plan=mtstate->mt_plans[0];
1858+
resultRelInfo=mtstate->mt_partitions;
18481859
for (i=0;i<mtstate->mt_num_partitions;i++)
18491860
{
18501861
Relationpartrel=resultRelInfo->ri_RelationDesc;
@@ -1858,9 +1869,9 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
18581869
partrel,rel);
18591870
foreach(ll,mapped_wcoList)
18601871
{
1861-
WithCheckOption*wco= (WithCheckOption*)lfirst(ll);
1862-
ExprState*wcoExpr=ExecInitQual((List*)wco->qual,
1863-
mtstate->mt_plans[i]);
1872+
WithCheckOption*wco=castNode(WithCheckOption,lfirst(ll));
1873+
ExprState*wcoExpr=ExecInitQual(castNode(List,wco->qual),
1874+
plan);
18641875

18651876
wcoExprs=lappend(wcoExprs,wcoExpr);
18661877
}

‎src/test/regress/expected/rowsecurity.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,14 @@ SELECT * FROM part_document ORDER by did;
13271327
ERROR: query would be affected by row-level security policy for table "part_document"
13281328
SELECT * FROM part_document_satire ORDER by did;
13291329
ERROR: query would be affected by row-level security policy for table "part_document_satire"
1330+
-- Check behavior with a policy that uses a SubPlan not an InitPlan.
1331+
SET SESSION AUTHORIZATION regress_rls_alice;
1332+
SET row_security TO ON;
1333+
CREATE POLICY pp3 ON part_document AS RESTRICTIVE
1334+
USING ((SELECT dlevel <= seclv FROM uaccount WHERE pguser = current_user));
1335+
SET SESSION AUTHORIZATION regress_rls_carol;
1336+
INSERT INTO part_document VALUES (100, 11, 5, 'regress_rls_carol', 'testing pp3'); -- fail
1337+
ERROR: new row violates row-level security policy "pp3" for table "part_document"
13301338
----- Dependencies -----
13311339
SET SESSION AUTHORIZATION regress_rls_alice;
13321340
SET row_security TO ON;

‎src/test/regress/sql/rowsecurity.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,15 @@ SET row_security TO OFF;
450450
SELECT*FROM part_documentORDER by did;
451451
SELECT*FROM part_document_satireORDER by did;
452452

453+
-- Check behavior with a policy that uses a SubPlan not an InitPlan.
454+
SET SESSION AUTHORIZATION regress_rls_alice;
455+
SET row_security TOON;
456+
CREATE POLICY pp3ON part_documentAS RESTRICTIVE
457+
USING ((SELECT dlevel<= seclvFROM uaccountWHERE pguser=current_user));
458+
459+
SET SESSION AUTHORIZATION regress_rls_carol;
460+
INSERT INTO part_documentVALUES (100,11,5,'regress_rls_carol','testing pp3');-- fail
461+
453462
----- Dependencies -----
454463
SET SESSION AUTHORIZATION regress_rls_alice;
455464
SET row_security TOON;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp