mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
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
This commit is contained in:
@ -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;
|
||||
|
||||
@ -302,20 +287,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)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user