mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
Add a relkind field to RangeTblEntry to avoid some syscache lookups.
The recent additions for FDW support required checking foreign-table-ness in several places in the parse/plan chain. While it's not clear whether that would really result in a noticeable slowdown, it seems best to avoid any performance risk by keeping a copy of the relation's relkind in RangeTblEntry. That might have some other uses later, anyway. Per discussion.
This commit is contained in:
@@ -40,7 +40,6 @@
|
||||
#include "parser/parse_target.h"
|
||||
#include "parser/parsetree.h"
|
||||
#include "rewrite/rewriteManip.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/rel.h"
|
||||
|
||||
|
||||
@@ -2178,13 +2177,11 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc,
|
||||
{
|
||||
case RTE_RELATION:
|
||||
/* ignore foreign tables */
|
||||
if (get_rel_relkind(rte->relid) != RELKIND_FOREIGN_TABLE)
|
||||
{
|
||||
applyLockingClause(qry, i,
|
||||
lc->forUpdate, lc->noWait,
|
||||
pushedDown);
|
||||
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
|
||||
}
|
||||
if (rte->relkind == RELKIND_FOREIGN_TABLE)
|
||||
break;
|
||||
applyLockingClause(qry, i,
|
||||
lc->forUpdate, lc->noWait, pushedDown);
|
||||
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
|
||||
break;
|
||||
case RTE_SUBQUERY:
|
||||
applyLockingClause(qry, i,
|
||||
@@ -2231,11 +2228,11 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc,
|
||||
switch (rte->rtekind)
|
||||
{
|
||||
case RTE_RELATION:
|
||||
if (get_rel_relkind(rte->relid) == RELKIND_FOREIGN_TABLE)
|
||||
if (rte->relkind == RELKIND_FOREIGN_TABLE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE/SHARE cannot be used with foreign table \"%s\"",
|
||||
get_rel_name(rte->relid)),
|
||||
rte->eref->aliasname),
|
||||
parser_errposition(pstate, thisrel->location)));
|
||||
applyLockingClause(qry, i,
|
||||
lc->forUpdate, lc->noWait,
|
||||
@@ -2256,12 +2253,6 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc,
|
||||
errmsg("SELECT FOR UPDATE/SHARE cannot be applied to a join"),
|
||||
parser_errposition(pstate, thisrel->location)));
|
||||
break;
|
||||
case RTE_SPECIAL:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE/SHARE cannot be applied to NEW or OLD"),
|
||||
parser_errposition(pstate, thisrel->location)));
|
||||
break;
|
||||
case RTE_FUNCTION:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
|
@@ -894,6 +894,7 @@ addRangeTableEntry(ParseState *pstate,
|
||||
lockmode = isLockedRefname(pstate, refname) ? RowShareLock : AccessShareLock;
|
||||
rel = parserOpenTable(pstate, relation, lockmode);
|
||||
rte->relid = RelationGetRelid(rel);
|
||||
rte->relkind = rel->rd_rel->relkind;
|
||||
|
||||
/*
|
||||
* Build the list of effective column names using user-supplied aliases
|
||||
@@ -956,6 +957,7 @@ addRangeTableEntryForRelation(ParseState *pstate,
|
||||
rte->rtekind = RTE_RELATION;
|
||||
rte->alias = alias;
|
||||
rte->relid = RelationGetRelid(rel);
|
||||
rte->relkind = rel->rd_rel->relkind;
|
||||
|
||||
/*
|
||||
* Build the list of effective column names using user-supplied aliases
|
||||
|
@@ -305,7 +305,6 @@ markTargetListOrigin(ParseState *pstate, TargetEntry *tle,
|
||||
markTargetListOrigin(pstate, tle, aliasvar, netlevelsup);
|
||||
}
|
||||
break;
|
||||
case RTE_SPECIAL:
|
||||
case RTE_FUNCTION:
|
||||
case RTE_VALUES:
|
||||
/* not a simple relation, leave it unmarked */
|
||||
@@ -1357,7 +1356,6 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
|
||||
switch (rte->rtekind)
|
||||
{
|
||||
case RTE_RELATION:
|
||||
case RTE_SPECIAL:
|
||||
case RTE_VALUES:
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user