diff options
author | Andres Freund <andres@anarazel.de> | 2018-11-20 15:36:57 -0800 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2018-11-20 16:00:17 -0800 |
commit | 578b229718e8f15fa779e20f086c4b6bb3776106 (patch) | |
tree | 701869752158d27daa080d292befeb2e52f19037 /src/backend/parser | |
parent | 0999ac479292c12a7c373e612b15e1ff47077990 (diff) | |
download | postgresql-578b229718e8f15fa779e20f086c4b6bb3776106.tar.gz postgresql-578b229718e8f15fa779e20f086c4b6bb3776106.zip |
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
Diffstat (limited to 'src/backend/parser')
-rw-r--r-- | src/backend/parser/gram.y | 48 | ||||
-rw-r--r-- | src/backend/parser/parse_clause.c | 40 | ||||
-rw-r--r-- | src/backend/parser/parse_oper.c | 2 | ||||
-rw-r--r-- | src/backend/parser/parse_relation.c | 23 | ||||
-rw-r--r-- | src/backend/parser/parse_target.c | 2 | ||||
-rw-r--r-- | src/backend/parser/parse_type.c | 16 | ||||
-rw-r--r-- | src/backend/parser/parse_utilcmd.c | 46 |
7 files changed, 39 insertions, 138 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 2effd511358..2c2208ffb72 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -440,7 +440,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type <boolean> opt_instead %type <boolean> opt_unique opt_concurrently opt_verbose opt_full %type <boolean> opt_freeze opt_analyze opt_default opt_recheck -%type <defelt> opt_binary opt_oids copy_delimiter +%type <defelt> opt_binary copy_delimiter %type <boolean> copy_from opt_program @@ -2311,14 +2311,7 @@ alter_table_cmd: n->missing_ok = false; $$ = (Node *)n; } - /* ALTER TABLE <name> SET WITH OIDS */ - | SET WITH OIDS - { - AlterTableCmd *n = makeNode(AlterTableCmd); - n->subtype = AT_AddOids; - $$ = (Node *)n; - } - /* ALTER TABLE <name> SET WITHOUT OIDS */ + /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */ | SET WITHOUT OIDS { AlterTableCmd *n = makeNode(AlterTableCmd); @@ -2961,23 +2954,23 @@ ClosePortalStmt: * syntax had a hard-wired, space-separated set of options. * * Really old syntax, from versions 7.2 and prior: - * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file + * COPY [ BINARY ] table FROM/TO file * [ [ USING ] DELIMITERS 'delimiter' ] ] * [ WITH NULL AS 'null string' ] * This option placement is not supported with COPY (query...). * *****************************************************************************/ -CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids +CopyStmt: COPY opt_binary qualified_name opt_column_list copy_from opt_program copy_file_name copy_delimiter opt_with copy_options { CopyStmt *n = makeNode(CopyStmt); n->relation = $3; n->query = NULL; n->attlist = $4; - n->is_from = $6; - n->is_program = $7; - n->filename = $8; + n->is_from = $5; + n->is_program = $6; + n->filename = $7; if (n->is_program && n->filename == NULL) ereport(ERROR, @@ -2989,12 +2982,10 @@ CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids /* Concatenate user-supplied flags */ if ($2) n->options = lappend(n->options, $2); - if ($5) - n->options = lappend(n->options, $5); - if ($9) - n->options = lappend(n->options, $9); - if ($11) - n->options = list_concat(n->options, $11); + if ($8) + n->options = lappend(n->options, $8); + if ($10) + n->options = list_concat(n->options, $10); $$ = (Node *)n; } | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options @@ -3054,10 +3045,6 @@ copy_opt_item: { $$ = makeDefElem("format", (Node *)makeString("binary"), @1); } - | OIDS - { - $$ = makeDefElem("oids", (Node *)makeInteger(true), @1); - } | FREEZE { $$ = makeDefElem("freeze", (Node *)makeInteger(true), @1); @@ -3118,14 +3105,6 @@ opt_binary: | /*EMPTY*/ { $$ = NULL; } ; -opt_oids: - WITH OIDS - { - $$ = makeDefElem("oids", (Node *)makeInteger(true), @1); - } - | /*EMPTY*/ { $$ = NULL; } - ; - copy_delimiter: opt_using DELIMITERS Sconst { @@ -3942,11 +3921,10 @@ part_elem: ColId opt_collate opt_class $$ = n; } ; -/* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */ +/* WITHOUT OIDS is legacy only */ OptWith: WITH reloptions { $$ = $2; } - | WITH OIDS { $$ = list_make1(makeDefElem("oids", (Node *) makeInteger(true), @1)); } - | WITHOUT OIDS { $$ = list_make1(makeDefElem("oids", (Node *) makeInteger(false), @1)); } + | WITHOUT OIDS { $$ = NIL; } | /*EMPTY*/ { $$ = NIL; } ; diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 660011a3ec3..4ba51203a6a 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -250,46 +250,6 @@ setTargetTable(ParseState *pstate, RangeVar *relation, } /* - * Given a relation-options list (of DefElems), return true iff the specified - * table/result set should be created with OIDs. This needs to be done after - * parsing the query string because the return value can depend upon the - * default_with_oids GUC var. - * - * In some situations, we want to reject an OIDS option even if it's present. - * That's (rather messily) handled here rather than reloptions.c, because that - * code explicitly punts checking for oids to here. - */ -bool -interpretOidsOption(List *defList, bool allowOids) -{ - ListCell *cell; - - /* Scan list to see if OIDS was included */ - foreach(cell, defList) - { - DefElem *def = (DefElem *) lfirst(cell); - - if (def->defnamespace == NULL && - strcmp(def->defname, "oids") == 0) - { - if (!allowOids) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("unrecognized parameter \"%s\"", - def->defname))); - return defGetBoolean(def); - } - } - - /* Force no-OIDS result if caller disallows OIDS. */ - if (!allowOids) - return false; - - /* OIDS option was not specified, so use default. */ - return default_with_oids; -} - -/* * Extract all not-in-common columns from column lists of a source table */ static void diff --git a/src/backend/parser/parse_oper.c b/src/backend/parser/parse_oper.c index b279e1236ad..2f780b9941d 100644 --- a/src/backend/parser/parse_oper.c +++ b/src/backend/parser/parse_oper.c @@ -244,7 +244,7 @@ get_sort_group_operators(Oid argtype, Oid oprid(Operator op) { - return HeapTupleGetOid(op); + return ((Form_pg_operator) GETSTRUCT(op))->oid; } /* given operator tuple, return the underlying function's OID */ diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 66a7105b099..378cbcbf79e 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -1528,7 +1528,7 @@ addRangeTableEntryForFunction(ParseState *pstate, else if (functypclass == TYPEFUNC_SCALAR) { /* Base data type, i.e. scalar */ - tupdesc = CreateTemplateTupleDesc(1, false); + tupdesc = CreateTemplateTupleDesc(1); TupleDescInitEntry(tupdesc, (AttrNumber) 1, chooseScalarFunctionAlias(funcexpr, funcname, @@ -1545,7 +1545,7 @@ addRangeTableEntryForFunction(ParseState *pstate, * Use the column definition list to construct a tupdesc and fill * in the RangeTblFunction's lists. */ - tupdesc = CreateTemplateTupleDesc(list_length(coldeflist), false); + tupdesc = CreateTemplateTupleDesc(list_length(coldeflist)); i = 1; foreach(col, coldeflist) { @@ -1619,7 +1619,7 @@ addRangeTableEntryForFunction(ParseState *pstate, totalatts++; /* Merge the tuple descs of each function into a composite one */ - tupdesc = CreateTemplateTupleDesc(totalatts, false); + tupdesc = CreateTemplateTupleDesc(totalatts); natts = 0; for (i = 0; i < nfuncs; i++) { @@ -3113,10 +3113,7 @@ attnameAttNum(Relation rd, const char *attname, bool sysColOK) if (sysColOK) { if ((i = specialAttNum(attname)) != InvalidAttrNumber) - { - if (i != ObjectIdAttributeNumber || rd->rd_rel->relhasoids) - return i; - } + return i; } /* on failure */ @@ -3125,20 +3122,18 @@ attnameAttNum(Relation rd, const char *attname, bool sysColOK) /* specialAttNum() * - * Check attribute name to see if it is "special", e.g. "oid". + * Check attribute name to see if it is "special", e.g. "xmin". * - 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. + * Caller needs to ensure that it really is an attribute of the rel. */ static int specialAttNum(const char *attname) { const FormData_pg_attribute *sysatt; - sysatt = SystemAttributeByName(attname, - true /* "oid" will be accepted */ ); + sysatt = SystemAttributeByName(attname); if (sysatt != NULL) return sysatt->attnum; return InvalidAttrNumber; @@ -3159,7 +3154,7 @@ attnumAttName(Relation rd, int attid) { const FormData_pg_attribute *sysatt; - sysatt = SystemAttributeDefinition(attid, rd->rd_rel->relhasoids); + sysatt = SystemAttributeDefinition(attid); return &sysatt->attname; } if (attid > rd->rd_att->natts) @@ -3181,7 +3176,7 @@ attnumTypeId(Relation rd, int attid) { const FormData_pg_attribute *sysatt; - sysatt = SystemAttributeDefinition(attid, rd->rd_rel->relhasoids); + sysatt = SystemAttributeDefinition(attid); return sysatt->atttypid; } if (attid > rd->rd_att->natts) diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 3d31be38d56..b8702d914dc 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -1503,7 +1503,7 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup) expandRTE(rte, var->varno, 0, var->location, false, &names, &vars); - tupleDesc = CreateTemplateTupleDesc(list_length(vars), false); + tupleDesc = CreateTemplateTupleDesc(list_length(vars)); i = 1; forboth(lname, names, lvar, vars) { diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c index d959b6122a5..a9dead5ae01 100644 --- a/src/backend/parser/parse_type.c +++ b/src/backend/parser/parse_type.c @@ -161,7 +161,7 @@ LookupTypeName(ParseState *pstate, const TypeName *typeName, namespaceId = LookupExplicitNamespace(schemaname, missing_ok); if (OidIsValid(namespaceId)) - typoid = GetSysCacheOid2(TYPENAMENSP, + typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, PointerGetDatum(typname), ObjectIdGetDatum(namespaceId)); else @@ -230,7 +230,7 @@ LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok) return InvalidOid; } - typoid = HeapTupleGetOid(tup); + typoid = ((Form_pg_type) GETSTRUCT(tup))->oid; ReleaseSysCache(tup); return typoid; @@ -277,7 +277,7 @@ typenameTypeId(ParseState *pstate, const TypeName *typeName) Type tup; tup = typenameType(pstate, typeName, NULL); - typoid = HeapTupleGetOid(tup); + typoid = ((Form_pg_type) GETSTRUCT(tup))->oid; ReleaseSysCache(tup); return typoid; @@ -296,7 +296,7 @@ typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Type tup; tup = typenameType(pstate, typeName, typmod_p); - *typeid_p = HeapTupleGetOid(tup); + *typeid_p = ((Form_pg_type) GETSTRUCT(tup))->oid; ReleaseSysCache(tup); } @@ -572,7 +572,7 @@ typeTypeId(Type tp) { if (tp == NULL) /* probably useless */ elog(ERROR, "typeTypeId() called with NULL type struct"); - return HeapTupleGetOid(tp); + return ((Form_pg_type) GETSTRUCT(tp))->oid; } /* given type (as type struct), return the length of type */ @@ -832,13 +832,15 @@ parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok } else { - if (!((Form_pg_type) GETSTRUCT(tup))->typisdefined) + Form_pg_type typ = (Form_pg_type) GETSTRUCT(tup); + + if (!typ->typisdefined) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("type \"%s\" is only a shell", TypeNameToString(typeName)), parser_errposition(NULL, typeName->location))); - *typeid_p = HeapTupleGetOid(tup); + *typeid_p = typ->oid; ReleaseSysCache(tup); } } diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 2e222d822b3..52582d0a13f 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -80,7 +80,6 @@ typedef struct List *inhRelations; /* relations to inherit from */ bool isforeign; /* true if CREATE/ALTER FOREIGN TABLE */ bool isalter; /* true if altering existing table */ - bool hasoids; /* does relation have an OID column? */ List *columns; /* ColumnDef items */ List *ckconstraints; /* CHECK constraints */ List *fkconstraints; /* FOREIGN KEY constraints */ @@ -168,7 +167,6 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString) Oid namespaceid; Oid existing_relid; ParseCallbackState pcbstate; - bool like_found = false; bool is_foreign_table = IsA(stmt, CreateForeignTableStmt); /* @@ -247,18 +245,6 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString) cxt.partbound = stmt->partbound; cxt.ofType = (stmt->ofTypename != NULL); - /* - * Notice that we allow OIDs here only for plain tables, even though - * foreign tables also support them. This is necessary because the - * default_with_oids GUC must apply only to plain tables and not any other - * relkind; doing otherwise would break existing pg_dump files. We could - * allow explicit "WITH OIDS" while not allowing default_with_oids to - * affect other relkinds, but it would complicate interpretOidsOption(), - * and right now there's no WITH OIDS option in CREATE FOREIGN TABLE - * anyway. - */ - cxt.hasoids = interpretOidsOption(stmt->options, !cxt.isforeign); - Assert(!stmt->ofTypename || !stmt->inhRelations); /* grammar enforces */ if (stmt->ofTypename) @@ -291,7 +277,6 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString) break; case T_TableLikeClause: - like_found = true; transformTableLikeClause(&cxt, (TableLikeClause *) element); break; @@ -303,20 +288,6 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString) } /* - * If we had any LIKE tables, they may require creation of an OID column - * even though the command's own WITH clause didn't ask for one (or, - * perhaps, even specifically rejected having one). Insert a WITH option - * to ensure that happens. We prepend to the list because the first oid - * option will be honored, and we want to override anything already there. - * (But note that DefineRelation will override this again to add an OID - * column if one appears in an inheritance parent table.) - */ - if (like_found && cxt.hasoids) - stmt->options = lcons(makeDefElem("oids", - (Node *) makeInteger(true), -1), - stmt->options); - - /* * transformIndexConstraints wants cxt.alist to contain only index * statements, so transfer anything we already have into save_alist. */ @@ -692,7 +663,7 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column) errmsg("identity columns are not supported on partitions"))); ctype = typenameType(cxt->pstate, column->typeName, NULL); - typeOid = HeapTupleGetOid(ctype); + typeOid = ((Form_pg_type) GETSTRUCT(ctype))->oid; ReleaseSysCache(ctype); if (saw_identity) @@ -1079,9 +1050,6 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla } } - /* We use oids if at least one LIKE'ed table has oids. */ - cxt->hasoids |= relation->rd_rel->relhasoids; - /* * Copy CHECK constraints if requested, being careful to adjust attribute * numbers so they match the child. @@ -1245,7 +1213,7 @@ transformOfType(CreateStmtContext *cxt, TypeName *ofTypename) tuple = typenameType(NULL, ofTypename, NULL); check_of_type(tuple); - ofTypeId = HeapTupleGetOid(tuple); + ofTypeId = ((Form_pg_type) GETSTRUCT(tuple))->oid; ofTypename->typeOid = ofTypeId; /* cached for later */ tupdesc = lookup_rowtype_tupdesc(ofTypeId, -1); @@ -2078,8 +2046,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) attform = TupleDescAttr(heap_rel->rd_att, attnum - 1); } else - attform = SystemAttributeDefinition(attnum, - heap_rel->rd_rel->relhasoids); + attform = SystemAttributeDefinition(attnum); attname = pstrdup(NameStr(attform->attname)); if (i < index_form->indnkeyatts) @@ -2169,7 +2136,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) if (constraint->contype == CONSTR_PRIMARY) column->is_not_null = true; } - else if (SystemAttributeByName(key, cxt->hasoids) != NULL) + else if (SystemAttributeByName(key) != NULL) { /* * column will be a system column in the new table, so accept @@ -2292,7 +2259,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) if (!found) { - if (SystemAttributeByName(key, cxt->hasoids) != NULL) + if (SystemAttributeByName(key) != NULL) { /* * column will be a system column in the new table, so accept @@ -2966,7 +2933,6 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, cxt.rel = rel; cxt.inhRelations = NIL; cxt.isalter = true; - cxt.hasoids = false; /* need not be right */ cxt.columns = NIL; cxt.ckconstraints = NIL; cxt.fkconstraints = NIL; @@ -3400,7 +3366,7 @@ transformColumnType(CreateStmtContext *cxt, ColumnDef *column) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("collations are not supported by type %s", - format_type_be(HeapTupleGetOid(ctype))), + format_type_be(typtup->oid)), parser_errposition(cxt->pstate, column->collClause->location))); } |