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));
rte = makeNode(RangeTblEntry);
rte->rtekind = RTE_RELATION;
rte->relid = RelationGetRelid(rel);
+ rte->relkind = rel->rd_rel->relkind;
rte->requiredPerms = required_access;
tupDesc = RelationGetDescr(rel);
COPY_SCALAR_FIELD(rtekind);
COPY_SCALAR_FIELD(relid);
+ COPY_SCALAR_FIELD(relkind);
COPY_NODE_FIELD(subquery);
COPY_SCALAR_FIELD(jointype);
COPY_NODE_FIELD(joinaliasvars);
{
COMPARE_SCALAR_FIELD(rtekind);
COMPARE_SCALAR_FIELD(relid);
+ COMPARE_SCALAR_FIELD(relkind);
COMPARE_NODE_FIELD(subquery);
COMPARE_SCALAR_FIELD(jointype);
COMPARE_NODE_FIELD(joinaliasvars);
switch (rte->rtekind)
{
case RTE_RELATION:
- case RTE_SPECIAL:
case RTE_CTE:
/* nothing to do */
break;
switch (rte->rtekind)
{
case RTE_RELATION:
- case RTE_SPECIAL:
case RTE_CTE:
/* we don't bother to copy eref, aliases, etc; OK? */
break;
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);
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]",
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);
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);
/* 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;
}
}
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;
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);
#include "parser/parse_target.h"
#include "parser/parsetree.h"
#include "rewrite/rewriteManip.h"
-#include "utils/lsyscache.h"
#include "utils/rel.h"
{
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,
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,
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),
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
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
markTargetListOrigin(pstate, tle, aliasvar, netlevelsup);
}
break;
- case RTE_SPECIAL:
case RTE_FUNCTION:
case RTE_VALUES:
/* not a simple relation, leave it unmarked */
switch (rte->rtekind)
{
case RTE_RELATION:
- case RTE_SPECIAL:
case RTE_VALUES:
/*
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;
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;
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++)
if (!isnull)
{
Node *qual;
+ char relkind;
deparse_context context;
deparse_namespace dpns;
RangeTblEntry *oldrte;
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;
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;
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;
switch (rte->rtekind)
{
case RTE_RELATION:
- case RTE_SPECIAL:
case RTE_VALUES:
/*
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 201102221
+#define CATALOG_VERSION_NO 201102222
#endif
Oid reltoastidxid; /* if toast table, OID of chunk_id index */
bool relhasindex; /* T if has (or has had) any indexes */
bool relisshared; /* T if shared across databases */
- char relpersistence; /* see RELPERSISTENCE_xxx constants */
+ char relpersistence; /* see RELPERSISTENCE_xxx constants below */
char relkind; /* see RELKIND_xxx constants below */
int2 relnatts; /* number of user attributes */
DATA(insert OID = 1259 ( pg_class PGNSP 83 0 PGUID 0 0 0 0 0 0 0 f f p r 26 0 t f f f f 3 _null_ _null_ ));
DESCR("");
+
+#define RELKIND_RELATION 'r' /* ordinary table */
#define RELKIND_INDEX 'i' /* secondary index */
-#define RELKIND_RELATION 'r' /* ordinary cataloged heap */
-#define RELKIND_SEQUENCE 'S' /* SEQUENCE relation */
-#define RELKIND_UNCATALOGED 'u' /* temporary heap */
-#define RELKIND_TOASTVALUE 't' /* moved off huge values */
+#define RELKIND_SEQUENCE 'S' /* sequence object */
+#define RELKIND_TOASTVALUE 't' /* for out-of-line values */
#define RELKIND_VIEW 'v' /* view */
#define RELKIND_COMPOSITE_TYPE 'c' /* composite type */
#define RELKIND_FOREIGN_TABLE 'f' /* foreign table */
+#define RELKIND_UNCATALOGED 'u' /* not yet cataloged */
-#define RELPERSISTENCE_PERMANENT 'p'
-#define RELPERSISTENCE_UNLOGGED 'u'
-#define RELPERSISTENCE_TEMP 't'
+#define RELPERSISTENCE_PERMANENT 'p' /* regular table */
+#define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */
+#define RELPERSISTENCE_TEMP 't' /* temporary table */
#endif /* PG_CLASS_H */
* like outer joins and join-output-column aliasing.) Other special
* RTE types also exist, as indicated by RTEKind.
*
+ * Note that we consider RTE_RELATION to cover anything that has a pg_class
+ * entry. relkind distinguishes the sub-cases.
+ *
* alias is an Alias node representing the AS alias-clause attached to the
* FROM expression, or NULL if no clause.
*
* indicates no permissions checking). If checkAsUser is not zero,
* then do the permissions checks using the access rights of that user,
* not the current effective user ID. (This allows rules to act as
- * setuid gateways.)
+ * setuid gateways.) Permissions checks only apply to RELATION RTEs.
*
* For SELECT/INSERT/UPDATE permissions, if the user doesn't have
* table-wide permissions then it is sufficient to have the permissions
RTE_RELATION, /* ordinary relation reference */
RTE_SUBQUERY, /* subquery in FROM */
RTE_JOIN, /* join */
- RTE_SPECIAL, /* special rule relation (NEW or OLD) */
RTE_FUNCTION, /* function in FROM */
RTE_VALUES, /* VALUES (<exprlist>), (<exprlist>), ... */
RTE_CTE /* common table expr (WITH list element) */
* Fields valid for a plain relation RTE (else zero):
*/
Oid relid; /* OID of the relation */
+ char relkind; /* relation kind (see pg_class.relkind) */
/*
* Fields valid for a subquery RTE (else NULL):