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

Commitca08ea5

Browse files
committed
Fix usage of whole-row variables in WCO and RLS policy expressions.
Since WITH CHECK OPTION was introduced, ExecInitModifyTable hasinitialized WCO expressions with the wrong plan node as parent -- that is,it passed its input subplan not the ModifyTable node itself. Up to nowwe thought this was harmless, but bug #16006 from Vinay Banakar shows it'snot: if the input node is a SubqueryScan then ExecInitWholeRowVar can getconfused into doing the wrong thing. (The fact that ExecInitWholeRowVarcontains such logic is certainly a horrid kluge that doesn't deserve tolive, but figuring out another way to do that is a task for some other day.)Andres had already noticed the wrong-parent mistake and fixed it in commit148e632, but not being aware of any user-visible consequences, he quitereasonably didn't back-patch. This patch is simply a back-patch of148e632, plus addition of a test case based on bug #16006. I also addedthe test case to v12/HEAD, even though the bug is already fixed there.Back-patch to all supported branches. 9.4 lacks RLS policies so thenew test case doesn't work there, but I'm pretty sure a test could bedevised based on using a whole-row Var in a plain WITH CHECK OPTIONcondition. (I lack the cycles to do so myself, though.)Andres Freund and Tom LaneDiscussion:https://postgr.es/m/16006-99290d2e4642cbd5@postgresql.orgDiscussion:https://postgr.es/m/20181205225213.hiwa3kgoxeybqcqv@alap3.anarazel.de
1 parent1f705e6 commitca08ea5

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

‎src/backend/executor/nodeModifyTable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
11981198
{
11991199
WithCheckOption*wco= (WithCheckOption*)lfirst(ll);
12001200
ExprState*wcoExpr=ExecInitExpr((Expr*)wco->qual,
1201-
mtstate->mt_plans[i]);
1201+
&mtstate->ps);
12021202

12031203
wcoExprs=lappend(wcoExprs,wcoExpr);
12041204
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,31 +1604,31 @@ UPDATE rw_view1 SET a = a + 5; -- should fail
16041604
ERROR: new row violates WITH CHECK OPTION for view "rw_view1"
16051605
DETAIL: Failing row contains (15).
16061606
EXPLAIN (costs off) INSERT INTO rw_view1 VALUES (5);
1607-
QUERY PLAN
1608-
---------------------------------------------------------------
1607+
QUERY PLAN
1608+
---------------------------------------------------------
16091609
Insert on base_tbl b
16101610
-> Result
1611-
SubPlan 1
1612-
-> Index Only Scan using ref_tbl_pkey on ref_tbl r
1613-
Index Cond: (a = b.a)
1614-
SubPlan 2
1615-
-> Seq Scan on ref_tbl r_1
1611+
SubPlan 1
1612+
-> Index Only Scan using ref_tbl_pkey on ref_tbl r
1613+
Index Cond: (a = b.a)
1614+
SubPlan 2
1615+
-> Seq Scan on ref_tbl r_1
16161616
(7 rows)
16171617

16181618
EXPLAIN (costs off) UPDATE rw_view1 SET a = a + 5;
1619-
QUERY PLAN
1620-
-----------------------------------------------------------------
1619+
QUERY PLAN
1620+
-----------------------------------------------------------
16211621
Update on base_tbl b
16221622
-> Hash Semi Join
16231623
Hash Cond: (b.a = r.a)
16241624
-> Seq Scan on base_tbl b
16251625
-> Hash
16261626
-> Seq Scan on ref_tbl r
1627-
SubPlan 1
1628-
-> Index Only Scan using ref_tbl_pkey on ref_tbl r_1
1629-
Index Cond: (a = b.a)
1630-
SubPlan 2
1631-
-> Seq Scan on ref_tbl r_2
1627+
SubPlan 1
1628+
-> Index Only Scan using ref_tbl_pkey on ref_tbl r_1
1629+
Index Cond: (a = b.a)
1630+
SubPlan 2
1631+
-> Seq Scan on ref_tbl r_2
16321632
(11 rows)
16331633

16341634
DROP TABLE base_tbl, ref_tbl CASCADE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp