Skip to content

Commit 3a33d56

Browse files
committed
Revert "Fix permission tests for views/tables proven empty by constraint exclusion."
This reverts commit 15b0421. Per complaint from Robert Haas, that patch caused crashes on appendrel cases, and it didn't fix all forms of the problem anyway. Consensus is we'll leave this problem alone in the back branches, at least for now.
1 parent edc8e85 commit 3a33d56

File tree

4 files changed

+15
-52
lines changed

4 files changed

+15
-52
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,7 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
11291129
/*
11301130
* It's possible that constraint exclusion proved the subquery empty. If
11311131
* so, it's convenient to turn it back into a dummy path so that we will
1132-
* recognize appropriate optimizations at this query level. (But see
1133-
* create_append_plan in createplan.c, which has to reverse this
1134-
* substitution.)
1132+
* recognize appropriate optimizations at this level.
11351133
*/
11361134
if (is_dummy_plan(rel->subplan))
11371135
{

src/backend/optimizer/plan/createplan.c

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -664,63 +664,37 @@ static Plan *
664664
create_append_plan(PlannerInfo *root, AppendPath *best_path)
665665
{
666666
Append *plan;
667-
RelOptInfo *rel = best_path->path.parent;
668-
List *tlist = build_relation_tlist(rel);
667+
List *tlist = build_relation_tlist(best_path->path.parent);
669668
List *subplans = NIL;
670669
ListCell *subpaths;
671670

672671
/*
673-
* The subpaths list could be empty, if every child was proven empty by
674-
* constraint exclusion. In that case generate a dummy plan that returns
675-
* no rows.
672+
* It is possible for the subplans list to contain only one entry, or even
673+
* no entries. Handle these cases specially.
676674
*
677-
* Note that an AppendPath with no members is also generated in certain
678-
* cases where there was no appending construct at all, but we know the
679-
* relation is empty (see set_dummy_rel_pathlist).
675+
* XXX ideally, if there's just one entry, we'd not bother to generate an
676+
* Append node but just return the single child. At the moment this does
677+
* not work because the varno of the child scan plan won't match the
678+
* parent-rel Vars it'll be asked to emit.
680679
*/
681680
if (best_path->subpaths == NIL)
682681
{
683-
/*
684-
* If this is a dummy path for a subquery, we have to wrap the
685-
* subquery's original plan in a SubqueryScan so that setrefs.c will
686-
* do the right things. (In particular, it must pull up the
687-
* subquery's rangetable so that the executor will apply permissions
688-
* checks to those rels at runtime.)
689-
*/
690-
if (rel->rtekind == RTE_SUBQUERY)
691-
{
692-
Assert(is_dummy_plan(rel->subplan));
693-
return (Plan *) make_subqueryscan(tlist,
694-
NIL,
695-
rel->relid,
696-
rel->subplan);
697-
}
698-
else
699-
{
700-
/* Generate a Result plan with constant-FALSE gating qual */
701-
return (Plan *) make_result(root,
702-
tlist,
703-
(Node *) list_make1(makeBoolConst(false,
704-
false)),
705-
NULL);
706-
}
682+
/* Generate a Result plan with constant-FALSE gating qual */
683+
return (Plan *) make_result(root,
684+
tlist,
685+
(Node *) list_make1(makeBoolConst(false,
686+
false)),
687+
NULL);
707688
}
708689

709-
/* Build the plan for each child */
690+
/* Normal case with multiple subpaths */
710691
foreach(subpaths, best_path->subpaths)
711692
{
712693
Path *subpath = (Path *) lfirst(subpaths);
713694

714695
subplans = lappend(subplans, create_plan_recurse(root, subpath));
715696
}
716697

717-
/*
718-
* XXX ideally, if there's just one child, we'd not bother to generate an
719-
* Append node but just return the single child. At the moment this does
720-
* not work because the varno of the child scan plan won't match the
721-
* parent-rel Vars it'll be asked to emit.
722-
*/
723-
724698
plan = make_append(subplans, tlist);
725699

726700
return (Plan *) plan;

src/test/regress/expected/privileges.out

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ CREATE VIEW atestv1 AS SELECT * FROM atest1; -- ok
198198
/* The next *should* fail, but it's not implemented that way yet. */
199199
CREATE VIEW atestv2 AS SELECT * FROM atest2;
200200
CREATE VIEW atestv3 AS SELECT * FROM atest3; -- ok
201-
/* Empty view is a corner case that failed in 9.2. */
202-
CREATE VIEW atestv0 AS SELECT 0 as x WHERE false; -- ok
203201
SELECT * FROM atestv1; -- ok
204202
a | b
205203
---+-----
@@ -226,8 +224,6 @@ SELECT * FROM atestv3; -- ok
226224
-----+-----+-------
227225
(0 rows)
228226

229-
SELECT * FROM atestv0; -- fail
230-
ERROR: permission denied for relation atestv0
231227
CREATE VIEW atestv4 AS SELECT * FROM atestv3; -- nested view
232228
SELECT * FROM atestv4; -- ok
233229
one | two | three
@@ -1390,7 +1386,6 @@ drop table dep_priv_test;
13901386
drop sequence x_seq;
13911387
DROP FUNCTION testfunc2(int);
13921388
DROP FUNCTION testfunc4(boolean);
1393-
DROP VIEW atestv0;
13941389
DROP VIEW atestv1;
13951390
DROP VIEW atestv2;
13961391
-- this should cascade to drop atestv4

src/test/regress/sql/privileges.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ CREATE VIEW atestv1 AS SELECT * FROM atest1; -- ok
147147
/* The next *should* fail, but it's not implemented that way yet. */
148148
CREATE VIEW atestv2 AS SELECT * FROM atest2;
149149
CREATE VIEW atestv3 AS SELECT * FROM atest3; -- ok
150-
/* Empty view is a corner case that failed in 9.2. */
151-
CREATE VIEW atestv0 AS SELECT 0 as x WHERE false; -- ok
152150

153151
SELECT * FROM atestv1; -- ok
154152
SELECT * FROM atestv2; -- fail
@@ -160,7 +158,6 @@ SET SESSION AUTHORIZATION regressuser4;
160158
SELECT * FROM atestv1; -- ok
161159
SELECT * FROM atestv2; -- fail
162160
SELECT * FROM atestv3; -- ok
163-
SELECT * FROM atestv0; -- fail
164161

165162
CREATE VIEW atestv4 AS SELECT * FROM atestv3; -- nested view
166163
SELECT * FROM atestv4; -- ok
@@ -831,7 +828,6 @@ drop sequence x_seq;
831828
DROP FUNCTION testfunc2(int);
832829
DROP FUNCTION testfunc4(boolean);
833830

834-
DROP VIEW atestv0;
835831
DROP VIEW atestv1;
836832
DROP VIEW atestv2;
837833
-- this should cascade to drop atestv4

0 commit comments

Comments
 (0)