aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/dependency.c1
-rw-r--r--src/backend/commands/copy.c1
-rw-r--r--src/backend/nodes/copyfuncs.c1
-rw-r--r--src/backend/nodes/equalfuncs.c1
-rw-r--r--src/backend/nodes/nodeFuncs.c2
-rw-r--r--src/backend/nodes/outfuncs.c2
-rw-r--r--src/backend/nodes/print.c8
-rw-r--r--src/backend/nodes/readfuncs.c2
-rw-r--r--src/backend/optimizer/path/allpaths.c67
-rw-r--r--src/backend/optimizer/plan/planner.c3
-rw-r--r--src/backend/parser/analyze.c23
-rw-r--r--src/backend/parser/parse_relation.c2
-rw-r--r--src/backend/parser/parse_target.c2
-rw-r--r--src/backend/rewrite/rewriteHandler.c9
-rw-r--r--src/backend/utils/adt/ri_triggers.c2
-rw-r--r--src/backend/utils/adt/ruleutils.c7
16 files changed, 70 insertions, 63 deletions
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index 1679776f019..bce0e076837 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1284,6 +1284,7 @@ recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
rte.type = T_RangeTblEntry;
rte.rtekind = RTE_RELATION;
rte.relid = relId;
+ rte.relkind = RELKIND_RELATION; /* no need for exactness here */
context.rtables = list_make1(list_make1(&rte));
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 44f568f3964..3c504e96be2 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -763,6 +763,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
rte = makeNode(RangeTblEntry);
rte->rtekind = RTE_RELATION;
rte->relid = RelationGetRelid(rel);
+ rte->relkind = rel->rd_rel->relkind;
rte->requiredPerms = required_access;
tupDesc = RelationGetDescr(rel);
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 1ba746bb4d8..04763d44ebb 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -1927,6 +1927,7 @@ _copyRangeTblEntry(RangeTblEntry *from)
COPY_SCALAR_FIELD(rtekind);
COPY_SCALAR_FIELD(relid);
+ COPY_SCALAR_FIELD(relkind);
COPY_NODE_FIELD(subquery);
COPY_SCALAR_FIELD(jointype);
COPY_NODE_FIELD(joinaliasvars);
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index dd332f19f00..c896f49ff6f 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -2286,6 +2286,7 @@ _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
{
COMPARE_SCALAR_FIELD(rtekind);
COMPARE_SCALAR_FIELD(relid);
+ COMPARE_SCALAR_FIELD(relkind);
COMPARE_NODE_FIELD(subquery);
COMPARE_SCALAR_FIELD(jointype);
COMPARE_NODE_FIELD(joinaliasvars);
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c
index 8a23047d382..d4b92429171 100644
--- a/src/backend/nodes/nodeFuncs.c
+++ b/src/backend/nodes/nodeFuncs.c
@@ -1671,7 +1671,6 @@ range_table_walker(List *rtable,
switch (rte->rtekind)
{
case RTE_RELATION:
- case RTE_SPECIAL:
case RTE_CTE:
/* nothing to do */
break;
@@ -2374,7 +2373,6 @@ range_table_mutator(List *rtable,
switch (rte->rtekind)
{
case RTE_RELATION:
- case RTE_SPECIAL:
case RTE_CTE:
/* we don't bother to copy eref, aliases, etc; OK? */
break;
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 10f630e27f5..706b2425cf2 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -2275,8 +2275,8 @@ _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
switch (node->rtekind)
{
case RTE_RELATION:
- case RTE_SPECIAL:
WRITE_OID_FIELD(relid);
+ WRITE_CHAR_FIELD(relkind);
break;
case RTE_SUBQUERY:
WRITE_NODE_FIELD(subquery);
diff --git a/src/backend/nodes/print.c b/src/backend/nodes/print.c
index 14487f25a10..cd119dbabb8 100644
--- a/src/backend/nodes/print.c
+++ b/src/backend/nodes/print.c
@@ -265,8 +265,8 @@ print_rt(List *rtable)
switch (rte->rtekind)
{
case RTE_RELATION:
- printf("%d\t%s\t%u",
- i, rte->eref->aliasname, rte->relid);
+ printf("%d\t%s\t%u\t%c",
+ i, rte->eref->aliasname, rte->relid, rte->relkind);
break;
case RTE_SUBQUERY:
printf("%d\t%s\t[subquery]",
@@ -276,10 +276,6 @@ print_rt(List *rtable)
printf("%d\t%s\t[join]",
i, rte->eref->aliasname);
break;
- case RTE_SPECIAL:
- printf("%d\t%s\t[special]",
- i, rte->eref->aliasname);
- break;
case RTE_FUNCTION:
printf("%d\t%s\t[rangefunction]",
i, rte->eref->aliasname);
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index b007caeee3e..c76884e991f 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -1171,8 +1171,8 @@ _readRangeTblEntry(void)
switch (local_node->rtekind)
{
case RTE_RELATION:
- case RTE_SPECIAL:
READ_OID_FIELD(relid);
+ READ_CHAR_FIELD(relkind);
break;
case RTE_SUBQUERY:
READ_NODE_FIELD(subquery);
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index c835a954ed9..dc2a23bb273 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -176,41 +176,44 @@ set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
/* It's an "append relation", process accordingly */
set_append_rel_pathlist(root, rel, rti, rte);
}
- else if (rel->rtekind == RTE_SUBQUERY)
- {
- /* Subquery --- generate a separate plan for it */
- set_subquery_pathlist(root, rel, rti, rte);
- }
- else if (rel->rtekind == RTE_FUNCTION)
- {
- /* RangeFunction --- generate a suitable path for it */
- set_function_pathlist(root, rel, rte);
- }
- else if (rel->rtekind == RTE_VALUES)
- {
- /* Values list --- generate a suitable path for it */
- set_values_pathlist(root, rel, rte);
- }
- else if (rel->rtekind == RTE_CTE)
- {
- /* CTE reference --- generate a suitable path for it */
- if (rte->self_reference)
- set_worktable_pathlist(root, rel, rte);
- else
- set_cte_pathlist(root, rel, rte);
- }
else
{
- Assert(rel->rtekind == RTE_RELATION);
- if (get_rel_relkind(rte->relid) == RELKIND_FOREIGN_TABLE)
- {
- /* Foreign table */
- set_foreign_pathlist(root, rel, rte);
- }
- else
+ switch (rel->rtekind)
{
- /* Plain relation */
- set_plain_rel_pathlist(root, rel, rte);
+ case RTE_RELATION:
+ if (rte->relkind == RELKIND_FOREIGN_TABLE)
+ {
+ /* Foreign table */
+ set_foreign_pathlist(root, rel, rte);
+ }
+ else
+ {
+ /* Plain relation */
+ set_plain_rel_pathlist(root, rel, rte);
+ }
+ break;
+ case RTE_SUBQUERY:
+ /* Subquery --- generate a separate plan for it */
+ set_subquery_pathlist(root, rel, rti, rte);
+ break;
+ case RTE_FUNCTION:
+ /* RangeFunction --- generate a suitable path for it */
+ set_function_pathlist(root, rel, rte);
+ break;
+ case RTE_VALUES:
+ /* Values list --- generate a suitable path for it */
+ set_values_pathlist(root, rel, rte);
+ break;
+ case RTE_CTE:
+ /* CTE reference --- generate a suitable path for it */
+ if (rte->self_reference)
+ set_worktable_pathlist(root, rel, rte);
+ else
+ set_cte_pathlist(root, rel, rte);
+ break;
+ default:
+ elog(ERROR, "unexpected rtekind: %d", (int) rel->rtekind);
+ break;
}
}
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index b73b872b312..ee09673051f 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -1915,7 +1915,7 @@ preprocess_rowmarks(PlannerInfo *root)
newrc->rowmarkId = ++(root->glob->lastRowMarkId);
/* real tables support REFERENCE, anything else needs COPY */
if (rte->rtekind == RTE_RELATION &&
- get_rel_relkind(rte->relid) != RELKIND_FOREIGN_TABLE)
+ rte->relkind != RELKIND_FOREIGN_TABLE)
newrc->markType = ROW_MARK_REFERENCE;
else
newrc->markType = ROW_MARK_COPY;
@@ -3078,6 +3078,7 @@ plan_cluster_use_sort(Oid tableOid, Oid indexOid)
rte = makeNode(RangeTblEntry);
rte->rtekind = RTE_RELATION;
rte->relid = tableOid;
+ rte->relkind = RELKIND_RELATION;
rte->inh = false;
rte->inFromCl = true;
query->rtable = list_make1(rte);
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index c7a7a230767..7f28d9df4f5 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -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),
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index 497c726f314..033ed411fde 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -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
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index a0761da875b..e9ace37e2d8 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -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:
/*
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index 3a50642fce8..c0d25b15c60 100644
--- a/src/backend/rewrite/rewriteHandler.c
+++ b/src/backend/rewrite/rewriteHandler.c
@@ -144,6 +144,13 @@ AcquireRewriteLocks(Query *parsetree, bool forUpdatePushedDown)
lockmode = AccessShareLock;
rel = heap_open(rte->relid, lockmode);
+
+ /*
+ * While we have the relation open, update the RTE's relkind,
+ * just in case it changed since this rule was made.
+ */
+ rte->relkind = rel->rd_rel->relkind;
+
heap_close(rel, NoLock);
break;
@@ -1393,7 +1400,7 @@ markQueryForLocking(Query *qry, Node *jtnode,
if (rte->rtekind == RTE_RELATION)
{
/* ignore foreign tables */
- if (get_rel_relkind(rte->relid) != RELKIND_FOREIGN_TABLE)
+ if (rte->relkind != RELKIND_FOREIGN_TABLE)
{
applyLockingClause(qry, rti, forUpdate, noWait, pushedDown);
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c
index 5ef1563d1c9..591d2eb16b0 100644
--- a/src/backend/utils/adt/ri_triggers.c
+++ b/src/backend/utils/adt/ri_triggers.c
@@ -2651,11 +2651,13 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
pkrte = makeNode(RangeTblEntry);
pkrte->rtekind = RTE_RELATION;
pkrte->relid = RelationGetRelid(pk_rel);
+ pkrte->relkind = pk_rel->rd_rel->relkind;
pkrte->requiredPerms = ACL_SELECT;
fkrte = makeNode(RangeTblEntry);
fkrte->rtekind = RTE_RELATION;
fkrte->relid = RelationGetRelid(fk_rel);
+ fkrte->relkind = fk_rel->rd_rel->relkind;
fkrte->requiredPerms = ACL_SELECT;
for (i = 0; i < riinfo.nkeys; i++)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index cd64235438e..d9b359465a2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -628,6 +628,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
if (!isnull)
{
Node *qual;
+ char relkind;
deparse_context context;
deparse_namespace dpns;
RangeTblEntry *oldrte;
@@ -637,10 +638,13 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
qual = stringToNode(TextDatumGetCString(value));
+ relkind = get_rel_relkind(trigrec->tgrelid);
+
/* Build minimal OLD and NEW RTEs for the rel */
oldrte = makeNode(RangeTblEntry);
oldrte->rtekind = RTE_RELATION;
oldrte->relid = trigrec->tgrelid;
+ oldrte->relkind = relkind;
oldrte->eref = makeAlias("old", NIL);
oldrte->inh = false;
oldrte->inFromCl = true;
@@ -648,6 +652,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
newrte = makeNode(RangeTblEntry);
newrte->rtekind = RTE_RELATION;
newrte->relid = trigrec->tgrelid;
+ newrte->relkind = relkind;
newrte->eref = makeAlias("new", NIL);
newrte->inh = false;
newrte->inFromCl = true;
@@ -2125,6 +2130,7 @@ deparse_context_for(const char *aliasname, Oid relid)
rte = makeNode(RangeTblEntry);
rte->rtekind = RTE_RELATION;
rte->relid = relid;
+ rte->relkind = RELKIND_RELATION; /* no need for exactness here */
rte->eref = makeAlias(aliasname, NIL);
rte->inh = false;
rte->inFromCl = true;
@@ -4004,7 +4010,6 @@ get_name_for_var_field(Var *var, int fieldno,
switch (rte->rtekind)
{
case RTE_RELATION:
- case RTE_SPECIAL:
case RTE_VALUES:
/*