diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-08-10 18:57:42 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-08-10 18:57:42 +0000 |
| commit | bf56f0759bdfa87f143c3abd09f893a5f530fe88 (patch) | |
| tree | 10555a5e46bcfdfd9799b8f0e13ab48101d766de /src/backend/parser | |
| parent | d062f0f4e91f68b1f55b04691bd92d1efc83dc54 (diff) | |
| download | postgresql-bf56f0759bdfa87f143c3abd09f893a5f530fe88.tar.gz | |
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')
| -rw-r--r-- | src/backend/parser/gram.y | 15 | ||||
| -rw-r--r-- | src/backend/parser/parse_relation.c | 58 |
2 files changed, 37 insertions, 36 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 2a08413daf..c16bd865ce 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.242 2001/08/10 14:30:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.243 2001/08/10 18:57:36 tgl Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -198,7 +198,7 @@ static void doNegateFloat(Value *v); %type <typnam> func_arg, func_return, func_type, aggr_argtype -%type <boolean> opt_arg, TriggerForOpt, TriggerForType, OptTemp +%type <boolean> opt_arg, TriggerForOpt, TriggerForType, OptTemp, OptWithOids %type <list> for_update_clause, opt_for_update_clause, update_list %type <boolean> opt_all @@ -1174,14 +1174,15 @@ copy_null: WITH NULL_P AS Sconst { $$ = $4; } * *****************************************************************************/ -CreateStmt: CREATE OptTemp TABLE relation_name '(' OptTableElementList ')' OptInherit +CreateStmt: CREATE OptTemp TABLE relation_name '(' OptTableElementList ')' OptInherit OptWithOids { CreateStmt *n = makeNode(CreateStmt); - n->istemp = $2; n->relname = $4; n->tableElts = $6; n->inhRelnames = $8; n->constraints = NIL; + n->istemp = $2; + n->hasoids = $9; $$ = (Node *)n; } ; @@ -1541,6 +1542,12 @@ OptInherit: INHERITS '(' relation_name_list ')' { $$ = $3; } | /*EMPTY*/ { $$ = NIL; } ; +OptWithOids: WITH OIDS { $$ = TRUE; } + | WITHOUT OIDS { $$ = FALSE; } + | /*EMPTY*/ { $$ = TRUE; } + ; + + /* * Note: CREATE TABLE ... AS SELECT ... is just another spelling for * SELECT ... INTO. diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index e1d49842fd..1cc3d19c78 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) |
