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/utils | |
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/utils')
30 files changed, 159 insertions, 281 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index c5f7918440b..30cf3d0b11f 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -1763,7 +1763,7 @@ aclexplode(PG_FUNCTION_ARGS) * build tupdesc for result tuples (matches out parameters in pg_proc * entry) */ - tupdesc = CreateTemplateTupleDesc(4, false); + tupdesc = CreateTemplateTupleDesc(4); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "grantor", OIDOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "grantee", @@ -5191,7 +5191,8 @@ get_role_oid(const char *rolname, bool missing_ok) { Oid oid; - oid = GetSysCacheOid1(AUTHNAME, CStringGetDatum(rolname)); + oid = GetSysCacheOid1(AUTHNAME, Anum_pg_authid_oid, + CStringGetDatum(rolname)); if (!OidIsValid(oid) && !missing_ok) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 20d6cee8b10..cd5fd0a099f 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -4674,7 +4674,7 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS) * build tupdesc for result tuples. This must match this function's * pg_proc entry! */ - tupdesc = CreateTemplateTupleDesc(3, false); + tupdesc = CreateTemplateTupleDesc(3); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "abbrev", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "utc_offset", @@ -4801,7 +4801,7 @@ pg_timezone_names(PG_FUNCTION_ARGS) * build tupdesc for result tuples. This must match this function's * pg_proc entry! */ - tupdesc = CreateTemplateTupleDesc(4, false); + tupdesc = CreateTemplateTupleDesc(4); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "abbrev", diff --git a/src/backend/utils/adt/enum.c b/src/backend/utils/adt/enum.c index 01edccced29..99f0a90248f 100644 --- a/src/backend/utils/adt/enum.c +++ b/src/backend/utils/adt/enum.c @@ -64,7 +64,7 @@ static void check_safe_enum_use(HeapTuple enumval_tup) { TransactionId xmin; - Form_pg_enum en; + Form_pg_enum en = (Form_pg_enum) GETSTRUCT(enumval_tup); /* * If the row is hinted as committed, it's surely safe. This provides a @@ -88,14 +88,13 @@ check_safe_enum_use(HeapTuple enumval_tup) * owning type. (This'd also be false for values made by other * transactions; but the previous tests should have handled all of those.) */ - if (!EnumBlacklisted(HeapTupleGetOid(enumval_tup))) + if (!EnumBlacklisted(en->oid)) return; /* * There might well be other tests we could do here to narrow down the * unsafe conditions, but for now just raise an exception. */ - en = (Form_pg_enum) GETSTRUCT(enumval_tup); ereport(ERROR, (errcode(ERRCODE_UNSAFE_NEW_ENUM_VALUE_USAGE), errmsg("unsafe use of new value \"%s\" of enum type %s", @@ -140,7 +139,7 @@ enum_in(PG_FUNCTION_ARGS) * This comes from pg_enum.oid and stores system oids in user tables. This * oid must be preserved by binary upgrades. */ - enumoid = HeapTupleGetOid(tup); + enumoid = ((Form_pg_enum) GETSTRUCT(tup))->oid; ReleaseSysCache(tup); @@ -204,7 +203,7 @@ enum_recv(PG_FUNCTION_ARGS) /* check it's safe to use in SQL */ check_safe_enum_use(tup); - enumoid = HeapTupleGetOid(tup); + enumoid = ((Form_pg_enum) GETSTRUCT(tup))->oid; ReleaseSysCache(tup); @@ -414,7 +413,7 @@ enum_endpoint(Oid enumtypoid, ScanDirection direction) { /* check it's safe to use in SQL */ check_safe_enum_use(enum_tuple); - minmax = HeapTupleGetOid(enum_tuple); + minmax = ((Form_pg_enum) GETSTRUCT(enum_tuple))->oid; } else { @@ -574,7 +573,7 @@ enum_range_internal(Oid enumtypoid, Oid lower, Oid upper) while (HeapTupleIsValid(enum_tuple = systable_getnext_ordered(enum_scan, ForwardScanDirection))) { - Oid enum_oid = HeapTupleGetOid(enum_tuple); + Oid enum_oid = ((Form_pg_enum) GETSTRUCT(enum_tuple))->oid; if (!left_found && lower == enum_oid) left_found = true; diff --git a/src/backend/utils/adt/expandedrecord.c b/src/backend/utils/adt/expandedrecord.c index 9aa6f3aac51..5561b741e98 100644 --- a/src/backend/utils/adt/expandedrecord.c +++ b/src/backend/utils/adt/expandedrecord.c @@ -741,9 +741,6 @@ ER_get_flat_size(ExpandedObjectHeader *eohptr) if (hasnull) len += BITMAPLEN(tupdesc->natts); - if (tupdesc->tdhasoid) - len += sizeof(Oid); - hoff = len = MAXALIGN(len); /* align user data safely */ data_len = heap_compute_data_size(tupdesc, erh->dvalues, erh->dnulls); @@ -804,9 +801,6 @@ ER_flatten_into(ExpandedObjectHeader *eohptr, HeapTupleHeaderSetNatts(tuphdr, tupdesc->natts); tuphdr->t_hoff = erh->hoff; - if (tupdesc->tdhasoid) /* else leave infomask = 0 */ - tuphdr->t_infomask = HEAP_HASOID; - /* And fill the data area from dvalues/dnulls */ heap_fill_tuple(tupdesc, erh->dvalues, @@ -1045,7 +1039,7 @@ expanded_record_lookup_field(ExpandedRecordHeader *erh, const char *fieldname, } /* How about system attributes? */ - sysattr = SystemAttributeByName(fieldname, tupdesc->tdhasoid); + sysattr = SystemAttributeByName(fieldname); if (sysattr != NULL) { finfo->fnumber = sysattr->attnum; diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c index d4dc92c2fd9..5081a974c21 100644 --- a/src/backend/utils/adt/genfile.c +++ b/src/backend/utils/adt/genfile.c @@ -388,7 +388,7 @@ pg_stat_file(PG_FUNCTION_ARGS) * This record type had better match the output parameters declared for me * in pg_proc.h. */ - tupdesc = CreateTemplateTupleDesc(6, false); + tupdesc = CreateTemplateTupleDesc(6); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "size", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, @@ -538,7 +538,7 @@ pg_ls_dir_files(FunctionCallInfo fcinfo, const char *dir, bool missing_ok) fctx = palloc(sizeof(directory_fctx)); - tupdesc = CreateTemplateTupleDesc(3, false); + tupdesc = CreateTemplateTupleDesc(3); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "size", diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c index 66c09a1f316..525decb6f1b 100644 --- a/src/backend/utils/adt/lockfuncs.c +++ b/src/backend/utils/adt/lockfuncs.c @@ -101,7 +101,7 @@ pg_lock_status(PG_FUNCTION_ARGS) /* build tupdesc for result tuples */ /* this had better match function's declaration in pg_proc.h */ - tupdesc = CreateTemplateTupleDesc(NUM_LOCK_STATUS_COLUMNS, false); + tupdesc = CreateTemplateTupleDesc(NUM_LOCK_STATUS_COLUMNS); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "locktype", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "database", diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 309eb2935c7..d05849f1d42 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -402,7 +402,7 @@ pg_get_keywords(PG_FUNCTION_ARGS) funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - tupdesc = CreateTemplateTupleDesc(3, false); + tupdesc = CreateTemplateTupleDesc(3); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "catcode", diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c index 8871aed9045..1b21da8d096 100644 --- a/src/backend/utils/adt/orderedsetaggs.c +++ b/src/backend/utils/adt/orderedsetaggs.c @@ -215,7 +215,7 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples) * Get a tupledesc corresponding to the aggregated inputs * (including sort expressions) of the agg. */ - qstate->tupdesc = ExecTypeFromTL(aggref->args, false); + qstate->tupdesc = ExecTypeFromTL(aggref->args); /* If we need a flag column, hack the tupledesc to include that */ if (ishypothetical) @@ -223,7 +223,7 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples) TupleDesc newdesc; int natts = qstate->tupdesc->natts; - newdesc = CreateTemplateTupleDesc(natts + 1, false); + newdesc = CreateTemplateTupleDesc(natts + 1); for (i = 1; i <= natts; i++) TupleDescCopyEntry(newdesc, i, qstate->tupdesc, i); diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c index 8f9218ad0aa..78dd2b542b5 100644 --- a/src/backend/utils/adt/partitionfuncs.c +++ b/src/backend/utils/adt/partitionfuncs.c @@ -72,7 +72,7 @@ pg_partition_tree(PG_FUNCTION_ARGS) */ partitions = find_all_inheritors(rootrelid, AccessShareLock, NULL); - tupdesc = CreateTemplateTupleDesc(PG_PARTITION_TREE_COLS, false); + tupdesc = CreateTemplateTupleDesc(PG_PARTITION_TREE_COLS); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "relid", REGCLASSOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "parentid", diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index e95e3471846..f955f1912a4 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -1829,7 +1829,7 @@ pg_stat_get_archiver(PG_FUNCTION_ARGS) MemSet(nulls, 0, sizeof(nulls)); /* Initialise attributes information in the tuple descriptor */ - tupdesc = CreateTemplateTupleDesc(7, false); + tupdesc = CreateTemplateTupleDesc(7); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "last_archived_wal", diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 29884f1c8b6..4857caecaad 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -843,7 +843,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty) tgrel = heap_open(TriggerRelationId, AccessShareLock); ScanKeyInit(&skey[0], - ObjectIdAttributeNumber, + Anum_pg_trigger_oid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(trigid)); @@ -1883,7 +1883,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, Relation relation = heap_open(ConstraintRelationId, AccessShareLock); ScanKeyInit(&scankey[0], - ObjectIdAttributeNumber, + Anum_pg_constraint_oid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(constraintId)); @@ -2930,11 +2930,10 @@ print_function_arguments(StringInfo buf, HeapTuple proctup, HeapTuple aggtup; Form_pg_aggregate agg; - aggtup = SearchSysCache1(AGGFNOID, - ObjectIdGetDatum(HeapTupleGetOid(proctup))); + aggtup = SearchSysCache1(AGGFNOID, proc->oid); if (!HeapTupleIsValid(aggtup)) elog(ERROR, "cache lookup failed for aggregate %u", - HeapTupleGetOid(proctup)); + proc->oid); agg = (Form_pg_aggregate) GETSTRUCT(aggtup); if (AGGKIND_IS_ORDERED_SET(agg->aggkind)) insertorderbyat = agg->aggnumdirectargs; diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index dbbbcc979b4..73fbb4ac86b 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -5216,7 +5216,6 @@ get_variable_numdistinct(VariableStatData *vardata, bool *isdefault) { switch (((Var *) vardata->var)->varattno) { - case ObjectIdAttributeNumber: case SelfItemPointerAttributeNumber: stadistinct = -1.0; /* unique (and all non null) */ break; diff --git a/src/backend/utils/adt/trigfuncs.c b/src/backend/utils/adt/trigfuncs.c index 04605021d79..93ac936420d 100644 --- a/src/backend/utils/adt/trigfuncs.c +++ b/src/backend/utils/adt/trigfuncs.c @@ -66,17 +66,6 @@ suppress_redundant_updates_trigger(PG_FUNCTION_ARGS) newheader = newtuple->t_data; oldheader = oldtuple->t_data; - /* - * We are called before the OID, if any, has been transcribed from the old - * tuple to the new (in heap_update). To avoid a bogus compare failure, - * copy the OID now. But check that someone didn't already put another - * OID value into newtuple. (That's not actually possible at present, but - * maybe someday.) - */ - if (trigdata->tg_relation->rd_rel->relhasoids && - !OidIsValid(HeapTupleHeaderGetOid(newheader))) - HeapTupleHeaderSetOid(newheader, HeapTupleHeaderGetOid(oldheader)); - /* if the tuple payload is the same ... */ if (newtuple->t_len == oldtuple->t_len && newheader->t_hoff == oldheader->t_hoff && diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c index 258fe47a245..3c55166a14e 100644 --- a/src/backend/utils/adt/tsvector_op.c +++ b/src/backend/utils/adt/tsvector_op.c @@ -646,7 +646,7 @@ tsvector_unnest(PG_FUNCTION_ARGS) funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - tupdesc = CreateTemplateTupleDesc(3, false); + tupdesc = CreateTemplateTupleDesc(3); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "lexeme", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "positions", @@ -2187,7 +2187,7 @@ ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx, } Assert(stat->stackpos <= stat->maxdepth); - tupdesc = CreateTemplateTupleDesc(3, false); + tupdesc = CreateTemplateTupleDesc(3); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "ndoc", diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index 5ddbf6eab10..b31fd5acea7 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -338,39 +338,31 @@ CatalogCacheComputeTupleHashValue(CatCache *cache, int nkeys, HeapTuple tuple) switch (nkeys) { case 4: - v4 = (cc_keyno[3] == ObjectIdAttributeNumber) - ? ObjectIdGetDatum(HeapTupleGetOid(tuple)) - : fastgetattr(tuple, - cc_keyno[3], - cc_tupdesc, - &isNull); + v4 = fastgetattr(tuple, + cc_keyno[3], + cc_tupdesc, + &isNull); Assert(!isNull); /* FALLTHROUGH */ case 3: - v3 = (cc_keyno[2] == ObjectIdAttributeNumber) - ? ObjectIdGetDatum(HeapTupleGetOid(tuple)) - : fastgetattr(tuple, - cc_keyno[2], - cc_tupdesc, - &isNull); + v3 = fastgetattr(tuple, + cc_keyno[2], + cc_tupdesc, + &isNull); Assert(!isNull); /* FALLTHROUGH */ case 2: - v2 = (cc_keyno[1] == ObjectIdAttributeNumber) - ? ObjectIdGetDatum(HeapTupleGetOid(tuple)) - : fastgetattr(tuple, - cc_keyno[1], - cc_tupdesc, - &isNull); + v2 = fastgetattr(tuple, + cc_keyno[1], + cc_tupdesc, + &isNull); Assert(!isNull); /* FALLTHROUGH */ case 1: - v1 = (cc_keyno[0] == ObjectIdAttributeNumber) - ? ObjectIdGetDatum(HeapTupleGetOid(tuple)) - : fastgetattr(tuple, - cc_keyno[0], - cc_tupdesc, - &isNull); + v1 = fastgetattr(tuple, + cc_keyno[0], + cc_tupdesc, + &isNull); Assert(!isNull); break; default: @@ -998,8 +990,8 @@ CatalogCacheInitializeCache(CatCache *cache) } else { - if (cache->cc_keyno[i] != ObjectIdAttributeNumber) - elog(FATAL, "only sys attr supported in caches is OID"); + if (cache->cc_keyno[i] < 0) + elog(FATAL, "sys attributes are not supported in caches"); keytype = OIDOID; } @@ -1935,9 +1927,7 @@ CatCacheFreeKeys(TupleDesc tupdesc, int nkeys, int *attnos, Datum *keys) int attnum = attnos[i]; Form_pg_attribute att; - /* only valid system attribute is the oid, which is by value */ - if (attnum == ObjectIdAttributeNumber) - continue; + /* system attribute are not supported in caches */ Assert(attnum > 0); att = TupleDescAttr(tupdesc, attnum - 1); @@ -1966,33 +1956,25 @@ CatCacheCopyKeys(TupleDesc tupdesc, int nkeys, int *attnos, for (i = 0; i < nkeys; i++) { int attnum = attnos[i]; + Form_pg_attribute att = TupleDescAttr(tupdesc, attnum - 1); + Datum src = srckeys[i]; + NameData srcname; - if (attnum == ObjectIdAttributeNumber) + /* + * Must be careful in case the caller passed a C string where a + * NAME is wanted: convert the given argument to a correctly + * padded NAME. Otherwise the memcpy() done by datumCopy() could + * fall off the end of memory. + */ + if (att->atttypid == NAMEOID) { - dstkeys[i] = srckeys[i]; + namestrcpy(&srcname, DatumGetCString(src)); + src = NameGetDatum(&srcname); } - else - { - Form_pg_attribute att = TupleDescAttr(tupdesc, attnum - 1); - Datum src = srckeys[i]; - NameData srcname; - /* - * Must be careful in case the caller passed a C string where a - * NAME is wanted: convert the given argument to a correctly - * padded NAME. Otherwise the memcpy() done by datumCopy() could - * fall off the end of memory. - */ - if (att->atttypid == NAMEOID) - { - namestrcpy(&srcname, DatumGetCString(src)); - src = NameGetDatum(&srcname); - } - - dstkeys[i] = datumCopy(src, - att->attbyval, - att->attlen); - } + dstkeys[i] = datumCopy(src, + att->attbyval, + att->attlen); } } diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index f3ded4def90..51574937959 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -1166,7 +1166,7 @@ CacheInvalidateHeapTuple(Relation relation, { Form_pg_class classtup = (Form_pg_class) GETSTRUCT(tuple); - relationId = HeapTupleGetOid(tuple); + relationId = classtup->oid; if (classtup->relisshared) databaseId = InvalidOid; else @@ -1292,7 +1292,7 @@ CacheInvalidateRelcacheByTuple(HeapTuple classTuple) PrepareInvalidationState(); - relationId = HeapTupleGetOid(classTuple); + relationId = classtup->oid; if (classtup->relisshared) databaseId = InvalidOid; else diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 892ddc0d486..7a263cc1fdc 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -1653,7 +1653,7 @@ get_func_rows(Oid funcid) Oid get_relname_relid(const char *relname, Oid relnamespace) { - return GetSysCacheOid2(RELNAMENSP, + return GetSysCacheOid2(RELNAMENSP, Anum_pg_class_oid, PointerGetDatum(relname), ObjectIdGetDatum(relnamespace)); } @@ -2056,7 +2056,7 @@ getTypeIOParam(HeapTuple typeTuple) if (OidIsValid(typeStruct->typelem)) return typeStruct->typelem; else - return HeapTupleGetOid(typeTuple); + return typeStruct->oid; } /* diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c index fc7e8dbe269..9ec81c5f367 100644 --- a/src/backend/utils/cache/plancache.c +++ b/src/backend/utils/cache/plancache.c @@ -1663,12 +1663,12 @@ PlanCacheComputeResultDesc(List *stmt_list) case PORTAL_ONE_SELECT: case PORTAL_ONE_MOD_WITH: query = linitial_node(Query, stmt_list); - return ExecCleanTypeFromTL(query->targetList, false); + return ExecCleanTypeFromTL(query->targetList); case PORTAL_ONE_RETURNING: query = QueryListGetPrimaryStmt(stmt_list); Assert(query->returningList); - return ExecCleanTypeFromTL(query->returningList, false); + return ExecCleanTypeFromTL(query->returningList); case PORTAL_UTIL_SELECT: query = linitial_node(Query, stmt_list); diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index aecbd4a9437..c3071db1cdf 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -261,8 +261,7 @@ static void write_relcache_init_file(bool shared); static void write_item(const void *data, Size len, FILE *fp); static void formrdesc(const char *relationName, Oid relationReltype, - bool isshared, bool hasoids, - int natts, const FormData_pg_attribute *attrs); + bool isshared, int natts, const FormData_pg_attribute *attrs); static HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic); static Relation AllocateRelationDesc(Form_pg_class relp); @@ -328,7 +327,7 @@ ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic) * form a scan key */ ScanKeyInit(&key[0], - ObjectIdAttributeNumber, + Anum_pg_class_oid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(targetRelId)); @@ -414,8 +413,7 @@ AllocateRelationDesc(Form_pg_class relp) relation->rd_rel = relationForm; /* and allocate attribute tuple form storage */ - relation->rd_att = CreateTemplateTupleDesc(relationForm->relnatts, - relationForm->relhasoids); + relation->rd_att = CreateTemplateTupleDesc(relationForm->relnatts); /* which we mark as a reference-counted tupdesc */ relation->rd_att->tdrefcount = 1; @@ -505,7 +503,6 @@ RelationBuildTupleDesc(Relation relation) /* copy some fields from pg_class row to rd_att */ relation->rd_att->tdtypeid = relation->rd_rel->reltype; relation->rd_att->tdtypmod = -1; /* unnecessary, but... */ - relation->rd_att->tdhasoid = relation->rd_rel->relhasoids; constr = (TupleConstr *) MemoryContextAlloc(CacheMemoryContext, sizeof(TupleConstr)); @@ -789,7 +786,7 @@ RelationBuildRuleLock(Relation relation) rule = (RewriteRule *) MemoryContextAlloc(rulescxt, sizeof(RewriteRule)); - rule->ruleId = HeapTupleGetOid(rewrite_tuple); + rule->ruleId = rewrite_form->oid; rule->event = rewrite_form->ev_type - '0'; rule->enabled = rewrite_form->ev_enabled; @@ -1090,8 +1087,8 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) /* * get information from the pg_class_tuple */ - relid = HeapTupleGetOid(pg_class_tuple); relp = (Form_pg_class) GETSTRUCT(pg_class_tuple); + relid = relp->oid; Assert(relid == targetRelId); /* @@ -1641,7 +1638,7 @@ LookupOpclassInfo(Oid operatorClassOid, * work while bootstrapping. */ ScanKeyInit(&skey[0], - ObjectIdAttributeNumber, + Anum_pg_opclass_oid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(operatorClassOid)); rel = heap_open(OperatorClassRelationId, AccessShareLock); @@ -1725,7 +1722,7 @@ LookupOpclassInfo(Oid operatorClassOid, */ static void formrdesc(const char *relationName, Oid relationReltype, - bool isshared, bool hasoids, + bool isshared, int natts, const FormData_pg_attribute *attrs) { Relation relation; @@ -1789,7 +1786,6 @@ formrdesc(const char *relationName, Oid relationReltype, relation->rd_rel->reltuples = 0; relation->rd_rel->relallvisible = 0; relation->rd_rel->relkind = RELKIND_RELATION; - relation->rd_rel->relhasoids = hasoids; relation->rd_rel->relnatts = (int16) natts; /* @@ -1799,7 +1795,7 @@ formrdesc(const char *relationName, Oid relationReltype, * because it will never be replaced. The data comes from * src/include/catalog/ headers via genbki.pl. */ - relation->rd_att = CreateTemplateTupleDesc(natts, hasoids); + relation->rd_att = CreateTemplateTupleDesc(natts); relation->rd_att->tdrefcount = 1; /* mark as refcounted */ relation->rd_att->tdtypeid = relationReltype; @@ -2964,7 +2960,6 @@ AtEOXact_cleanup(Relation relation, bool isCommit) { list_free(relation->rd_indexlist); relation->rd_indexlist = NIL; - relation->rd_oidindex = InvalidOid; relation->rd_pkindex = InvalidOid; relation->rd_replidindex = InvalidOid; relation->rd_indexvalid = 0; @@ -3077,7 +3072,6 @@ AtEOSubXact_cleanup(Relation relation, bool isCommit, { list_free(relation->rd_indexlist); relation->rd_indexlist = NIL; - relation->rd_oidindex = InvalidOid; relation->rd_pkindex = InvalidOid; relation->rd_replidindex = InvalidOid; relation->rd_indexvalid = 0; @@ -3208,7 +3202,6 @@ RelationBuildLocalRelation(const char *relname, rel->rd_rel->relnamespace = relnamespace; rel->rd_rel->relkind = relkind; - rel->rd_rel->relhasoids = rel->rd_att->tdhasoid; rel->rd_rel->relnatts = natts; rel->rd_rel->reltype = InvalidOid; /* needed when bootstrapping: */ @@ -3508,15 +3501,15 @@ RelationCacheInitializePhase2(void) if (!load_relcache_init_file(true)) { formrdesc("pg_database", DatabaseRelation_Rowtype_Id, true, - true, Natts_pg_database, Desc_pg_database); + Natts_pg_database, Desc_pg_database); formrdesc("pg_authid", AuthIdRelation_Rowtype_Id, true, - true, Natts_pg_authid, Desc_pg_authid); + Natts_pg_authid, Desc_pg_authid); formrdesc("pg_auth_members", AuthMemRelation_Rowtype_Id, true, - false, Natts_pg_auth_members, Desc_pg_auth_members); + Natts_pg_auth_members, Desc_pg_auth_members); formrdesc("pg_shseclabel", SharedSecLabelRelation_Rowtype_Id, true, - false, Natts_pg_shseclabel, Desc_pg_shseclabel); + Natts_pg_shseclabel, Desc_pg_shseclabel); formrdesc("pg_subscription", SubscriptionRelation_Rowtype_Id, true, - true, Natts_pg_subscription, Desc_pg_subscription); + Natts_pg_subscription, Desc_pg_subscription); #define NUM_CRITICAL_SHARED_RELS 5 /* fix if you change list above */ } @@ -3567,13 +3560,13 @@ RelationCacheInitializePhase3(void) needNewCacheFile = true; formrdesc("pg_class", RelationRelation_Rowtype_Id, false, - true, Natts_pg_class, Desc_pg_class); + Natts_pg_class, Desc_pg_class); formrdesc("pg_attribute", AttributeRelation_Rowtype_Id, false, - false, Natts_pg_attribute, Desc_pg_attribute); + Natts_pg_attribute, Desc_pg_attribute); formrdesc("pg_proc", ProcedureRelation_Rowtype_Id, false, - true, Natts_pg_proc, Desc_pg_proc); + Natts_pg_proc, Desc_pg_proc); formrdesc("pg_type", TypeRelation_Rowtype_Id, false, - true, Natts_pg_type, Desc_pg_type); + Natts_pg_type, Desc_pg_type); #define NUM_CRITICAL_LOCAL_RELS 4 /* fix if you change list above */ } @@ -3725,7 +3718,6 @@ RelationCacheInitializePhase3(void) */ Assert(relation->rd_att->tdtypeid == relp->reltype); Assert(relation->rd_att->tdtypmod == -1); - Assert(relation->rd_att->tdhasoid == relp->relhasoids); ReleaseSysCache(htup); @@ -3868,8 +3860,7 @@ load_critical_index(Oid indexoid, Oid heapoid) * extracting fields. */ static TupleDesc -BuildHardcodedDescriptor(int natts, const FormData_pg_attribute *attrs, - bool hasoids) +BuildHardcodedDescriptor(int natts, const FormData_pg_attribute *attrs) { TupleDesc result; MemoryContext oldcxt; @@ -3877,7 +3868,7 @@ BuildHardcodedDescriptor(int natts, const FormData_pg_attribute *attrs, oldcxt = MemoryContextSwitchTo(CacheMemoryContext); - result = CreateTemplateTupleDesc(natts, hasoids); + result = CreateTemplateTupleDesc(natts); result->tdtypeid = RECORDOID; /* not right, but we don't care */ result->tdtypmod = -1; @@ -3906,8 +3897,7 @@ GetPgClassDescriptor(void) /* Already done? */ if (pgclassdesc == NULL) pgclassdesc = BuildHardcodedDescriptor(Natts_pg_class, - Desc_pg_class, - true); + Desc_pg_class); return pgclassdesc; } @@ -3920,8 +3910,7 @@ GetPgIndexDescriptor(void) /* Already done? */ if (pgindexdesc == NULL) pgindexdesc = BuildHardcodedDescriptor(Natts_pg_index, - Desc_pg_index, - false); + Desc_pg_index); return pgindexdesc; } @@ -4145,7 +4134,7 @@ RelationGetFKeyList(Relation relation) continue; info = makeNode(ForeignKeyCacheInfo); - info->conoid = HeapTupleGetOid(htup); + info->conoid = constraint->oid; info->conrelid = constraint->conrelid; info->confrelid = constraint->confrelid; @@ -4248,11 +4237,6 @@ RelationGetFKeyList(Relation relation) * since the caller will typically be doing syscache lookups on the relevant * indexes, and syscache lookup could cause SI messages to be processed! * - * We also update rd_oidindex, which this module treats as effectively part - * of the index list. rd_oidindex is valid when rd_indexvalid isn't zero; - * it is the pg_class OID of a unique index on OID when the relation has one, - * and InvalidOid if there is no such index. - * * In exactly the same way, we update rd_pkindex, which is the OID of the * relation's primary key index if any, else InvalidOid; and rd_replidindex, * which is the pg_class OID of an index to be used as the relation's @@ -4268,7 +4252,6 @@ RelationGetIndexList(Relation relation) List *result; List *oldlist; char replident = relation->rd_rel->relreplident; - Oid oidIndex = InvalidOid; Oid pkeyIndex = InvalidOid; Oid candidateIndex = InvalidOid; MemoryContext oldcxt; @@ -4284,7 +4267,6 @@ RelationGetIndexList(Relation relation) * if we get some sort of error partway through. */ result = NIL; - oidIndex = InvalidOid; /* Prepare to scan pg_index for entries having indrelid = this rel. */ ScanKeyInit(&skey, @@ -4299,9 +4281,6 @@ RelationGetIndexList(Relation relation) while (HeapTupleIsValid(htup = systable_getnext(indscan))) { Form_pg_index index = (Form_pg_index) GETSTRUCT(htup); - Datum indclassDatum; - oidvector *indclass; - bool isnull; /* * Ignore any indexes that are currently being dropped. This will @@ -4316,18 +4295,6 @@ RelationGetIndexList(Relation relation) result = insert_ordered_oid(result, index->indexrelid); /* - * indclass cannot be referenced directly through the C struct, - * because it comes after the variable-width indkey field. Must - * extract the datum the hard way... - */ - indclassDatum = heap_getattr(htup, - Anum_pg_index_indclass, - GetPgIndexDescriptor(), - &isnull); - Assert(!isnull); - indclass = (oidvector *) DatumGetPointer(indclassDatum); - - /* * Invalid, non-unique, non-immediate or predicate indexes aren't * interesting for either oid indexes or replication identity indexes, * so don't check them. @@ -4337,12 +4304,6 @@ RelationGetIndexList(Relation relation) !heap_attisnull(htup, Anum_pg_index_indpred, NULL)) continue; - /* Check to see if is a usable btree index on OID */ - if (index->indnatts == 1 && - index->indkey.values[0] == ObjectIdAttributeNumber && - indclass->values[0] == OID_BTREE_OPS_OID) - oidIndex = index->indexrelid; - /* remember primary key index if any */ if (index->indisprimary) pkeyIndex = index->indexrelid; @@ -4360,7 +4321,6 @@ RelationGetIndexList(Relation relation) oldcxt = MemoryContextSwitchTo(CacheMemoryContext); oldlist = relation->rd_indexlist; relation->rd_indexlist = list_copy(result); - relation->rd_oidindex = oidIndex; relation->rd_pkindex = pkeyIndex; if (replident == REPLICA_IDENTITY_DEFAULT && OidIsValid(pkeyIndex)) relation->rd_replidindex = pkeyIndex; @@ -4435,7 +4395,11 @@ RelationGetStatExtList(Relation relation) NULL, 1, &skey); while (HeapTupleIsValid(htup = systable_getnext(indscan))) - result = insert_ordered_oid(result, HeapTupleGetOid(htup)); + { + Oid oid = ((Form_pg_statistic_ext) GETSTRUCT(htup))->oid; + + result = insert_ordered_oid(result, oid); + } systable_endscan(indscan); @@ -4510,7 +4474,7 @@ insert_ordered_oid(List *list, Oid datum) * touch rd_keyattr, rd_pkattr or rd_idattr. */ void -RelationSetIndexList(Relation relation, List *indexIds, Oid oidIndex) +RelationSetIndexList(Relation relation, List *indexIds) { MemoryContext oldcxt; @@ -4522,7 +4486,6 @@ RelationSetIndexList(Relation relation, List *indexIds, Oid oidIndex) /* Okay to replace old list */ list_free(relation->rd_indexlist); relation->rd_indexlist = indexIds; - relation->rd_oidindex = oidIndex; /* * For the moment, assume the target rel hasn't got a pk or replica index. @@ -4536,34 +4499,6 @@ RelationSetIndexList(Relation relation, List *indexIds, Oid oidIndex) } /* - * RelationGetOidIndex -- get the pg_class OID of the relation's OID index - * - * Returns InvalidOid if there is no such index. - */ -Oid -RelationGetOidIndex(Relation relation) -{ - List *ilist; - - /* - * If relation doesn't have OIDs at all, caller is probably confused. (We - * could just silently return InvalidOid, but it seems better to throw an - * assertion.) - */ - Assert(relation->rd_rel->relhasoids); - - if (relation->rd_indexvalid == 0) - { - /* RelationGetIndexList does the heavy lifting. */ - ilist = RelationGetIndexList(relation); - list_free(ilist); - Assert(relation->rd_indexvalid != 0); - } - - return relation->rd_oidindex; -} - -/* * RelationGetPrimaryKeyIndex -- get OID of the relation's primary key index * * Returns InvalidOid if there is no such index. @@ -5472,8 +5407,7 @@ load_relcache_init_file(bool shared) rel->rd_rel = relform; /* initialize attribute tuple forms */ - rel->rd_att = CreateTemplateTupleDesc(relform->relnatts, - relform->relhasoids); + rel->rd_att = CreateTemplateTupleDesc(relform->relnatts); rel->rd_att->tdrefcount = 1; /* mark as refcounted */ rel->rd_att->tdtypeid = relform->reltype; @@ -5677,7 +5611,6 @@ load_relcache_init_file(bool shared) rel->rd_fkeylist = NIL; rel->rd_fkeyvalid = false; rel->rd_indexlist = NIL; - rel->rd_oidindex = InvalidOid; rel->rd_pkindex = InvalidOid; rel->rd_replidindex = InvalidOid; rel->rd_indexattr = NULL; diff --git a/src/backend/utils/cache/relfilenodemap.c b/src/backend/utils/cache/relfilenodemap.c index 34679725b3d..74c4636895f 100644 --- a/src/backend/utils/cache/relfilenodemap.c +++ b/src/backend/utils/cache/relfilenodemap.c @@ -212,29 +212,17 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) while (HeapTupleIsValid(ntp = systable_getnext(scandesc))) { + Form_pg_class classform = (Form_pg_class) GETSTRUCT(ntp); + if (found) elog(ERROR, "unexpected duplicate for tablespace %u, relfilenode %u", reltablespace, relfilenode); found = true; -#ifdef USE_ASSERT_CHECKING - { - bool isnull; - Oid check; - - check = fastgetattr(ntp, Anum_pg_class_reltablespace, - RelationGetDescr(relation), - &isnull); - Assert(!isnull && check == reltablespace); - - check = fastgetattr(ntp, Anum_pg_class_relfilenode, - RelationGetDescr(relation), - &isnull); - Assert(!isnull && check == relfilenode); - } -#endif - relid = HeapTupleGetOid(ntp); + Assert(classform->reltablespace == reltablespace); + Assert(classform->relfilenode == relfilenode); + relid = classform->oid; } systable_endscan(scandesc); diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c index 2b381782a32..c26808a8334 100644 --- a/src/backend/utils/cache/syscache.c +++ b/src/backend/utils/cache/syscache.c @@ -147,7 +147,7 @@ static const struct cachedesc cacheinfo[] = { AmOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_am_oid, 0, 0, 0 @@ -246,7 +246,7 @@ static const struct cachedesc cacheinfo[] = { AuthIdOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_authid_oid, 0, 0, 0 @@ -280,7 +280,7 @@ static const struct cachedesc cacheinfo[] = { OpclassOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_opclass_oid, 0, 0, 0 @@ -302,7 +302,7 @@ static const struct cachedesc cacheinfo[] = { CollationOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_collation_oid, 0, 0, 0 @@ -316,7 +316,7 @@ static const struct cachedesc cacheinfo[] = { Anum_pg_conversion_connamespace, Anum_pg_conversion_conforencoding, Anum_pg_conversion_contoencoding, - ObjectIdAttributeNumber, + Anum_pg_conversion_oid }, 8 }, @@ -335,7 +335,7 @@ static const struct cachedesc cacheinfo[] = { ConstraintOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_constraint_oid, 0, 0, 0 @@ -346,7 +346,7 @@ static const struct cachedesc cacheinfo[] = { ConversionOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_conversion_oid, 0, 0, 0 @@ -357,7 +357,7 @@ static const struct cachedesc cacheinfo[] = { DatabaseOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_database_oid, 0, 0, 0 @@ -379,7 +379,7 @@ static const struct cachedesc cacheinfo[] = { EnumOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_enum_oid, 0, 0, 0 @@ -412,7 +412,7 @@ static const struct cachedesc cacheinfo[] = { EventTriggerOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_event_trigger_oid, 0, 0, 0 @@ -434,7 +434,7 @@ static const struct cachedesc cacheinfo[] = { ForeignDataWrapperOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_foreign_data_wrapper_oid, 0, 0, 0 @@ -456,7 +456,7 @@ static const struct cachedesc cacheinfo[] = { ForeignServerOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_foreign_server_oid, 0, 0, 0 @@ -500,7 +500,7 @@ static const struct cachedesc cacheinfo[] = { LanguageOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_language_oid, 0, 0, 0 @@ -522,7 +522,7 @@ static const struct cachedesc cacheinfo[] = { NamespaceOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_namespace_oid, 0, 0, 0 @@ -544,7 +544,7 @@ static const struct cachedesc cacheinfo[] = { OperatorOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_operator_oid, 0, 0, 0 @@ -566,7 +566,7 @@ static const struct cachedesc cacheinfo[] = { OpfamilyOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_opfamily_oid, 0, 0, 0 @@ -599,7 +599,7 @@ static const struct cachedesc cacheinfo[] = { ProcedureOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_proc_oid, 0, 0, 0 @@ -621,7 +621,7 @@ static const struct cachedesc cacheinfo[] = { PublicationObjectIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_publication_oid, 0, 0, 0 @@ -632,7 +632,7 @@ static const struct cachedesc cacheinfo[] = { PublicationRelObjectIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_publication_rel_oid, 0, 0, 0 @@ -676,7 +676,7 @@ static const struct cachedesc cacheinfo[] = { ClassOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_class_oid, 0, 0, 0 @@ -742,7 +742,7 @@ static const struct cachedesc cacheinfo[] = { StatisticExtOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_statistic_ext_oid, 0, 0, 0 @@ -775,7 +775,7 @@ static const struct cachedesc cacheinfo[] = { SubscriptionObjectIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_subscription_oid, 0, 0, 0 @@ -797,7 +797,7 @@ static const struct cachedesc cacheinfo[] = { TablespaceOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_tablespace_oid, 0, 0, 0, @@ -808,7 +808,7 @@ static const struct cachedesc cacheinfo[] = { TransformOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_transform_oid, 0, 0, 0, @@ -852,7 +852,7 @@ static const struct cachedesc cacheinfo[] = { TSConfigOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_ts_config_oid, 0, 0, 0 @@ -874,7 +874,7 @@ static const struct cachedesc cacheinfo[] = { TSDictionaryOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_ts_dict_oid, 0, 0, 0 @@ -896,7 +896,7 @@ static const struct cachedesc cacheinfo[] = { TSParserOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_ts_parser_oid, 0, 0, 0 @@ -918,7 +918,7 @@ static const struct cachedesc cacheinfo[] = { TSTemplateOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_ts_template_oid, 0, 0, 0 @@ -940,7 +940,7 @@ static const struct cachedesc cacheinfo[] = { TypeOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_type_oid, 0, 0, 0 @@ -951,7 +951,7 @@ static const struct cachedesc cacheinfo[] = { UserMappingOidIndexId, 1, { - ObjectIdAttributeNumber, + Anum_pg_user_mapping_oid, 0, 0, 0 @@ -1213,24 +1213,29 @@ SearchSysCacheExists(int cacheId, /* * GetSysCacheOid * - * A convenience routine that does SearchSysCache and returns the OID - * of the found tuple, or InvalidOid if no tuple could be found. + * A convenience routine that does SearchSysCache and returns the OID in the + * oidcol column of the found tuple, or InvalidOid if no tuple could be found. * No lock is retained on the syscache entry. */ Oid GetSysCacheOid(int cacheId, + AttrNumber oidcol, Datum key1, Datum key2, Datum key3, Datum key4) { HeapTuple tuple; + bool isNull; Oid result; tuple = SearchSysCache(cacheId, key1, key2, key3, key4); if (!HeapTupleIsValid(tuple)) return InvalidOid; - result = HeapTupleGetOid(tuple); + result = heap_getattr(tuple, oidcol, + SysCache[cacheId]->cc_tupdesc, + &isNull); + Assert(!isNull); /* columns used as oids should never be NULL */ ReleaseSysCache(tuple); return result; } diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c index 663d4ed8bbd..09f9d5fdcbd 100644 --- a/src/backend/utils/cache/typcache.c +++ b/src/backend/utils/cache/typcache.c @@ -2351,7 +2351,7 @@ load_enum_cache_data(TypeCacheEntry *tcache) maxitems *= 2; items = (EnumItem *) repalloc(items, sizeof(EnumItem) * maxitems); } - items[numitems].enum_oid = HeapTupleGetOid(enum_tuple); + items[numitems].enum_oid = en->oid; items[numitems].sort_order = en->enumsortorder; numitems++; } diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index 6cbbd5b78b0..73ff48c1963 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -529,7 +529,7 @@ fetch_finfo_record(void *filehandle, const char *funcname) static CFuncHashTabEntry * lookup_C_func(HeapTuple procedureTuple) { - Oid fn_oid = HeapTupleGetOid(procedureTuple); + Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid; CFuncHashTabEntry *entry; if (CFuncHash == NULL) @@ -554,7 +554,7 @@ static void record_C_func(HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec) { - Oid fn_oid = HeapTupleGetOid(procedureTuple); + Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid; CFuncHashTabEntry *entry; bool found; diff --git a/src/backend/utils/fmgr/funcapi.c b/src/backend/utils/fmgr/funcapi.c index 30923518f5e..c4df255f101 100644 --- a/src/backend/utils/fmgr/funcapi.c +++ b/src/backend/utils/fmgr/funcapi.c @@ -1301,7 +1301,7 @@ build_function_result_tupdesc_d(char prokind, if (numoutargs < 2 && prokind != PROKIND_PROCEDURE) return NULL; - desc = CreateTemplateTupleDesc(numoutargs, false); + desc = CreateTemplateTupleDesc(numoutargs); for (i = 0; i < numoutargs; i++) { TupleDescInitEntry(desc, i + 1, @@ -1421,7 +1421,7 @@ TypeGetTupleDesc(Oid typeoid, List *colaliases) /* OK, get the column alias */ attname = strVal(linitial(colaliases)); - tupdesc = CreateTemplateTupleDesc(1, false); + tupdesc = CreateTemplateTupleDesc(1); TupleDescInitEntry(tupdesc, (AttrNumber) 1, attname, diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 238fe1deec8..3d10aa57079 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -616,7 +616,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid) } rform = (Form_pg_authid) GETSTRUCT(roleTup); - roleid = HeapTupleGetOid(roleTup); + roleid = rform->oid; rname = NameStr(rform->rolname); AuthenticatedUserId = roleid; diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 4f1d2a0d288..b636b1e262a 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -146,7 +146,7 @@ GetDatabaseTupleByOid(Oid dboid) * form a scan key */ ScanKeyInit(&key[0], - ObjectIdAttributeNumber, + Anum_pg_database_oid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(dboid)); @@ -885,7 +885,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, (errcode(ERRCODE_UNDEFINED_DATABASE), errmsg("database \"%s\" does not exist", in_dbname))); dbform = (Form_pg_database) GETSTRUCT(tuple); - MyDatabaseId = HeapTupleGetOid(tuple); + MyDatabaseId = dbform->oid; MyDatabaseTableSpace = dbform->dattablespace; /* take database name from the caller, just for paranoia */ strlcpy(dbname, in_dbname, sizeof(dbname)); @@ -902,7 +902,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, (errcode(ERRCODE_UNDEFINED_DATABASE), errmsg("database %u does not exist", dboid))); dbform = (Form_pg_database) GETSTRUCT(tuple); - MyDatabaseId = HeapTupleGetOid(tuple); + MyDatabaseId = dbform->oid; MyDatabaseTableSpace = dbform->dattablespace; Assert(MyDatabaseId == dboid); strlcpy(dbname, NameStr(dbform->datname), sizeof(dbname)); @@ -984,7 +984,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, tuple = GetDatabaseTuple(dbname); if (!HeapTupleIsValid(tuple) || - MyDatabaseId != HeapTupleGetOid(tuple) || + MyDatabaseId != ((Form_pg_database) GETSTRUCT(tuple))->oid || MyDatabaseTableSpace != ((Form_pg_database) GETSTRUCT(tuple))->dattablespace) ereport(FATAL, (errcode(ERRCODE_UNDEFINED_DATABASE), diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 19c678f596f..0ec3ff0fd6b 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -464,7 +464,6 @@ char *event_source; bool row_security; bool check_function_bodies = true; -bool default_with_oids = false; bool session_auth_is_superuser; int log_min_error_statement = ERROR; @@ -1513,15 +1512,6 @@ static struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, { - {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS, - gettext_noop("Create new tables with OIDs by default."), - NULL - }, - &default_with_oids, - false, - NULL, NULL, NULL - }, - { {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE, gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."), NULL @@ -8260,7 +8250,7 @@ GetPGVariableResultDesc(const char *name) if (guc_name_compare(name, "all") == 0) { /* need a tuple descriptor representing three TEXT columns */ - tupdesc = CreateTemplateTupleDesc(3, false); + tupdesc = CreateTemplateTupleDesc(3); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting", @@ -8276,7 +8266,7 @@ GetPGVariableResultDesc(const char *name) (void) GetConfigOptionByName(name, &varname, false); /* need a tuple descriptor representing a single TEXT column */ - tupdesc = CreateTemplateTupleDesc(1, false); + tupdesc = CreateTemplateTupleDesc(1); TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname, TEXTOID, -1, 0); } @@ -8299,7 +8289,7 @@ ShowGUCConfigOption(const char *name, DestReceiver *dest) value = GetConfigOptionByName(name, &varname, false); /* need a tuple descriptor representing a single TEXT column */ - tupdesc = CreateTemplateTupleDesc(1, false); + tupdesc = CreateTemplateTupleDesc(1); TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 1, varname, TEXTOID, -1, 0); @@ -8325,7 +8315,7 @@ ShowAllGUCConfig(DestReceiver *dest) bool isnull[3] = {false, false, false}; /* need a tuple descriptor representing three TEXT columns */ - tupdesc = CreateTemplateTupleDesc(3, false); + tupdesc = CreateTemplateTupleDesc(3); TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 1, "name", TEXTOID, -1, 0); TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 2, "setting", @@ -8767,7 +8757,7 @@ show_all_settings(PG_FUNCTION_ARGS) * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns * of the appropriate types */ - tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false); + tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting", @@ -8907,7 +8897,7 @@ show_all_file_settings(PG_FUNCTION_ARGS) oldcontext = MemoryContextSwitchTo(per_query_ctx); /* Build a tuple descriptor for our result type */ - tupdesc = CreateTemplateTupleDesc(NUM_PG_FILE_SETTINGS_ATTS, false); + tupdesc = CreateTemplateTupleDesc(NUM_PG_FILE_SETTINGS_ATTS); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "sourcefile", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "sourceline", diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c index 3fc8b6a8a84..a3768752698 100644 --- a/src/backend/utils/misc/pg_controldata.c +++ b/src/backend/utils/misc/pg_controldata.c @@ -41,7 +41,7 @@ pg_control_system(PG_FUNCTION_ARGS) * Construct a tuple descriptor for the result row. This must match this * function's pg_proc entry! */ - tupdesc = CreateTemplateTupleDesc(4, false); + tupdesc = CreateTemplateTupleDesc(4); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "pg_control_version", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "catalog_version_no", @@ -91,7 +91,7 @@ pg_control_checkpoint(PG_FUNCTION_ARGS) * Construct a tuple descriptor for the result row. This must match this * function's pg_proc entry! */ - tupdesc = CreateTemplateTupleDesc(18, false); + tupdesc = CreateTemplateTupleDesc(18); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "checkpoint_lsn", LSNOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "redo_lsn", @@ -221,7 +221,7 @@ pg_control_recovery(PG_FUNCTION_ARGS) * Construct a tuple descriptor for the result row. This must match this * function's pg_proc entry! */ - tupdesc = CreateTemplateTupleDesc(5, false); + tupdesc = CreateTemplateTupleDesc(5); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "min_recovery_end_lsn", LSNOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "min_recovery_end_timeline", @@ -274,7 +274,7 @@ pg_control_init(PG_FUNCTION_ARGS) * Construct a tuple descriptor for the result row. This must match this * function's pg_proc entry! */ - tupdesc = CreateTemplateTupleDesc(12, false); + tupdesc = CreateTemplateTupleDesc(12); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "max_data_alignment", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "database_block_size", diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 26d5c4c9677..3038fe627b2 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -649,7 +649,6 @@ #array_nulls = on #backslash_quote = safe_encoding # on, off, or safe_encoding -#default_with_oids = off #escape_string_warning = on #lo_compat_privileges = off #operator_precedence_warning = off diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c index d34cab0eb88..2b014c86bd1 100644 --- a/src/backend/utils/mmgr/portalmem.c +++ b/src/backend/utils/mmgr/portalmem.c @@ -1146,7 +1146,7 @@ pg_cursor(PG_FUNCTION_ARGS) * build tupdesc for result tuples. This must match the definition of the * pg_cursors view in system_views.sql */ - tupdesc = CreateTemplateTupleDesc(6, false); + tupdesc = CreateTemplateTupleDesc(6); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "statement", |