summaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_relation.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-08-10 18:57:42 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-08-10 18:57:42 +0000
commitbf56f0759bdfa87f143c3abd09f893a5f530fe88 (patch)
tree10555a5e46bcfdfd9799b8f0e13ab48101d766de /src/backend/parser/parse_relation.c
parentd062f0f4e91f68b1f55b04691bd92d1efc83dc54 (diff)
Make OIDs optional, per discussions in pghackers. WITH OIDS is still the
default, but OIDS are removed from many system catalogs that don't need them. Some interesting side effects: TOAST pointers are 20 bytes not 32 now; pg_description has a three-column key instead of one. Bugs fixed in passing: BINARY cursors work again; pg_class.relhaspkey has some usefulness; pg_dump dumps comments on indexes, rules, and triggers in a valid order. initdb forced.
Diffstat (limited to 'src/backend/parser/parse_relation.c')
-rw-r--r--src/backend/parser/parse_relation.c58
1 files changed, 26 insertions, 32 deletions
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index e1d49842fd2..1cc3d19c78d 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.55 2001/05/07 00:43:23 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.56 2001/08/10 18:57:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -28,6 +28,7 @@
#include "rewrite/rewriteManip.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
+#include "utils/syscache.h"
static Node *scanNameSpaceForRefname(ParseState *pstate, Node *nsnode,
@@ -38,6 +39,7 @@ static Node *scanJoinForColumn(JoinExpr *join, char *colname,
int sublevels_up);
static bool isForUpdate(ParseState *pstate, char *relname);
static List *expandNamesVars(ParseState *pstate, List *names, List *vars);
+static int specialAttNum(char *a);
static void warnAutoRange(ParseState *pstate, char *refname);
@@ -318,11 +320,19 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname)
*/
if (rte->relid != InvalidOid)
{
+ /* quick check to see if name could be a system column */
attnum = specialAttNum(colname);
if (attnum != InvalidAttrNumber)
{
- result = (Node *) make_var(pstate, rte, attnum);
- rte->checkForRead = true;
+ /* now check to see if column actually is defined */
+ if (SearchSysCacheExists(ATTNUM,
+ ObjectIdGetDatum(rte->relid),
+ Int16GetDatum(attnum),
+ 0, 0))
+ {
+ result = (Node *) make_var(pstate, rte, attnum);
+ rte->checkForRead = true;
+ }
}
}
@@ -968,7 +978,10 @@ attnameAttNum(Relation rd, char *a)
return i + 1;
if ((i = specialAttNum(a)) != InvalidAttrNumber)
- return i;
+ {
+ if (i != ObjectIdAttributeNumber || rd->rd_rel->relhasoids)
+ return i;
+ }
/* on failure */
elog(ERROR, "Relation '%s' does not have attribute '%s'",
@@ -977,10 +990,15 @@ attnameAttNum(Relation rd, char *a)
}
/* specialAttNum()
+ *
* Check attribute name to see if it is "special", e.g. "oid".
* - thomas 2000-02-07
+ *
+ * Note: this only discovers whether the name could be a system attribute.
+ * Caller needs to verify that it really is an attribute of the rel,
+ * at least in the case of "oid", which is now optional.
*/
-int
+static int
specialAttNum(char *a)
{
int i;
@@ -993,38 +1011,14 @@ specialAttNum(char *a)
}
-#ifdef NOT_USED
-/*
- * Given range variable, return whether attribute of this name
- * is a set.
- * NOTE the ASSUMPTION here that no system attributes are, or ever
- * will be, sets.
- *
- * This should only be used if the relation is already
- * heap_open()'ed. Use the cache version get_attisset()
- * for access to non-opened relations.
- */
-bool
-attnameIsSet(Relation rd, char *name)
-{
- int i;
-
- /* First check if this is a system attribute */
- for (i = 0; i < SPECIALS; i++)
- {
- if (strcmp(special_attr[i].attrname, name) == 0)
- return false; /* no sys attr is a set */
- }
- return get_attisset(RelationGetRelid(rd), name);
-}
-
-#endif
-
/* given attribute id, return type of that attribute */
/*
* This should only be used if the relation is already
* heap_open()'ed. Use the cache version get_atttype()
* for access to non-opened relations.
+ *
+ * Note: we don't bother to check rd->rd_rel->relhasoids; we assume that
+ * the caller will only ask about OID if that column has been found valid.
*/
Oid
attnumTypeId(Relation rd, int attid)