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

Commit0f8cfaf

Browse files
committed
Retain relkind too in RTE_SUBQUERY entries for views.
47bb9db modified the ApplyRetrieveRule()'s conversion of a view'soriginal RTE_RELATION entry into an RTE_SUBQUERY one to retain relid,rellockmode, and perminfoindex so that the executor can lock the viewand check its permissions. It seems better to also retainrelkind for cross-checking that the exception of anRTE_SUBQUERY entry being allowed to carry relation details onlyapplies to views, so do so.Bump catversion because this changes the output format ofRTE_SUBQUERY RTEs.Suggested-by: David Steele <david@pgmasters.net>Reviewed-by: David Steele <david@pgmasters.net>Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>Discussion:https://postgr.es/m/3953179e-9540-e5d1-a743-4bef368785b0%40pgmasters.net
1 parentae66716 commit0f8cfaf

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

‎src/backend/executor/execMain.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,15 @@ ExecCheckPermissions(List *rangeTable, List *rteperminfos,
595595
if (rte->perminfoindex!=0)
596596
{
597597
/* Sanity checks */
598+
599+
/*
600+
* Only relation RTEs and subquery RTEs that were once relation
601+
* RTEs (views) have their perminfoindex set.
602+
*/
603+
Assert(rte->rtekind==RTE_RELATION||
604+
(rte->rtekind==RTE_SUBQUERY&&
605+
rte->relkind==RELKIND_VIEW));
606+
598607
(void)getRTEPermissionInfo(rteperminfos,rte);
599608
/* Many-to-one mapping not allowed */
600609
Assert(!bms_is_member(rte->perminfoindex,indexset));

‎src/backend/nodes/outfuncs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
513513
WRITE_BOOL_FIELD(security_barrier);
514514
/* we re-use these RELATION fields, too: */
515515
WRITE_OID_FIELD(relid);
516+
WRITE_CHAR_FIELD(relkind);
516517
WRITE_INT_FIELD(rellockmode);
517518
WRITE_UINT_FIELD(perminfoindex);
518519
break;

‎src/backend/nodes/readfuncs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ _readRangeTblEntry(void)
503503
READ_BOOL_FIELD(security_barrier);
504504
/* we re-use these RELATION fields, too: */
505505
READ_OID_FIELD(relid);
506+
READ_CHAR_FIELD(relkind);
506507
READ_INT_FIELD(rellockmode);
507508
READ_UINT_FIELD(perminfoindex);
508509
break;

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,11 +1851,10 @@ ApplyRetrieveRule(Query *parsetree,
18511851

18521852
/*
18531853
* Clear fields that should not be set in a subquery RTE. Note that we
1854-
* leave the relid, rellockmode, and perminfoindex fields set, so that the
1855-
* view relation can be appropriately locked before execution and its
1856-
* permissions checked.
1854+
* leave the relid,relkind,rellockmode, and perminfoindex fields set, so
1855+
*that theview relation can be appropriately locked before execution and
1856+
*itspermissions checked.
18571857
*/
1858-
rte->relkind=0;
18591858
rte->tablesample=NULL;
18601859
rte->inh= false;/* must not be set for a subquery */
18611860

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/*yyyymmddN */
60-
#defineCATALOG_VERSION_NO202305211
60+
#defineCATALOG_VERSION_NO202306141
6161

6262
#endif

‎src/include/nodes/parsenodes.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,13 +1056,13 @@ typedef struct RangeTblEntry
10561056
* this RTE in the containing struct's list of same; 0 if permissions need
10571057
* not be checked for this RTE.
10581058
*
1059-
* As a special case, relid, rellockmode, and perminfoindex can also be
1060-
* set (nonzero) in an RTE_SUBQUERY RTE. This occurs when we convert an
1061-
* RTE_RELATION RTE naming a view into an RTE_SUBQUERY containing the
1062-
* view's query. We still need to perform run-time locking and permission
1063-
* checks on the view, even though it's not directly used in the query
1064-
* anymore, and the most expedient way to do that is to retain these
1065-
* fields from the old state of the RTE.
1059+
* As a special case, relid,relkind,rellockmode, and perminfoindex can
1060+
*also beset (nonzero) in an RTE_SUBQUERY RTE. This occurs when we
1061+
*convert anRTE_RELATION RTE naming a view into an RTE_SUBQUERY
1062+
*containing theview's query. We still need to perform run-time locking
1063+
*and permissionchecks on the view, even though it's not directly used
1064+
*in the queryanymore, and the most expedient way to do that is to
1065+
*retain thesefields from the old state of the RTE.
10661066
*
10671067
* As a special case, RTE_NAMEDTUPLESTORE can also set relid to indicate
10681068
* that the tuple format of the tuplestore is the same as the referenced

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp