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

Commitd1423c5

Browse files
committed
Correctly update hasSubLinks while mutating a rule action.
rewriteRuleAction neglected to check for SubLink nodes in thesecurityQuals of range table entries. This could lead to failingto convert such a SubLink to a SubPlan, resulting in assertioncrashes or weird errors later in planning.In passing, fix some poor coding in rewriteTargetView:we should not pass the source parsetree's hasSubLinksfield to ReplaceVarsFromTargetList's outer_hasSubLinks.ReplaceVarsFromTargetList knows enough to ignore thatwhen a Query node is passed, but it's still confusingand bad precedent: if we did try to update that flagwe'd be updating a stale copy of the parsetree.Per bug #17972 from Alexander Lakhin. This has been broken sincewe added RangeTblEntry.securityQuals (although the presented testcase only fails back to215b43c), so back-patch all the way.Discussion:https://postgr.es/m/17972-f422c094237847d0@postgresql.org
1 parent5eaa05f commitd1423c5

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ rewriteRuleAction(Query *parsetree,
477477
/* other RTE types don't contain bare expressions */
478478
break;
479479
}
480+
sub_action->hasSubLinks |=
481+
checkExprHasSubLink((Node*)rte->securityQuals);
480482
if (sub_action->hasSubLinks)
481483
break;/* no need to keep scanning rtable */
482484
}
@@ -3338,7 +3340,7 @@ rewriteTargetView(Query *parsetree, Relation view)
33383340
view_targetlist,
33393341
REPLACEVARS_REPORT_ERROR,
33403342
0,
3341-
&parsetree->hasSubLinks);
3343+
NULL);
33423344

33433345
/*
33443346
* Update all other RTI references in the query that point to the view

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,6 +2601,38 @@ DROP VIEW v1;
26012601
DROP TABLE t2;
26022602
DROP TABLE t1;
26032603
--
2604+
-- Test sub-select in nested security barrier views, per bug #17972
2605+
--
2606+
CREATE TABLE t1 (a int);
2607+
CREATE VIEW v1 WITH (security_barrier = true) AS
2608+
SELECT * FROM t1;
2609+
CREATE RULE v1_upd_rule AS ON UPDATE TO v1 DO INSTEAD
2610+
UPDATE t1 SET a = NEW.a WHERE a = OLD.a;
2611+
CREATE VIEW v2 WITH (security_barrier = true) AS
2612+
SELECT * FROM v1 WHERE EXISTS (SELECT 1);
2613+
EXPLAIN (COSTS OFF) UPDATE v2 SET a = 1;
2614+
QUERY PLAN
2615+
---------------------------------------------------
2616+
Update on t1
2617+
InitPlan 1 (returns $0)
2618+
-> Result
2619+
-> Merge Join
2620+
Merge Cond: (t1.a = v1.a)
2621+
-> Sort
2622+
Sort Key: t1.a
2623+
-> Seq Scan on t1
2624+
-> Sort
2625+
Sort Key: v1.a
2626+
-> Subquery Scan on v1
2627+
-> Result
2628+
One-Time Filter: $0
2629+
-> Seq Scan on t1 t1_1
2630+
(14 rows)
2631+
2632+
DROP VIEW v2;
2633+
DROP VIEW v1;
2634+
DROP TABLE t1;
2635+
--
26042636
-- Test CREATE OR REPLACE VIEW turning a non-updatable view into an
26052637
-- auto-updatable view and adding check options in a single step
26062638
--

‎src/test/regress/sql/updatable_views.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,23 @@ DROP VIEW v1;
12431243
DROPTABLE t2;
12441244
DROPTABLE t1;
12451245

1246+
--
1247+
-- Test sub-select in nested security barrier views, per bug #17972
1248+
--
1249+
CREATETABLEt1 (aint);
1250+
CREATEVIEWv1 WITH (security_barrier= true)AS
1251+
SELECT*FROM t1;
1252+
CREATERULEv1_upd_ruleASONUPDATE TO v1 DO INSTEAD
1253+
UPDATE t1SET a=NEW.aWHERE a=OLD.a;
1254+
CREATEVIEWv2 WITH (security_barrier= true)AS
1255+
SELECT*FROM v1WHERE EXISTS (SELECT1);
1256+
1257+
EXPLAIN (COSTS OFF)UPDATE v2SET a=1;
1258+
1259+
DROPVIEW v2;
1260+
DROPVIEW v1;
1261+
DROPTABLE t1;
1262+
12461263
--
12471264
-- Test CREATE OR REPLACE VIEW turning a non-updatable view into an
12481265
-- auto-updatable view and adding check options in a single step

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp