Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6d47021

Browse files
committed
Fix description and grouping of RangeTblEntry.inh
The inh field of RangeTblEntry was doubly confusingly documented. Some parts of the code insisted that it was only valid for RTE_RELATION entries, other parts said the field was valid for all entries. Neither was quite correct. More correctly, the field is valid for RTE_RELATION entries but is also used in the planner for RTE_SUBQUERY entries. So it makes more sense to group it with other fields that are primarily for RTE_RELATION but borrowed by RTE_SUBQUERY. (The exact position was chosen so that it is next to relkind for better struct packing, and next to relid, since relid and inh are sort of the input fields and the others are filled in later.) Also add documentation for the planner's use at the struct definition. Discussion: https://www.postgresql.org/message-id/6c1fbccc-85c8-40d3-b08b-4f47f2093711@eisentraut.org
1 parent 1f1d73a commit 6d47021

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

src/backend/nodes/outfuncs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
503503
{
504504
case RTE_RELATION:
505505
WRITE_OID_FIELD(relid);
506+
WRITE_BOOL_FIELD(inh);
506507
WRITE_CHAR_FIELD(relkind);
507508
WRITE_INT_FIELD(rellockmode);
508509
WRITE_UINT_FIELD(perminfoindex);
@@ -513,6 +514,7 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
513514
WRITE_BOOL_FIELD(security_barrier);
514515
/* we re-use these RELATION fields, too: */
515516
WRITE_OID_FIELD(relid);
517+
WRITE_BOOL_FIELD(inh);
516518
WRITE_CHAR_FIELD(relkind);
517519
WRITE_INT_FIELD(rellockmode);
518520
WRITE_UINT_FIELD(perminfoindex);
@@ -564,7 +566,6 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
564566
}
565567

566568
WRITE_BOOL_FIELD(lateral);
567-
WRITE_BOOL_FIELD(inh);
568569
WRITE_BOOL_FIELD(inFromCl);
569570
WRITE_NODE_FIELD(securityQuals);
570571
}

src/backend/nodes/queryjumblefuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ _jumbleRangeTblEntry(JumbleState *jstate, Node *node)
364364
{
365365
case RTE_RELATION:
366366
JUMBLE_FIELD(relid);
367-
JUMBLE_NODE(tablesample);
368367
JUMBLE_FIELD(inh);
368+
JUMBLE_NODE(tablesample);
369369
break;
370370
case RTE_SUBQUERY:
371371
JUMBLE_NODE(subquery);

src/backend/nodes/readfuncs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ _readRangeTblEntry(void)
357357
{
358358
case RTE_RELATION:
359359
READ_OID_FIELD(relid);
360+
READ_BOOL_FIELD(inh);
360361
READ_CHAR_FIELD(relkind);
361362
READ_INT_FIELD(rellockmode);
362363
READ_UINT_FIELD(perminfoindex);
@@ -367,6 +368,7 @@ _readRangeTblEntry(void)
367368
READ_BOOL_FIELD(security_barrier);
368369
/* we re-use these RELATION fields, too: */
369370
READ_OID_FIELD(relid);
371+
READ_BOOL_FIELD(inh);
370372
READ_CHAR_FIELD(relkind);
371373
READ_INT_FIELD(rellockmode);
372374
READ_UINT_FIELD(perminfoindex);
@@ -428,7 +430,6 @@ _readRangeTblEntry(void)
428430
}
429431

430432
READ_BOOL_FIELD(lateral);
431-
READ_BOOL_FIELD(inh);
432433
READ_BOOL_FIELD(inFromCl);
433434
READ_NODE_FIELD(securityQuals);
434435

src/backend/parser/parse_relation.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,7 @@ addRangeTableEntry(ParseState *pstate,
15001500
*/
15011501
rel = parserOpenTable(pstate, relation, lockmode);
15021502
rte->relid = RelationGetRelid(rel);
1503+
rte->inh = inh;
15031504
rte->relkind = rel->rd_rel->relkind;
15041505
rte->rellockmode = lockmode;
15051506

@@ -1517,7 +1518,6 @@ addRangeTableEntry(ParseState *pstate,
15171518
* which is the right thing for all except target tables.
15181519
*/
15191520
rte->lateral = false;
1520-
rte->inh = inh;
15211521
rte->inFromCl = inFromCl;
15221522

15231523
perminfo = addRTEPermissionInfo(&pstate->p_rteperminfos, rte);
@@ -1585,6 +1585,7 @@ addRangeTableEntryForRelation(ParseState *pstate,
15851585
rte->rtekind = RTE_RELATION;
15861586
rte->alias = alias;
15871587
rte->relid = RelationGetRelid(rel);
1588+
rte->inh = inh;
15881589
rte->relkind = rel->rd_rel->relkind;
15891590
rte->rellockmode = lockmode;
15901591

@@ -1602,7 +1603,6 @@ addRangeTableEntryForRelation(ParseState *pstate,
16021603
* which is the right thing for all except target tables.
16031604
*/
16041605
rte->lateral = false;
1605-
rte->inh = inh;
16061606
rte->inFromCl = inFromCl;
16071607

16081608
perminfo = addRTEPermissionInfo(&pstate->p_rteperminfos, rte);
@@ -1700,7 +1700,6 @@ addRangeTableEntryForSubquery(ParseState *pstate,
17001700
* addRTEPermissionInfo().
17011701
*/
17021702
rte->lateral = lateral;
1703-
rte->inh = false; /* never true for subqueries */
17041703
rte->inFromCl = inFromCl;
17051704

17061705
/*
@@ -2023,7 +2022,6 @@ addRangeTableEntryForFunction(ParseState *pstate,
20232022
* ExecCheckPermissions()), so no need to perform addRTEPermissionInfo().
20242023
*/
20252024
rte->lateral = lateral;
2026-
rte->inh = false; /* never true for functions */
20272025
rte->inFromCl = inFromCl;
20282026

20292027
/*
@@ -2108,7 +2106,6 @@ addRangeTableEntryForTableFunc(ParseState *pstate,
21082106
* ExecCheckPermissions()), so no need to perform addRTEPermissionInfo().
21092107
*/
21102108
rte->lateral = lateral;
2111-
rte->inh = false; /* never true for tablefunc RTEs */
21122109
rte->inFromCl = inFromCl;
21132110

21142111
/*
@@ -2189,7 +2186,6 @@ addRangeTableEntryForValues(ParseState *pstate,
21892186
* addRTEPermissionInfo().
21902187
*/
21912188
rte->lateral = lateral;
2192-
rte->inh = false; /* never true for values RTEs */
21932189
rte->inFromCl = inFromCl;
21942190

21952191
/*
@@ -2280,7 +2276,6 @@ addRangeTableEntryForJoin(ParseState *pstate,
22802276
* addRTEPermissionInfo().
22812277
*/
22822278
rte->lateral = false;
2283-
rte->inh = false; /* never true for joins */
22842279
rte->inFromCl = inFromCl;
22852280

22862281
/*
@@ -2425,7 +2420,6 @@ addRangeTableEntryForCTE(ParseState *pstate,
24252420
* addRTEPermissionInfo().
24262421
*/
24272422
rte->lateral = false;
2428-
rte->inh = false; /* never true for subqueries */
24292423
rte->inFromCl = inFromCl;
24302424

24312425
/*
@@ -2545,7 +2539,6 @@ addRangeTableEntryForENR(ParseState *pstate,
25452539
* addRTEPermissionInfo().
25462540
*/
25472541
rte->lateral = false;
2548-
rte->inh = false; /* never true for ENRs */
25492542
rte->inFromCl = inFromCl;
25502543

25512544
/*

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202403052
60+
#define CATALOG_VERSION_NO 202403071
6161

6262
#endif

src/include/nodes/parsenodes.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -989,10 +989,6 @@ typedef struct PartitionCmd
989989
* them from the joinaliasvars list, because that would affect the attnums
990990
* of Vars referencing the rest of the list.)
991991
*
992-
* inh is true for relation references that should be expanded to include
993-
* inheritance children, if the rel has any. This *must* be false for
994-
* RTEs other than RTE_RELATION entries.
995-
*
996992
* inFromCl marks those range variables that are listed in the FROM clause.
997993
* It's false for RTEs that are added to a query behind the scenes, such
998994
* as the NEW and OLD variables for a rule, or the subqueries of a UNION.
@@ -1041,6 +1037,13 @@ typedef struct RangeTblEntry
10411037
/*
10421038
* Fields valid for a plain relation RTE (else zero):
10431039
*
1040+
* inh is true for relation references that should be expanded to include
1041+
* inheritance children, if the rel has any. In the parser, this will
1042+
* only be true for RTE_RELATION entries. The planner also uses this
1043+
* field to mark RTE_SUBQUERY entries that contain UNION ALL queries that
1044+
* it has flattened into pulled-up subqueries (creating a structure much
1045+
* like the effects of inheritance).
1046+
*
10441047
* rellockmode is really LOCKMODE, but it's declared int to avoid having
10451048
* to include lock-related headers here. It must be RowExclusiveLock if
10461049
* the RTE is an INSERT/UPDATE/DELETE/MERGE target, else RowShareLock if
@@ -1070,6 +1073,7 @@ typedef struct RangeTblEntry
10701073
* tables to be invalidated if the underlying table is altered.
10711074
*/
10721075
Oid relid; /* OID of the relation */
1076+
bool inh; /* inheritance requested? */
10731077
char relkind; /* relation kind (see pg_class.relkind) */
10741078
int rellockmode; /* lock level that query requires on the rel */
10751079
Index perminfoindex; /* index of RTEPermissionInfo entry, or 0 */
@@ -1199,7 +1203,6 @@ typedef struct RangeTblEntry
11991203
Alias *alias; /* user-written alias clause, if any */
12001204
Alias *eref; /* expanded reference names */
12011205
bool lateral; /* subquery, function, or values is LATERAL? */
1202-
bool inh; /* inheritance requested? */
12031206
bool inFromCl; /* present in FROM clause? */
12041207
List *securityQuals; /* security barrier quals to apply, if any */
12051208
} RangeTblEntry;

0 commit comments

Comments
 (0)