Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/alter.c8
-rw-r--r--src/backend/commands/amcmds.c10
-rw-r--r--src/backend/commands/cluster.c16
-rw-r--r--src/backend/commands/copy.c142
-rw-r--r--src/backend/commands/createas.c21
-rw-r--r--src/backend/commands/dbcommands.c40
-rw-r--r--src/backend/commands/event_trigger.c28
-rw-r--r--src/backend/commands/explain.c2
-rw-r--r--src/backend/commands/extension.c24
-rw-r--r--src/backend/commands/foreigncmds.c45
-rw-r--r--src/backend/commands/functioncmds.c26
-rw-r--r--src/backend/commands/indexcmds.c27
-rw-r--r--src/backend/commands/matview.c5
-rw-r--r--src/backend/commands/opclasscmds.c47
-rw-r--r--src/backend/commands/policy.c18
-rw-r--r--src/backend/commands/prepare.c2
-rw-r--r--src/backend/commands/proclang.c18
-rw-r--r--src/backend/commands/publicationcmds.c39
-rw-r--r--src/backend/commands/schemacmds.c20
-rw-r--r--src/backend/commands/sequence.c2
-rw-r--r--src/backend/commands/statscmds.c13
-rw-r--r--src/backend/commands/subscriptioncmds.c31
-rw-r--r--src/backend/commands/tablecmds.c319
-rw-r--r--src/backend/commands/tablespace.c23
-rw-r--r--src/backend/commands/trigger.c35
-rw-r--r--src/backend/commands/tsearchcmds.c68
-rw-r--r--src/backend/commands/typecmds.c38
-rw-r--r--src/backend/commands/user.c42
-rw-r--r--src/backend/commands/vacuum.c6
-rw-r--r--src/backend/commands/vacuumlazy.c6
-rw-r--r--src/backend/commands/variable.c12
-rw-r--r--src/backend/commands/view.c1
32 files changed, 451 insertions, 683 deletions
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index eff325cc7d0..21e9d3916a1 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -903,6 +903,7 @@ void
AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
{
Oid classId = RelationGetRelid(rel);
+ AttrNumber Anum_oid = get_object_attnum_oid(classId);
AttrNumber Anum_owner = get_object_attnum_owner(classId);
AttrNumber Anum_namespace = get_object_attnum_namespace(classId);
AttrNumber Anum_acl = get_object_attnum_acl(classId);
@@ -913,7 +914,7 @@ AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
Oid old_ownerId;
Oid namespaceId = InvalidOid;
- oldtup = get_catalog_object_by_oid(rel, objectId);
+ oldtup = get_catalog_object_by_oid(rel, Anum_oid, objectId);
if (oldtup == NULL)
elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"",
objectId, RelationGetRelationName(rel));
@@ -959,8 +960,7 @@ AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
}
else
{
- snprintf(namebuf, sizeof(namebuf), "%u",
- HeapTupleGetOid(oldtup));
+ snprintf(namebuf, sizeof(namebuf), "%u", objectId);
objname = namebuf;
}
aclcheck_error(ACLCHECK_NOT_OWNER, objtype, objname);
@@ -1017,7 +1017,7 @@ AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
/* Update owner dependency reference */
if (classId == LargeObjectMetadataRelationId)
classId = LargeObjectRelationId;
- changeDependencyOnOwner(classId, HeapTupleGetOid(newtup), new_ownerId);
+ changeDependencyOnOwner(classId, objectId, new_ownerId);
/* Release memory */
pfree(values);
diff --git a/src/backend/commands/amcmds.c b/src/backend/commands/amcmds.c
index f2173450ad3..4367290a27c 100644
--- a/src/backend/commands/amcmds.c
+++ b/src/backend/commands/amcmds.c
@@ -15,6 +15,7 @@
#include "access/heapam.h"
#include "access/htup_details.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/pg_am.h"
@@ -60,7 +61,8 @@ CreateAccessMethod(CreateAmStmt *stmt)
errhint("Must be superuser to create an access method.")));
/* Check if name is used */
- amoid = GetSysCacheOid1(AMNAME, CStringGetDatum(stmt->amname));
+ amoid = GetSysCacheOid1(AMNAME, Anum_pg_am_oid,
+ CStringGetDatum(stmt->amname));
if (OidIsValid(amoid))
{
ereport(ERROR,
@@ -80,6 +82,8 @@ CreateAccessMethod(CreateAmStmt *stmt)
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ amoid = GetNewOidWithIndex(rel, AmOidIndexId, Anum_pg_am_oid);
+ values[Anum_pg_am_oid - 1] = ObjectIdGetDatum(amoid);
values[Anum_pg_am_amname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(stmt->amname));
values[Anum_pg_am_amhandler - 1] = ObjectIdGetDatum(amhandler);
@@ -87,7 +91,7 @@ CreateAccessMethod(CreateAmStmt *stmt)
tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
- amoid = CatalogTupleInsert(rel, tup);
+ CatalogTupleInsert(rel, tup);
heap_freetuple(tup);
myself.classId = AccessMethodRelationId;
@@ -164,7 +168,7 @@ get_am_type_oid(const char *amname, char amtype, bool missing_ok)
NameStr(amform->amname),
get_am_type_string(amtype))));
- oid = HeapTupleGetOid(tup);
+ oid = amform->oid;
ReleaseSysCache(tup);
}
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index 5ecd2565b4d..610e425a566 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -75,7 +75,7 @@ static List *get_tables_to_cluster(MemoryContext cluster_context);
static void reform_and_rewrite_tuple(HeapTuple tuple,
TupleDesc oldTupDesc, TupleDesc newTupDesc,
Datum *values, bool *isnull,
- bool newRelHasOids, RewriteState rwstate);
+ RewriteState rwstate);
/*---------------------------------------------------------------------------
@@ -688,8 +688,6 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, char relpersistence,
relpersistence,
false,
RelationIsMapped(OldHeap),
- true,
- 0,
ONCOMMIT_NOOP,
reloptions,
false,
@@ -1061,7 +1059,7 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
reform_and_rewrite_tuple(tuple,
oldTupDesc, newTupDesc,
values, isnull,
- NewHeap->rd_rel->relhasoids, rwstate);
+ rwstate);
}
if (indexScan != NULL)
@@ -1090,7 +1088,7 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
reform_and_rewrite_tuple(tuple,
oldTupDesc, newTupDesc,
values, isnull,
- NewHeap->rd_rel->relhasoids, rwstate);
+ rwstate);
}
tuplesort_end(tuplesort);
@@ -1755,7 +1753,7 @@ get_tables_to_cluster(MemoryContext cluster_context)
*
* 2. The tuple might not even be legal for the new table; this is
* currently only known to happen as an after-effect of ALTER TABLE
- * SET WITHOUT OIDS.
+ * SET WITHOUT OIDS (in an older version, via pg_upgrade).
*
* So, we must reconstruct the tuple from component Datums.
*/
@@ -1763,7 +1761,7 @@ static void
reform_and_rewrite_tuple(HeapTuple tuple,
TupleDesc oldTupDesc, TupleDesc newTupDesc,
Datum *values, bool *isnull,
- bool newRelHasOids, RewriteState rwstate)
+ RewriteState rwstate)
{
HeapTuple copiedTuple;
int i;
@@ -1779,10 +1777,6 @@ reform_and_rewrite_tuple(HeapTuple tuple,
copiedTuple = heap_form_tuple(newTupDesc, values, isnull);
- /* Preserve OID, if any */
- if (newRelHasOids)
- HeapTupleSetOid(copiedTuple, HeapTupleGetOid(tuple));
-
/* The heap rewrite module does the rest */
rewrite_heap_tuple(rwstate, tuple, copiedTuple);
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index a283fcb33ad..4aa8890fe81 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -131,7 +131,6 @@ typedef struct CopyStateData
bool is_program; /* is 'filename' a program to popen? */
copy_data_source_cb data_source_cb; /* function for reading data */
bool binary; /* binary format? */
- bool oids; /* include OIDs? */
bool freeze; /* freeze rows on loading? */
bool csv_mode; /* Comma Separated Value format? */
bool header_line; /* CSV header line? */
@@ -173,7 +172,6 @@ typedef struct CopyStateData
* Working state for COPY FROM
*/
AttrNumber num_defaults;
- bool file_has_oids;
FmgrInfo oid_in_function;
Oid oid_typioparam;
FmgrInfo *in_functions; /* array of input functions for each attrs */
@@ -313,7 +311,7 @@ static CopyState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *query,
static void EndCopyTo(CopyState cstate);
static uint64 DoCopyTo(CopyState cstate);
static uint64 CopyTo(CopyState cstate);
-static void CopyOneRowTo(CopyState cstate, Oid tupleOid,
+static void CopyOneRowTo(CopyState cstate,
Datum *values, bool *nulls);
static void CopyFromInsertBatch(CopyState cstate, EState *estate,
CommandId mycid, int hi_options,
@@ -1086,15 +1084,6 @@ ProcessCopyOptions(ParseState *pstate,
errmsg("COPY format \"%s\" not recognized", fmt),
parser_errposition(pstate, defel->location)));
}
- else if (strcmp(defel->defname, "oids") == 0)
- {
- if (cstate->oids)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("conflicting or redundant options"),
- parser_errposition(pstate, defel->location)));
- cstate->oids = defGetBoolean(defel);
- }
else if (strcmp(defel->defname, "freeze") == 0)
{
if (cstate->freeze)
@@ -1440,13 +1429,6 @@ BeginCopy(ParseState *pstate,
cstate->rel = rel;
tupDesc = RelationGetDescr(cstate->rel);
-
- /* Don't allow COPY w/ OIDs to or from a table without them */
- if (cstate->oids && !cstate->rel->rd_rel->relhasoids)
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_COLUMN),
- errmsg("table \"%s\" does not have OIDs",
- RelationGetRelationName(cstate->rel))));
}
else
{
@@ -1458,12 +1440,6 @@ BeginCopy(ParseState *pstate,
Assert(!is_from);
cstate->rel = NULL;
- /* Don't allow COPY w/ OIDs from a query */
- if (cstate->oids)
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("COPY (query) WITH OIDS is not supported")));
-
/*
* Run parse analysis and rewrite. Note this also acquires sufficient
* locks on the source table(s).
@@ -2028,8 +2004,6 @@ CopyTo(CopyState cstate)
CopySendData(cstate, BinarySignature, 11);
/* Flags field */
tmp = 0;
- if (cstate->oids)
- tmp |= (1 << 16);
CopySendInt32(cstate, tmp);
/* No header extension */
tmp = 0;
@@ -2091,7 +2065,7 @@ CopyTo(CopyState cstate)
heap_deform_tuple(tuple, tupDesc, values, nulls);
/* Format and send the data */
- CopyOneRowTo(cstate, HeapTupleGetOid(tuple), values, nulls);
+ CopyOneRowTo(cstate, values, nulls);
processed++;
}
@@ -2124,7 +2098,7 @@ CopyTo(CopyState cstate)
* Emit one row during CopyTo().
*/
static void
-CopyOneRowTo(CopyState cstate, Oid tupleOid, Datum *values, bool *nulls)
+CopyOneRowTo(CopyState cstate, Datum *values, bool *nulls)
{
bool need_delim = false;
FmgrInfo *out_functions = cstate->out_functions;
@@ -2139,25 +2113,6 @@ CopyOneRowTo(CopyState cstate, Oid tupleOid, Datum *values, bool *nulls)
{
/* Binary per-tuple header */
CopySendInt16(cstate, list_length(cstate->attnumlist));
- /* Send OID if wanted --- note attnumlist doesn't include it */
- if (cstate->oids)
- {
- /* Hack --- assume Oid is same size as int32 */
- CopySendInt32(cstate, sizeof(int32));
- CopySendInt32(cstate, tupleOid);
- }
- }
- else
- {
- /* Text format has no per-tuple header, but send OID if wanted */
- /* Assume digits don't need any quoting or encoding conversion */
- if (cstate->oids)
- {
- string = DatumGetCString(DirectFunctionCall1(oidout,
- ObjectIdGetDatum(tupleOid)));
- CopySendString(cstate, string);
- need_delim = true;
- }
}
foreach(cur, cstate->attnumlist)
@@ -2689,7 +2644,6 @@ CopyFrom(CopyState cstate)
{
TupleTableSlot *slot;
bool skip_tuple;
- Oid loaded_oid = InvalidOid;
CHECK_FOR_INTERRUPTS();
@@ -2706,15 +2660,12 @@ CopyFrom(CopyState cstate)
/* Switch into its memory context */
MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
- if (!NextCopyFrom(cstate, econtext, values, nulls, &loaded_oid))
+ if (!NextCopyFrom(cstate, econtext, values, nulls))
break;
/* And now we can form the input tuple. */
tuple = heap_form_tuple(tupDesc, values, nulls);
- if (loaded_oid != InvalidOid)
- HeapTupleSetOid(tuple, loaded_oid);
-
/*
* Constraints might reference the tableoid column, so initialize
* t_tableOid before evaluating them.
@@ -3368,12 +3319,7 @@ BeginCopyFrom(ParseState *pstate,
}
}
- if (!cstate->binary)
- {
- /* must rely on user to tell us... */
- cstate->file_has_oids = cstate->oids;
- }
- else
+ if (cstate->binary)
{
/* Read and verify binary header */
char readSig[11];
@@ -3390,7 +3336,10 @@ BeginCopyFrom(ParseState *pstate,
ereport(ERROR,
(errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
errmsg("invalid COPY file header (missing flags)")));
- cstate->file_has_oids = (tmp & (1 << 16)) != 0;
+ if ((tmp & (1 << 16)) != 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
+ errmsg("invalid COPY file header (WITH OIDS)")));
tmp &= ~(1 << 16);
if ((tmp >> 16) != 0)
ereport(ERROR,
@@ -3412,21 +3361,13 @@ BeginCopyFrom(ParseState *pstate,
}
}
- if (cstate->file_has_oids && cstate->binary)
- {
- getTypeBinaryInputInfo(OIDOID,
- &in_func_oid, &cstate->oid_typioparam);
- fmgr_info(in_func_oid, &cstate->oid_in_function);
- }
-
/* create workspace for CopyReadAttributes results */
if (!cstate->binary)
{
AttrNumber attr_count = list_length(cstate->attnumlist);
- int nfields = cstate->file_has_oids ? (attr_count + 1) : attr_count;
- cstate->max_fields = nfields;
- cstate->raw_fields = (char **) palloc(nfields * sizeof(char *));
+ cstate->max_fields = attr_count;
+ cstate->raw_fields = (char **) palloc(attr_count * sizeof(char *));
}
MemoryContextSwitchTo(oldcontext);
@@ -3499,7 +3440,7 @@ NextCopyFromRawFields(CopyState cstate, char ***fields, int *nfields)
*/
bool
NextCopyFrom(CopyState cstate, ExprContext *econtext,
- Datum *values, bool *nulls, Oid *tupleOid)
+ Datum *values, bool *nulls)
{
TupleDesc tupDesc;
AttrNumber num_phys_attrs,
@@ -3508,16 +3449,12 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
FmgrInfo *in_functions = cstate->in_functions;
Oid *typioparams = cstate->typioparams;
int i;
- int nfields;
- bool isnull;
- bool file_has_oids = cstate->file_has_oids;
int *defmap = cstate->defmap;
ExprState **defexprs = cstate->defexprs;
tupDesc = RelationGetDescr(cstate->rel);
num_phys_attrs = tupDesc->natts;
attr_count = list_length(cstate->attnumlist);
- nfields = file_has_oids ? (attr_count + 1) : attr_count;
/* Initialize all values for row to NULL */
MemSet(values, 0, num_phys_attrs * sizeof(Datum));
@@ -3536,41 +3473,13 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
return false;
/* check for overflowing fields */
- if (nfields > 0 && fldct > nfields)
+ if (attr_count > 0 && fldct > attr_count)
ereport(ERROR,
(errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
errmsg("extra data after last expected column")));
fieldno = 0;
- /* Read the OID field if present */
- if (file_has_oids)
- {
- if (fieldno >= fldct)
- ereport(ERROR,
- (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
- errmsg("missing data for OID column")));
- string = field_strings[fieldno++];
-
- if (string == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
- errmsg("null OID in COPY data")));
- else if (cstate->oids && tupleOid != NULL)
- {
- cstate->cur_attname = "oid";
- cstate->cur_attval = string;
- *tupleOid = DatumGetObjectId(DirectFunctionCall1(oidin,
- CStringGetDatum(string)));
- if (*tupleOid == InvalidOid)
- ereport(ERROR,
- (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
- errmsg("invalid OID in COPY data")));
- cstate->cur_attname = NULL;
- cstate->cur_attval = NULL;
- }
- }
-
/* Loop to read the user attributes on the line. */
foreach(cur, cstate->attnumlist)
{
@@ -3628,7 +3537,7 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
cstate->cur_attval = NULL;
}
- Assert(fieldno == nfields);
+ Assert(fieldno == attr_count);
}
else
{
@@ -3674,27 +3583,6 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
errmsg("row field count is %d, expected %d",
(int) fld_count, attr_count)));
- if (file_has_oids)
- {
- Oid loaded_oid;
-
- cstate->cur_attname = "oid";
- loaded_oid =
- DatumGetObjectId(CopyReadBinaryAttribute(cstate,
- 0,
- &cstate->oid_in_function,
- cstate->oid_typioparam,
- -1,
- &isnull));
- if (isnull || loaded_oid == InvalidOid)
- ereport(ERROR,
- (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
- errmsg("invalid OID in COPY data")));
- cstate->cur_attname = NULL;
- if (cstate->oids && tupleOid != NULL)
- *tupleOid = loaded_oid;
- }
-
i = 0;
foreach(cur, cstate->attnumlist)
{
@@ -5022,7 +4910,7 @@ copy_dest_receive(TupleTableSlot *slot, DestReceiver *self)
slot_getallattrs(slot);
/* And send the data */
- CopyOneRowTo(cstate, InvalidOid, slot->tts_values, slot->tts_isnull);
+ CopyOneRowTo(cstate, slot->tts_values, slot->tts_isnull);
myState->processed++;
return true;
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 7b60aa9e282..d01b258b654 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -391,20 +391,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
int
GetIntoRelEFlags(IntoClause *intoClause)
{
- int flags;
-
- /*
- * We need to tell the executor whether it has to produce OIDs or not,
- * because it doesn't have enough information to do so itself (since we
- * can't build the target relation until after ExecutorStart).
- *
- * Disallow the OIDS option for materialized views.
- */
- if (interpretOidsOption(intoClause->options,
- (intoClause->viewQuery == NULL)))
- flags = EXEC_FLAG_WITH_OIDS;
- else
- flags = EXEC_FLAG_WITHOUT_OIDS;
+ int flags = 0;
if (intoClause->skipData)
flags |= EXEC_FLAG_WITH_NO_DATA;
@@ -591,12 +578,6 @@ intorel_receive(TupleTableSlot *slot, DestReceiver *self)
*/
tuple = ExecCopySlotHeapTuple(slot);
- /*
- * force assignment of new OID (see comments in ExecInsert)
- */
- if (myState->rel->rd_rel->relhasoids)
- HeapTupleSetOid(tuple, InvalidOid);
-
heap_insert(myState->rel,
tuple,
myState->output_cid,
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 5342f217c02..f640f469729 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -504,7 +504,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
do
{
- dboid = GetNewOid(pg_database_rel);
+ dboid = GetNewOidWithIndex(pg_database_rel, DatabaseOidIndexId,
+ Anum_pg_database_oid);
} while (check_db_file_conflict(dboid));
/*
@@ -517,6 +518,7 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
MemSet(new_record, 0, sizeof(new_record));
MemSet(new_record_nulls, false, sizeof(new_record_nulls));
+ new_record[Anum_pg_database_oid - 1] = ObjectIdGetDatum(dboid);
new_record[Anum_pg_database_datname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(dbname));
new_record[Anum_pg_database_datdba - 1] = ObjectIdGetDatum(datdba);
@@ -543,8 +545,6 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
tuple = heap_form_tuple(RelationGetDescr(pg_database_rel),
new_record, new_record_nulls);
- HeapTupleSetOid(tuple, dboid);
-
CatalogTupleInsert(pg_database_rel, tuple);
/*
@@ -593,7 +593,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
scan = heap_beginscan_catalog(rel, 0, NULL);
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
- Oid srctablespace = HeapTupleGetOid(tuple);
+ Form_pg_tablespace spaceform = (Form_pg_tablespace) GETSTRUCT(tuple);
+ Oid srctablespace = spaceform->oid;
Oid dsttablespace;
char *srcpath;
char *dstpath;
@@ -1301,8 +1302,7 @@ movedb(const char *dbname, const char *tblspcname)
new_record_nulls, new_record_repl);
CatalogTupleUpdate(pgdbrel, &oldtuple->t_self, newtuple);
- InvokeObjectPostAlterHook(DatabaseRelationId,
- HeapTupleGetOid(newtuple), 0);
+ InvokeObjectPostAlterHook(DatabaseRelationId, db_id, 0);
systable_endscan(sysscan);
@@ -1400,6 +1400,7 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Oid dboid;
HeapTuple tuple,
newtuple;
+ Form_pg_database datform;
ScanKeyData scankey;
SysScanDesc scan;
ListCell *option;
@@ -1512,9 +1513,10 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", stmt->dbname)));
- dboid = HeapTupleGetOid(tuple);
+ datform = (Form_pg_database) GETSTRUCT(tuple);
+ dboid = datform->oid;
- if (!pg_database_ownercheck(HeapTupleGetOid(tuple), GetUserId()))
+ if (!pg_database_ownercheck(dboid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_DATABASE,
stmt->dbname);
@@ -1556,8 +1558,7 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
new_record_nulls, new_record_repl);
CatalogTupleUpdate(rel, &tuple->t_self, newtuple);
- InvokeObjectPostAlterHook(DatabaseRelationId,
- HeapTupleGetOid(newtuple), 0);
+ InvokeObjectPostAlterHook(DatabaseRelationId, dboid, 0);
systable_endscan(scan);
@@ -1626,8 +1627,8 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", dbname)));
- db_id = HeapTupleGetOid(tuple);
datForm = (Form_pg_database) GETSTRUCT(tuple);
+ db_id = datForm->oid;
/*
* If the new owner is the same as the existing owner, consider the
@@ -1645,7 +1646,7 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
HeapTuple newtuple;
/* Otherwise, must be owner of the existing object */
- if (!pg_database_ownercheck(HeapTupleGetOid(tuple), GetUserId()))
+ if (!pg_database_ownercheck(db_id, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_DATABASE,
dbname);
@@ -1694,11 +1695,10 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
heap_freetuple(newtuple);
/* Update owner dependency reference */
- changeDependencyOnOwner(DatabaseRelationId, HeapTupleGetOid(tuple),
- newOwnerId);
+ changeDependencyOnOwner(DatabaseRelationId, db_id, newOwnerId);
}
- InvokeObjectPostAlterHook(DatabaseRelationId, HeapTupleGetOid(tuple), 0);
+ InvokeObjectPostAlterHook(DatabaseRelationId, db_id, 0);
ObjectAddressSet(address, DatabaseRelationId, db_id);
@@ -1770,7 +1770,7 @@ get_db_info(const char *name, LOCKMODE lockmode,
break;
}
- dbOid = HeapTupleGetOid(tuple);
+ dbOid = ((Form_pg_database) GETSTRUCT(tuple))->oid;
systable_endscan(scan);
@@ -1878,7 +1878,8 @@ remove_dbtablespaces(Oid db_id)
scan = heap_beginscan_catalog(rel, 0, NULL);
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
- Oid dsttablespace = HeapTupleGetOid(tuple);
+ Form_pg_tablespace spcform = (Form_pg_tablespace) GETSTRUCT(tuple);
+ Oid dsttablespace = spcform->oid;
char *dstpath;
struct stat st;
@@ -1945,7 +1946,8 @@ check_db_file_conflict(Oid db_id)
scan = heap_beginscan_catalog(rel, 0, NULL);
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
- Oid dsttablespace = HeapTupleGetOid(tuple);
+ Form_pg_tablespace spcform = (Form_pg_tablespace) GETSTRUCT(tuple);
+ Oid dsttablespace = spcform->oid;
char *dstpath;
struct stat st;
@@ -2030,7 +2032,7 @@ get_database_oid(const char *dbname, bool missing_ok)
/* We assume that there can be at most one matching tuple */
if (HeapTupleIsValid(dbtuple))
- oid = HeapTupleGetOid(dbtuple);
+ oid = ((Form_pg_database)GETSTRUCT(dbtuple))->oid;
else
oid = InvalidOid;
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index 20a3a786929..3e7c1067d8e 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -15,6 +15,7 @@
#include "access/htup_details.h"
#include "access/xact.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
@@ -391,6 +392,9 @@ insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtO
tgrel = heap_open(EventTriggerRelationId, RowExclusiveLock);
/* Build the new pg_trigger tuple. */
+ trigoid = GetNewOidWithIndex(tgrel, EventTriggerOidIndexId,
+ Anum_pg_event_trigger_oid);
+ values[Anum_pg_event_trigger_oid - 1] = ObjectIdGetDatum(trigoid);
memset(nulls, false, sizeof(nulls));
namestrcpy(&evtnamedata, trigname);
values[Anum_pg_event_trigger_evtname - 1] = NameGetDatum(&evtnamedata);
@@ -408,7 +412,7 @@ insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtO
/* Insert heap tuple. */
tuple = heap_form_tuple(tgrel->rd_att, values, nulls);
- trigoid = CatalogTupleInsert(tgrel, tuple);
+ CatalogTupleInsert(tgrel, tuple);
heap_freetuple(tuple);
/* Depend on owner. */
@@ -516,14 +520,14 @@ AlterEventTrigger(AlterEventTrigStmt *stmt)
errmsg("event trigger \"%s\" does not exist",
stmt->trigname)));
- trigoid = HeapTupleGetOid(tup);
+ evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
+ trigoid = evtForm->oid;
if (!pg_event_trigger_ownercheck(trigoid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_EVENT_TRIGGER,
stmt->trigname);
/* tuple is a copy, so we can modify it below */
- evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
evtForm->evtenabled = tgenabled;
CatalogTupleUpdate(tgrel, &tup->t_self, tup);
@@ -546,6 +550,7 @@ AlterEventTriggerOwner(const char *name, Oid newOwnerId)
{
Oid evtOid;
HeapTuple tup;
+ Form_pg_event_trigger evtForm;
Relation rel;
ObjectAddress address;
@@ -558,7 +563,8 @@ AlterEventTriggerOwner(const char *name, Oid newOwnerId)
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("event trigger \"%s\" does not exist", name)));
- evtOid = HeapTupleGetOid(tup);
+ evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
+ evtOid = evtForm->oid;
AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
@@ -609,7 +615,7 @@ AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
if (form->evtowner == newOwnerId)
return;
- if (!pg_event_trigger_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ if (!pg_event_trigger_ownercheck(form->oid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_EVENT_TRIGGER,
NameStr(form->evtname));
@@ -626,11 +632,11 @@ AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
/* Update owner dependency reference */
changeDependencyOnOwner(EventTriggerRelationId,
- HeapTupleGetOid(tup),
+ form->oid,
newOwnerId);
InvokeObjectPostAlterHook(EventTriggerRelationId,
- HeapTupleGetOid(tup), 0);
+ form->oid, 0);
}
/*
@@ -644,7 +650,8 @@ get_event_trigger_oid(const char *trigname, bool missing_ok)
{
Oid oid;
- oid = GetSysCacheOid1(EVENTTRIGGERNAME, CStringGetDatum(trigname));
+ oid = GetSysCacheOid1(EVENTTRIGGERNAME, Anum_pg_event_trigger_oid,
+ CStringGetDatum(trigname));
if (!OidIsValid(oid) && !missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
@@ -1357,7 +1364,9 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
HeapTuple tuple;
catalog = heap_open(obj->address.classId, AccessShareLock);
- tuple = get_catalog_object_by_oid(catalog, obj->address.objectId);
+ tuple = get_catalog_object_by_oid(catalog,
+ get_object_attnum_oid(object->classId),
+ obj->address.objectId);
if (tuple)
{
@@ -2106,6 +2115,7 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
catalog = heap_open(addr.classId, AccessShareLock);
objtup = get_catalog_object_by_oid(catalog,
+ get_object_attnum_oid(addr.classId),
addr.objectId);
if (!HeapTupleIsValid(objtup))
elog(ERROR, "cache lookup failed for object %u/%u",
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index ab2c84ff98a..de09ded65b9 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -324,7 +324,7 @@ ExplainResultDesc(ExplainStmt *stmt)
}
/* Need a tuple descriptor representing a single TEXT or XML column */
- tupdesc = CreateTemplateTupleDesc(1, false);
+ tupdesc = CreateTemplateTupleDesc(1);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "QUERY PLAN",
result_type, -1, 0);
return tupdesc;
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
index 560064d3e1f..a587a1bc03e 100644
--- a/src/backend/commands/extension.c
+++ b/src/backend/commands/extension.c
@@ -32,6 +32,7 @@
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "access/xact.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
@@ -154,7 +155,7 @@ get_extension_oid(const char *extname, bool missing_ok)
/* We assume that there can be at most one matching tuple */
if (HeapTupleIsValid(tuple))
- result = HeapTupleGetOid(tuple);
+ result = ((Form_pg_extension) GETSTRUCT(tuple))->oid;
else
result = InvalidOid;
@@ -188,7 +189,7 @@ get_extension_name(Oid ext_oid)
rel = heap_open(ExtensionRelationId, AccessShareLock);
ScanKeyInit(&entry[0],
- ObjectIdAttributeNumber,
+ Anum_pg_extension_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(ext_oid));
@@ -227,7 +228,7 @@ get_extension_schema(Oid ext_oid)
rel = heap_open(ExtensionRelationId, AccessShareLock);
ScanKeyInit(&entry[0],
- ObjectIdAttributeNumber,
+ Anum_pg_extension_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(ext_oid));
@@ -1758,6 +1759,9 @@ InsertExtensionTuple(const char *extName, Oid extOwner,
memset(values, 0, sizeof(values));
memset(nulls, 0, sizeof(nulls));
+ extensionOid = GetNewOidWithIndex(rel, ExtensionOidIndexId,
+ Anum_pg_extension_oid);
+ values[Anum_pg_extension_oid - 1] = ObjectIdGetDatum(extensionOid);
values[Anum_pg_extension_extname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(extName));
values[Anum_pg_extension_extowner - 1] = ObjectIdGetDatum(extOwner);
@@ -1777,7 +1781,7 @@ InsertExtensionTuple(const char *extName, Oid extOwner,
tuple = heap_form_tuple(rel->rd_att, values, nulls);
- extensionOid = CatalogTupleInsert(rel, tuple);
+ CatalogTupleInsert(rel, tuple);
heap_freetuple(tuple);
heap_close(rel, RowExclusiveLock);
@@ -1848,7 +1852,7 @@ RemoveExtensionById(Oid extId)
rel = heap_open(ExtensionRelationId, RowExclusiveLock);
ScanKeyInit(&entry[0],
- ObjectIdAttributeNumber,
+ Anum_pg_extension_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(extId));
scandesc = systable_beginscan(rel, ExtensionOidIndexId, true,
@@ -2376,7 +2380,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
extRel = heap_open(ExtensionRelationId, RowExclusiveLock);
ScanKeyInit(&key[0],
- ObjectIdAttributeNumber,
+ Anum_pg_extension_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(CurrentExtensionObject));
@@ -2524,7 +2528,7 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
extRel = heap_open(ExtensionRelationId, RowExclusiveLock);
ScanKeyInit(&key[0],
- ObjectIdAttributeNumber,
+ Anum_pg_extension_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(extensionoid));
@@ -2723,7 +2727,7 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
extRel = heap_open(ExtensionRelationId, RowExclusiveLock);
ScanKeyInit(&key[0],
- ObjectIdAttributeNumber,
+ Anum_pg_extension_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(extensionOid));
@@ -2903,7 +2907,7 @@ ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt)
errmsg("extension \"%s\" does not exist",
stmt->extname)));
- extensionOid = HeapTupleGetOid(extTup);
+ extensionOid = ((Form_pg_extension) GETSTRUCT(extTup))->oid;
/*
* Determine the existing version we are updating from
@@ -3045,7 +3049,7 @@ ApplyExtensionUpdates(Oid extensionOid,
extRel = heap_open(ExtensionRelationId, RowExclusiveLock);
ScanKeyInit(&key[0],
- ObjectIdAttributeNumber,
+ Anum_pg_extension_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(extensionOid));
diff --git a/src/backend/commands/foreigncmds.c b/src/backend/commands/foreigncmds.c
index e5dd9958a4c..10e9d7f5629 100644
--- a/src/backend/commands/foreigncmds.c
+++ b/src/backend/commands/foreigncmds.c
@@ -17,6 +17,7 @@
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/xact.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
@@ -260,12 +261,12 @@ AlterForeignDataWrapperOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerI
/* Update owner dependency reference */
changeDependencyOnOwner(ForeignDataWrapperRelationId,
- HeapTupleGetOid(tup),
+ form->oid,
newOwnerId);
}
InvokeObjectPostAlterHook(ForeignDataWrapperRelationId,
- HeapTupleGetOid(tup), 0);
+ form->oid, 0);
}
/*
@@ -280,6 +281,8 @@ AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
HeapTuple tup;
Relation rel;
ObjectAddress address;
+ Form_pg_foreign_data_wrapper form;
+
rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
@@ -290,7 +293,8 @@ AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("foreign-data wrapper \"%s\" does not exist", name)));
- fdwId = HeapTupleGetOid(tup);
+ form = (Form_pg_foreign_data_wrapper) GETSTRUCT(tup);
+ fdwId = form->oid;
AlterForeignDataWrapperOwner_internal(rel, tup, newOwnerId);
@@ -354,7 +358,7 @@ AlterForeignServerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
Oid srvId;
AclResult aclresult;
- srvId = HeapTupleGetOid(tup);
+ srvId = form->oid;
/* Must be owner */
if (!pg_foreign_server_ownercheck(srvId, GetUserId()))
@@ -399,12 +403,12 @@ AlterForeignServerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
CatalogTupleUpdate(rel, &tup->t_self, tup);
/* Update owner dependency reference */
- changeDependencyOnOwner(ForeignServerRelationId, HeapTupleGetOid(tup),
+ changeDependencyOnOwner(ForeignServerRelationId, form->oid,
newOwnerId);
}
InvokeObjectPostAlterHook(ForeignServerRelationId,
- HeapTupleGetOid(tup), 0);
+ form->oid, 0);
}
/*
@@ -417,6 +421,7 @@ AlterForeignServerOwner(const char *name, Oid newOwnerId)
HeapTuple tup;
Relation rel;
ObjectAddress address;
+ Form_pg_foreign_server form;
rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
@@ -427,7 +432,8 @@ AlterForeignServerOwner(const char *name, Oid newOwnerId)
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("server \"%s\" does not exist", name)));
- servOid = HeapTupleGetOid(tup);
+ form = (Form_pg_foreign_server) GETSTRUCT(tup);
+ servOid = form->oid;
AlterForeignServerOwner_internal(rel, tup, newOwnerId);
@@ -601,6 +607,9 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ fdwId = GetNewOidWithIndex(rel, ForeignDataWrapperOidIndexId,
+ Anum_pg_foreign_data_wrapper_oid);
+ values[Anum_pg_foreign_data_wrapper_oid - 1] = ObjectIdGetDatum(fdwId);
values[Anum_pg_foreign_data_wrapper_fdwname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(stmt->fdwname));
values[Anum_pg_foreign_data_wrapper_fdwowner - 1] = ObjectIdGetDatum(ownerId);
@@ -627,7 +636,7 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
tuple = heap_form_tuple(rel->rd_att, values, nulls);
- fdwId = CatalogTupleInsert(rel, tuple);
+ CatalogTupleInsert(rel, tuple);
heap_freetuple(tuple);
@@ -706,7 +715,7 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
errmsg("foreign-data wrapper \"%s\" does not exist", stmt->fdwname)));
fdwForm = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp);
- fdwId = HeapTupleGetOid(tp);
+ fdwId = fdwForm->oid;
memset(repl_val, 0, sizeof(repl_val));
memset(repl_null, false, sizeof(repl_null));
@@ -915,6 +924,9 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ srvId = GetNewOidWithIndex(rel, ForeignServerOidIndexId,
+ Anum_pg_foreign_server_oid);
+ values[Anum_pg_foreign_server_oid - 1] = ObjectIdGetDatum(srvId);
values[Anum_pg_foreign_server_srvname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(stmt->servername));
values[Anum_pg_foreign_server_srvowner - 1] = ObjectIdGetDatum(ownerId);
@@ -950,7 +962,7 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
tuple = heap_form_tuple(rel->rd_att, values, nulls);
- srvId = CatalogTupleInsert(rel, tuple);
+ CatalogTupleInsert(rel, tuple);
heap_freetuple(tuple);
@@ -1003,8 +1015,8 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("server \"%s\" does not exist", stmt->servername)));
- srvId = HeapTupleGetOid(tp);
srvForm = (Form_pg_foreign_server) GETSTRUCT(tp);
+ srvId = srvForm->oid;
/*
* Only owner or a superuser can ALTER a SERVER.
@@ -1162,7 +1174,7 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
/*
* Check that the user mapping is unique within server.
*/
- umId = GetSysCacheOid2(USERMAPPINGUSERSERVER,
+ umId = GetSysCacheOid2(USERMAPPINGUSERSERVER, Anum_pg_user_mapping_oid,
ObjectIdGetDatum(useId),
ObjectIdGetDatum(srv->serverid));
@@ -1195,6 +1207,9 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ umId = GetNewOidWithIndex(rel, UserMappingOidIndexId,
+ Anum_pg_user_mapping_oid);
+ values[Anum_pg_user_mapping_oid - 1] = ObjectIdGetDatum(umId);
values[Anum_pg_user_mapping_umuser - 1] = ObjectIdGetDatum(useId);
values[Anum_pg_user_mapping_umserver - 1] = ObjectIdGetDatum(srv->serverid);
@@ -1211,7 +1226,7 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
tuple = heap_form_tuple(rel->rd_att, values, nulls);
- umId = CatalogTupleInsert(rel, tuple);
+ CatalogTupleInsert(rel, tuple);
heap_freetuple(tuple);
@@ -1273,7 +1288,7 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
srv = GetForeignServerByName(stmt->servername, false);
- umId = GetSysCacheOid2(USERMAPPINGUSERSERVER,
+ umId = GetSysCacheOid2(USERMAPPINGUSERSERVER, Anum_pg_user_mapping_oid,
ObjectIdGetDatum(useId),
ObjectIdGetDatum(srv->serverid));
if (!OidIsValid(umId))
@@ -1385,7 +1400,7 @@ RemoveUserMapping(DropUserMappingStmt *stmt)
return InvalidOid;
}
- umId = GetSysCacheOid2(USERMAPPINGUSERSERVER,
+ umId = GetSysCacheOid2(USERMAPPINGUSERSERVER, Anum_pg_user_mapping_oid,
ObjectIdGetDatum(useId),
ObjectIdGetDatum(srv->serverid));
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index f6e12a33532..ebece4d1d7e 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -36,6 +36,7 @@
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
@@ -938,8 +939,8 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
(PLTemplateExists(language) ?
errhint("Use CREATE EXTENSION to load the language into the database.") : 0)));
- languageOid = HeapTupleGetOid(languageTuple);
languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
+ languageOid = languageStruct->oid;
if (languageStruct->lanpltrusted)
{
@@ -1668,6 +1669,8 @@ CreateCast(CreateCastStmt *stmt)
format_type_be(targettypeid))));
/* ready to go */
+ castid = GetNewOidWithIndex(relation, CastOidIndexId, Anum_pg_cast_oid);
+ values[Anum_pg_cast_oid - 1] = ObjectIdGetDatum(castid);
values[Anum_pg_cast_castsource - 1] = ObjectIdGetDatum(sourcetypeid);
values[Anum_pg_cast_casttarget - 1] = ObjectIdGetDatum(targettypeid);
values[Anum_pg_cast_castfunc - 1] = ObjectIdGetDatum(funcid);
@@ -1678,7 +1681,7 @@ CreateCast(CreateCastStmt *stmt)
tuple = heap_form_tuple(RelationGetDescr(relation), values, nulls);
- castid = CatalogTupleInsert(relation, tuple);
+ CatalogTupleInsert(relation, tuple);
/* make dependency entries */
myself.classId = CastRelationId;
@@ -1730,7 +1733,7 @@ get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
{
Oid oid;
- oid = GetSysCacheOid2(CASTSOURCETARGET,
+ oid = GetSysCacheOid2(CASTSOURCETARGET, Anum_pg_cast_oid,
ObjectIdGetDatum(sourcetypeid),
ObjectIdGetDatum(targettypeid));
if (!OidIsValid(oid) && !missing_ok)
@@ -1753,7 +1756,7 @@ DropCastById(Oid castOid)
relation = heap_open(CastRelationId, RowExclusiveLock);
ScanKeyInit(&scankey,
- ObjectIdAttributeNumber,
+ Anum_pg_cast_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(castOid));
scan = systable_beginscan(relation, CastOidIndexId, true,
@@ -1925,6 +1928,8 @@ CreateTransform(CreateTransformStmt *stmt)
ObjectIdGetDatum(langid));
if (HeapTupleIsValid(tuple))
{
+ Form_pg_transform form = (Form_pg_transform) GETSTRUCT(tuple);
+
if (!stmt->replace)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
@@ -1939,14 +1944,17 @@ CreateTransform(CreateTransformStmt *stmt)
newtuple = heap_modify_tuple(tuple, RelationGetDescr(relation), values, nulls, replaces);
CatalogTupleUpdate(relation, &newtuple->t_self, newtuple);
- transformid = HeapTupleGetOid(tuple);
+ transformid = form->oid;
ReleaseSysCache(tuple);
is_replace = true;
}
else
{
+ transformid = GetNewOidWithIndex(relation, TransformOidIndexId,
+ Anum_pg_transform_oid);
+ values[Anum_pg_transform_oid - 1] = ObjectIdGetDatum(transformid);
newtuple = heap_form_tuple(RelationGetDescr(relation), values, nulls);
- transformid = CatalogTupleInsert(relation, newtuple);
+ CatalogTupleInsert(relation, newtuple);
is_replace = false;
}
@@ -2011,7 +2019,7 @@ get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
{
Oid oid;
- oid = GetSysCacheOid2(TRFTYPELANG,
+ oid = GetSysCacheOid2(TRFTYPELANG, Anum_pg_transform_oid,
ObjectIdGetDatum(type_id),
ObjectIdGetDatum(lang_id));
if (!OidIsValid(oid) && !missing_ok)
@@ -2035,7 +2043,7 @@ DropTransformById(Oid transformOid)
relation = heap_open(TransformRelationId, RowExclusiveLock);
ScanKeyInit(&scankey,
- ObjectIdAttributeNumber,
+ Anum_pg_transform_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(transformOid));
scan = systable_beginscan(relation, TransformOidIndexId, true,
@@ -2140,8 +2148,8 @@ ExecuteDoStmt(DoStmt *stmt, bool atomic)
(PLTemplateExists(language) ?
errhint("Use CREATE EXTENSION to load the language into the database.") : 0)));
- codeblock->langOid = HeapTupleGetOid(languageTuple);
languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
+ codeblock->langOid = languageStruct->oid;
codeblock->langIsTrusted = languageStruct->lanpltrusted;
codeblock->atomic = atomic;
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 906d7113781..73656d8cc84 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -172,8 +172,8 @@ CheckIndexCompatible(Oid oldId,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
accessMethodName)));
- accessMethodId = HeapTupleGetOid(tuple);
accessMethodForm = (Form_pg_am) GETSTRUCT(tuple);
+ accessMethodId = accessMethodForm->oid;
amRoutine = GetIndexAmRoutine(accessMethodForm->amhandler);
ReleaseSysCache(tuple);
@@ -583,8 +583,8 @@ DefineIndex(Oid relationId,
errmsg("access method \"%s\" does not exist",
accessMethodName)));
}
- accessMethodId = HeapTupleGetOid(tuple);
accessMethodForm = (Form_pg_am) GETSTRUCT(tuple);
+ accessMethodId = accessMethodForm->oid;
amRoutine = GetIndexAmRoutine(accessMethodForm->amhandler);
if (stmt->unique && !amRoutine->amcanunique)
@@ -748,14 +748,14 @@ DefineIndex(Oid relationId,
/*
- * We disallow indexes on system columns other than OID. They would not
- * necessarily get updated correctly, and they don't seem useful anyway.
+ * We disallow indexes on system columns. They would not necessarily get
+ * updated correctly, and they don't seem useful anyway.
*/
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
{
AttrNumber attno = indexInfo->ii_IndexAttrNumbers[i];
- if (attno < 0 && attno != ObjectIdAttributeNumber)
+ if (attno < 0)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("index creation on system columns is not supported")));
@@ -773,8 +773,7 @@ DefineIndex(Oid relationId,
for (i = FirstLowInvalidHeapAttributeNumber + 1; i < 0; i++)
{
- if (i != ObjectIdAttributeNumber &&
- bms_is_member(i - FirstLowInvalidHeapAttributeNumber,
+ if (bms_is_member(i - FirstLowInvalidHeapAttributeNumber,
indexattrs))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -1712,6 +1711,7 @@ ResolveOpClass(List *opclass, Oid attrType,
char *schemaname;
char *opcname;
HeapTuple tuple;
+ Form_pg_opclass opform;
Oid opClassId,
opInputType;
@@ -1796,8 +1796,9 @@ ResolveOpClass(List *opclass, Oid attrType,
* Verify that the index operator class accepts this datatype. Note we
* will accept binary compatibility.
*/
- opClassId = HeapTupleGetOid(tuple);
- opInputType = ((Form_pg_opclass) GETSTRUCT(tuple))->opcintype;
+ opform = (Form_pg_opclass) GETSTRUCT(tuple);
+ opClassId = opform->oid;
+ opInputType = opform->opcintype;
if (!IsBinaryCoercible(attrType, opInputType))
ereport(ERROR,
@@ -1866,7 +1867,7 @@ GetDefaultOpClass(Oid type_id, Oid am_id)
if (opclass->opcintype == type_id)
{
nexact++;
- result = HeapTupleGetOid(tup);
+ result = opclass->oid;
}
else if (nexact == 0 &&
IsBinaryCoercible(type_id, opclass->opcintype))
@@ -1874,12 +1875,12 @@ GetDefaultOpClass(Oid type_id, Oid am_id)
if (IsPreferredType(tcategory, opclass->opcintype))
{
ncompatiblepreferred++;
- result = HeapTupleGetOid(tup);
+ result = opclass->oid;
}
else if (ncompatiblepreferred == 0)
{
ncompatible++;
- result = HeapTupleGetOid(tup);
+ result = opclass->oid;
}
}
}
@@ -2405,7 +2406,7 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
Form_pg_class classtuple = (Form_pg_class) GETSTRUCT(tuple);
- Oid relid = HeapTupleGetOid(tuple);
+ Oid relid = classtuple->oid;
/*
* Only regular tables and matviews can have indexes, so ignore any
diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index fd12288cbe3..a171ebabf8f 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -184,9 +184,6 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("CONCURRENTLY and WITH NO DATA options cannot be used together")));
- /* We don't allow an oid column for a materialized view. */
- Assert(!matviewRel->rd_rel->relhasoids);
-
/*
* Check that everything is correct for a refresh. Problems at this point
* are internal errors, so elog is sufficient.
@@ -408,7 +405,7 @@ refresh_matview_datafill(DestReceiver *dest, Query *query,
dest, NULL, NULL, 0);
/* call ExecutorStart to prepare the plan for execution */
- ExecutorStart(queryDesc, EXEC_FLAG_WITHOUT_OIDS);
+ ExecutorStart(queryDesc, 0);
/* run the plan */
ExecutorRun(queryDesc, ForwardScanDirection, 0L, true);
diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c
index 3b5c90e3f41..93ef3bd17ca 100644
--- a/src/backend/commands/opclasscmds.c
+++ b/src/backend/commands/opclasscmds.c
@@ -23,6 +23,7 @@
#include "access/nbtree.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
@@ -142,12 +143,14 @@ Oid
get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)
{
HeapTuple htup;
+ Form_pg_opfamily opfamform;
Oid opfID;
htup = OpFamilyCacheLookup(amID, opfamilyname, missing_ok);
if (!HeapTupleIsValid(htup))
return InvalidOid;
- opfID = HeapTupleGetOid(htup);
+ opfamform = (Form_pg_opfamily) GETSTRUCT(htup);
+ opfID = opfamform->oid;
ReleaseSysCache(htup);
return opfID;
@@ -221,12 +224,14 @@ Oid
get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
{
HeapTuple htup;
+ Form_pg_opclass opcform;
Oid opcID;
htup = OpClassCacheLookup(amID, opclassname, missing_ok);
if (!HeapTupleIsValid(htup))
return InvalidOid;
- opcID = HeapTupleGetOid(htup);
+ opcform = (Form_pg_opclass) GETSTRUCT(htup);
+ opcID = opcform->oid;
ReleaseSysCache(htup);
return opcID;
@@ -271,6 +276,9 @@ CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid am
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ opfamilyoid = GetNewOidWithIndex(rel, OpfamilyOidIndexId,
+ Anum_pg_opfamily_oid);
+ values[Anum_pg_opfamily_oid - 1] = ObjectIdGetDatum(opfamilyoid);
values[Anum_pg_opfamily_opfmethod - 1] = ObjectIdGetDatum(amoid);
namestrcpy(&opfName, opfname);
values[Anum_pg_opfamily_opfname - 1] = NameGetDatum(&opfName);
@@ -279,7 +287,7 @@ CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid am
tup = heap_form_tuple(rel->rd_att, values, nulls);
- opfamilyoid = CatalogTupleInsert(rel, tup);
+ CatalogTupleInsert(rel, tup);
heap_freetuple(tup);
@@ -338,6 +346,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
ListCell *l;
Relation rel;
HeapTuple tup;
+ Form_pg_am amform;
IndexAmRoutine *amroutine;
Datum values[Natts_pg_opclass];
bool nulls[Natts_pg_opclass];
@@ -364,7 +373,8 @@ DefineOpClass(CreateOpClassStmt *stmt)
errmsg("access method \"%s\" does not exist",
stmt->amname)));
- amoid = HeapTupleGetOid(tup);
+ amform = (Form_pg_am) GETSTRUCT(tup);
+ amoid = amform->oid;
amroutine = GetIndexAmRoutineByAmId(amoid, false);
ReleaseSysCache(tup);
@@ -429,7 +439,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
ObjectIdGetDatum(namespaceoid));
if (HeapTupleIsValid(tup))
{
- opfamilyoid = HeapTupleGetOid(tup);
+ opfamilyoid = ((Form_pg_opfamily) GETSTRUCT(tup))->oid;
/*
* XXX given the superuser check above, there's no need for an
@@ -633,6 +643,9 @@ DefineOpClass(CreateOpClassStmt *stmt)
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ opclassoid = GetNewOidWithIndex(rel, OpclassOidIndexId,
+ Anum_pg_opclass_oid);
+ values[Anum_pg_opclass_oid - 1] = ObjectIdGetDatum(opclassoid);
values[Anum_pg_opclass_opcmethod - 1] = ObjectIdGetDatum(amoid);
namestrcpy(&opcName, opcname);
values[Anum_pg_opclass_opcname - 1] = NameGetDatum(&opcName);
@@ -645,7 +658,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
tup = heap_form_tuple(rel->rd_att, values, nulls);
- opclassoid = CatalogTupleInsert(rel, tup);
+ CatalogTupleInsert(rel, tup);
heap_freetuple(tup);
@@ -768,6 +781,7 @@ AlterOpFamily(AlterOpFamilyStmt *stmt)
int maxOpNumber, /* amstrategies value */
maxProcNumber; /* amsupport value */
HeapTuple tup;
+ Form_pg_am amform;
IndexAmRoutine *amroutine;
/* Get necessary info about access method */
@@ -778,7 +792,8 @@ AlterOpFamily(AlterOpFamilyStmt *stmt)
errmsg("access method \"%s\" does not exist",
stmt->amname)));
- amoid = HeapTupleGetOid(tup);
+ amform = (Form_pg_am) GETSTRUCT(tup);
+ amoid = amform->oid;
amroutine = GetIndexAmRoutineByAmId(amoid, false);
ReleaseSysCache(tup);
@@ -1333,6 +1348,9 @@ storeOperators(List *opfamilyname, Oid amoid,
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ entryoid = GetNewOidWithIndex(rel, AccessMethodOperatorOidIndexId,
+ Anum_pg_amop_oid);
+ values[Anum_pg_amop_oid - 1] = ObjectIdGetDatum(entryoid);
values[Anum_pg_amop_amopfamily - 1] = ObjectIdGetDatum(opfamilyoid);
values[Anum_pg_amop_amoplefttype - 1] = ObjectIdGetDatum(op->lefttype);
values[Anum_pg_amop_amoprighttype - 1] = ObjectIdGetDatum(op->righttype);
@@ -1344,7 +1362,7 @@ storeOperators(List *opfamilyname, Oid amoid,
tup = heap_form_tuple(rel->rd_att, values, nulls);
- entryoid = CatalogTupleInsert(rel, tup);
+ CatalogTupleInsert(rel, tup);
heap_freetuple(tup);
@@ -1445,6 +1463,9 @@ storeProcedures(List *opfamilyname, Oid amoid,
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ entryoid = GetNewOidWithIndex(rel, AccessMethodProcedureOidIndexId,
+ Anum_pg_amproc_oid);
+ values[Anum_pg_amproc_oid - 1] = ObjectIdGetDatum(entryoid);
values[Anum_pg_amproc_amprocfamily - 1] = ObjectIdGetDatum(opfamilyoid);
values[Anum_pg_amproc_amproclefttype - 1] = ObjectIdGetDatum(proc->lefttype);
values[Anum_pg_amproc_amprocrighttype - 1] = ObjectIdGetDatum(proc->righttype);
@@ -1453,7 +1474,7 @@ storeProcedures(List *opfamilyname, Oid amoid,
tup = heap_form_tuple(rel->rd_att, values, nulls);
- entryoid = CatalogTupleInsert(rel, tup);
+ CatalogTupleInsert(rel, tup);
heap_freetuple(tup);
@@ -1515,7 +1536,7 @@ dropOperators(List *opfamilyname, Oid amoid, Oid opfamilyoid,
Oid amopid;
ObjectAddress object;
- amopid = GetSysCacheOid4(AMOPSTRATEGY,
+ amopid = GetSysCacheOid4(AMOPSTRATEGY, Anum_pg_amop_oid,
ObjectIdGetDatum(opfamilyoid),
ObjectIdGetDatum(op->lefttype),
ObjectIdGetDatum(op->righttype),
@@ -1555,7 +1576,7 @@ dropProcedures(List *opfamilyname, Oid amoid, Oid opfamilyoid,
Oid amprocid;
ObjectAddress object;
- amprocid = GetSysCacheOid4(AMPROCNUM,
+ amprocid = GetSysCacheOid4(AMPROCNUM, Anum_pg_amproc_oid,
ObjectIdGetDatum(opfamilyoid),
ObjectIdGetDatum(op->lefttype),
ObjectIdGetDatum(op->righttype),
@@ -1627,7 +1648,7 @@ RemoveAmOpEntryById(Oid entryOid)
SysScanDesc scan;
ScanKeyInit(&skey[0],
- ObjectIdAttributeNumber,
+ Anum_pg_amop_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(entryOid));
@@ -1656,7 +1677,7 @@ RemoveAmProcEntryById(Oid entryOid)
SysScanDesc scan;
ScanKeyInit(&skey[0],
- ObjectIdAttributeNumber,
+ Anum_pg_amproc_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(entryOid));
diff --git a/src/backend/commands/policy.c b/src/backend/commands/policy.c
index 2fd17b24b9e..5b27a94471e 100644
--- a/src/backend/commands/policy.c
+++ b/src/backend/commands/policy.c
@@ -365,7 +365,7 @@ RemovePolicyById(Oid policy_id)
* Find the policy to delete.
*/
ScanKeyInit(&skey[0],
- ObjectIdAttributeNumber,
+ Anum_pg_policy_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(policy_id));
@@ -457,7 +457,7 @@ RemoveRoleFromObjectPolicy(Oid roleid, Oid classid, Oid policy_id)
* Find the policy to update.
*/
ScanKeyInit(&skey[0],
- ObjectIdAttributeNumber,
+ Anum_pg_policy_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(policy_id));
@@ -807,6 +807,9 @@ CreatePolicy(CreatePolicyStmt *stmt)
errmsg("policy \"%s\" for table \"%s\" already exists",
stmt->policy_name, RelationGetRelationName(target_table))));
+ policy_id = GetNewOidWithIndex(pg_policy_rel, PolicyOidIndexId,
+ Anum_pg_policy_oid);
+ values[Anum_pg_policy_oid - 1] = ObjectIdGetDatum(policy_id);
values[Anum_pg_policy_polrelid - 1] = ObjectIdGetDatum(table_id);
values[Anum_pg_policy_polname - 1] = DirectFunctionCall1(namein,
CStringGetDatum(stmt->policy_name));
@@ -829,7 +832,7 @@ CreatePolicy(CreatePolicyStmt *stmt)
policy_tuple = heap_form_tuple(RelationGetDescr(pg_policy_rel), values,
isnull);
- policy_id = CatalogTupleInsert(pg_policy_rel, policy_tuple);
+ CatalogTupleInsert(pg_policy_rel, policy_tuple);
/* Record Dependencies */
target.classId = RelationRelationId;
@@ -1033,7 +1036,7 @@ AlterPolicy(AlterPolicyStmt *stmt)
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("only WITH CHECK expression allowed for INSERT")));
- policy_id = HeapTupleGetOid(policy_tuple);
+ policy_id = ((Form_pg_policy) GETSTRUCT(policy_tuple))->oid;
if (role_ids != NULL)
{
@@ -1284,7 +1287,7 @@ rename_policy(RenameStmt *stmt)
errmsg("policy \"%s\" for table \"%s\" does not exist",
stmt->subname, RelationGetRelationName(target_table))));
- opoloid = HeapTupleGetOid(policy_tuple);
+ opoloid = ((Form_pg_policy) GETSTRUCT(policy_tuple))->oid;
policy_tuple = heap_copytuple(policy_tuple);
@@ -1293,8 +1296,7 @@ rename_policy(RenameStmt *stmt)
CatalogTupleUpdate(pg_policy_rel, &policy_tuple->t_self, policy_tuple);
- InvokeObjectPostAlterHook(PolicyRelationId,
- HeapTupleGetOid(policy_tuple), 0);
+ InvokeObjectPostAlterHook(PolicyRelationId, opoloid, 0);
ObjectAddressSet(address, PolicyRelationId, opoloid);
@@ -1359,7 +1361,7 @@ get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
policy_oid = InvalidOid;
}
else
- policy_oid = HeapTupleGetOid(policy_tuple);
+ policy_oid = ((Form_pg_policy) GETSTRUCT(policy_tuple))->oid;
/* Clean up. */
systable_endscan(sscan);
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index b945b1556a8..6036b735e9f 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -734,7 +734,7 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
* build tupdesc for result tuples. This must match the definition of the
* pg_prepared_statements view in system_views.sql
*/
- tupdesc = CreateTemplateTupleDesc(5, false);
+ tupdesc = CreateTemplateTupleDesc(5);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "statement",
diff --git a/src/backend/commands/proclang.c b/src/backend/commands/proclang.c
index c900ad9431a..08f5e55dc22 100644
--- a/src/backend/commands/proclang.c
+++ b/src/backend/commands/proclang.c
@@ -16,6 +16,7 @@
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
@@ -329,6 +330,7 @@ create_proc_lang(const char *languageName, bool replace,
NameData langname;
HeapTuple oldtup;
HeapTuple tup;
+ Oid langoid;
bool is_update;
ObjectAddress myself,
referenced;
@@ -356,19 +358,22 @@ create_proc_lang(const char *languageName, bool replace,
if (HeapTupleIsValid(oldtup))
{
+ Form_pg_language oldform = (Form_pg_language) GETSTRUCT(oldtup);
+
/* There is one; okay to replace it? */
if (!replace)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("language \"%s\" already exists", languageName)));
- if (!pg_language_ownercheck(HeapTupleGetOid(oldtup), languageOwner))
+ if (!pg_language_ownercheck(oldform->oid, languageOwner))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_LANGUAGE,
languageName);
/*
- * Do not change existing ownership or permissions. Note
+ * Do not change existing oid, ownership or permissions. Note
* dependency-update code below has to agree with this decision.
*/
+ replaces[Anum_pg_language_oid - 1] = false;
replaces[Anum_pg_language_lanowner - 1] = false;
replaces[Anum_pg_language_lanacl - 1] = false;
@@ -376,12 +381,16 @@ create_proc_lang(const char *languageName, bool replace,
tup = heap_modify_tuple(oldtup, tupDesc, values, nulls, replaces);
CatalogTupleUpdate(rel, &tup->t_self, tup);
+ langoid = oldform->oid;
ReleaseSysCache(oldtup);
is_update = true;
}
else
{
/* Creating a new language */
+ langoid = GetNewOidWithIndex(rel, LanguageOidIndexId,
+ Anum_pg_language_oid);
+ values[Anum_pg_language_oid - 1] = ObjectIdGetDatum(langoid);
tup = heap_form_tuple(tupDesc, values, nulls);
CatalogTupleInsert(rel, tup);
is_update = false;
@@ -394,7 +403,7 @@ create_proc_lang(const char *languageName, bool replace,
* shared dependencies do *not* need to change, and we leave them alone.)
*/
myself.classId = LanguageRelationId;
- myself.objectId = HeapTupleGetOid(tup);
+ myself.objectId = langoid;
myself.objectSubId = 0;
if (is_update)
@@ -550,7 +559,8 @@ get_language_oid(const char *langname, bool missing_ok)
{
Oid oid;
- oid = GetSysCacheOid1(LANGNAME, CStringGetDatum(langname));
+ oid = GetSysCacheOid1(LANGNAME, Anum_pg_language_oid,
+ CStringGetDatum(langname));
if (!OidIsValid(oid) && !missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index 6f7762a906c..b85c3d7c611 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -168,7 +168,8 @@ CreatePublication(CreatePublicationStmt *stmt)
rel = heap_open(PublicationRelationId, RowExclusiveLock);
/* Check if name is used */
- puboid = GetSysCacheOid1(PUBLICATIONNAME, CStringGetDatum(stmt->pubname));
+ puboid = GetSysCacheOid1(PUBLICATIONNAME, Anum_pg_publication_oid,
+ CStringGetDatum(stmt->pubname));
if (OidIsValid(puboid))
{
ereport(ERROR,
@@ -190,6 +191,9 @@ CreatePublication(CreatePublicationStmt *stmt)
&publish_update, &publish_delete,
&publish_truncate);
+ puboid = GetNewOidWithIndex(rel, PublicationObjectIndexId,
+ Anum_pg_publication_oid);
+ values[Anum_pg_publication_oid - 1] = ObjectIdGetDatum(puboid);
values[Anum_pg_publication_puballtables - 1] =
BoolGetDatum(stmt->for_all_tables);
values[Anum_pg_publication_pubinsert - 1] =
@@ -204,7 +208,7 @@ CreatePublication(CreatePublicationStmt *stmt)
tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
/* Insert tuple into catalog. */
- puboid = CatalogTupleInsert(rel, tup);
+ CatalogTupleInsert(rel, tup);
heap_freetuple(tup);
recordDependencyOnOwner(PublicationRelationId, puboid, GetUserId());
@@ -248,6 +252,7 @@ AlterPublicationOptions(AlterPublicationStmt *stmt, Relation rel,
bool publish_delete;
bool publish_truncate;
ObjectAddress obj;
+ Form_pg_publication pubform;
parse_publication_options(stmt->options,
&publish_given, &publish_insert,
@@ -282,14 +287,16 @@ AlterPublicationOptions(AlterPublicationStmt *stmt, Relation rel,
CommandCounterIncrement();
+ pubform = (Form_pg_publication) GETSTRUCT(tup);
+
/* Invalidate the relcache. */
- if (((Form_pg_publication) GETSTRUCT(tup))->puballtables)
+ if (pubform->puballtables)
{
CacheInvalidateRelcacheAll();
}
else
{
- List *relids = GetPublicationRelations(HeapTupleGetOid(tup));
+ List *relids = GetPublicationRelations(pubform->oid);
/*
* We don't want to send too many individual messages, at some point
@@ -310,11 +317,11 @@ AlterPublicationOptions(AlterPublicationStmt *stmt, Relation rel,
CacheInvalidateRelcacheAll();
}
- ObjectAddressSet(obj, PublicationRelationId, HeapTupleGetOid(tup));
+ ObjectAddressSet(obj, PublicationRelationId, pubform->oid);
EventTriggerCollectSimpleCommand(obj, InvalidObjectAddress,
(Node *) stmt);
- InvokeObjectPostAlterHook(PublicationRelationId, HeapTupleGetOid(tup), 0);
+ InvokeObjectPostAlterHook(PublicationRelationId, pubform->oid, 0);
}
/*
@@ -324,9 +331,9 @@ static void
AlterPublicationTables(AlterPublicationStmt *stmt, Relation rel,
HeapTuple tup)
{
- Oid pubid = HeapTupleGetOid(tup);
List *rels = NIL;
Form_pg_publication pubform = (Form_pg_publication) GETSTRUCT(tup);
+ Oid pubid = pubform->oid;
/* Check that user is allowed to manipulate the publication tables. */
if (pubform->puballtables)
@@ -403,6 +410,7 @@ AlterPublication(AlterPublicationStmt *stmt)
{
Relation rel;
HeapTuple tup;
+ Form_pg_publication pubform;
rel = heap_open(PublicationRelationId, RowExclusiveLock);
@@ -415,8 +423,10 @@ AlterPublication(AlterPublicationStmt *stmt)
errmsg("publication \"%s\" does not exist",
stmt->pubname)));
+ pubform = (Form_pg_publication) GETSTRUCT(tup);
+
/* must be owner */
- if (!pg_publication_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ if (!pg_publication_ownercheck(pubform->oid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_PUBLICATION,
stmt->pubname);
@@ -626,7 +636,8 @@ PublicationDropTables(Oid pubid, List *rels, bool missing_ok)
Relation rel = (Relation) lfirst(lc);
Oid relid = RelationGetRelid(rel);
- prid = GetSysCacheOid2(PUBLICATIONRELMAP, ObjectIdGetDatum(relid),
+ prid = GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
+ ObjectIdGetDatum(relid),
ObjectIdGetDatum(pubid));
if (!OidIsValid(prid))
{
@@ -662,7 +673,7 @@ AlterPublicationOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
AclResult aclresult;
/* Must be owner */
- if (!pg_publication_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ if (!pg_publication_ownercheck(form->oid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_PUBLICATION,
NameStr(form->pubname));
@@ -688,11 +699,11 @@ AlterPublicationOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
/* Update owner dependency reference */
changeDependencyOnOwner(PublicationRelationId,
- HeapTupleGetOid(tup),
+ form->oid,
newOwnerId);
InvokeObjectPostAlterHook(PublicationRelationId,
- HeapTupleGetOid(tup), 0);
+ form->oid, 0);
}
/*
@@ -705,6 +716,7 @@ AlterPublicationOwner(const char *name, Oid newOwnerId)
HeapTuple tup;
Relation rel;
ObjectAddress address;
+ Form_pg_publication pubform;
rel = heap_open(PublicationRelationId, RowExclusiveLock);
@@ -715,7 +727,8 @@ AlterPublicationOwner(const char *name, Oid newOwnerId)
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("publication \"%s\" does not exist", name)));
- subid = HeapTupleGetOid(tup);
+ pubform = (Form_pg_publication) GETSTRUCT(tup);
+ subid = pubform->oid;
AlterPublicationOwner_internal(rel, tup, newOwnerId);
diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c
index dc6cb46e4e7..f0ebe2d1c31 100644
--- a/src/backend/commands/schemacmds.c
+++ b/src/backend/commands/schemacmds.c
@@ -246,6 +246,7 @@ RenameSchema(const char *oldname, const char *newname)
Relation rel;
AclResult aclresult;
ObjectAddress address;
+ Form_pg_namespace nspform;
rel = heap_open(NamespaceRelationId, RowExclusiveLock);
@@ -255,7 +256,8 @@ RenameSchema(const char *oldname, const char *newname)
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", oldname)));
- nspOid = HeapTupleGetOid(tup);
+ nspform = (Form_pg_namespace) GETSTRUCT(tup);
+ nspOid = nspform->oid;
/* make sure the new name doesn't exist */
if (OidIsValid(get_namespace_oid(newname, true)))
@@ -264,7 +266,7 @@ RenameSchema(const char *oldname, const char *newname)
errmsg("schema \"%s\" already exists", newname)));
/* must be owner */
- if (!pg_namespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ if (!pg_namespace_ownercheck(nspOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_SCHEMA,
oldname);
@@ -281,10 +283,10 @@ RenameSchema(const char *oldname, const char *newname)
errdetail("The prefix \"pg_\" is reserved for system schemas.")));
/* rename */
- namestrcpy(&(((Form_pg_namespace) GETSTRUCT(tup))->nspname), newname);
+ namestrcpy(&nspform->nspname, newname);
CatalogTupleUpdate(rel, &tup->t_self, tup);
- InvokeObjectPostAlterHook(NamespaceRelationId, HeapTupleGetOid(tup), 0);
+ InvokeObjectPostAlterHook(NamespaceRelationId, nspOid, 0);
ObjectAddressSet(address, NamespaceRelationId, nspOid);
@@ -324,6 +326,7 @@ AlterSchemaOwner(const char *name, Oid newOwnerId)
HeapTuple tup;
Relation rel;
ObjectAddress address;
+ Form_pg_namespace nspform;
rel = heap_open(NamespaceRelationId, RowExclusiveLock);
@@ -333,7 +336,8 @@ AlterSchemaOwner(const char *name, Oid newOwnerId)
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", name)));
- nspOid = HeapTupleGetOid(tup);
+ nspform = (Form_pg_namespace) GETSTRUCT(tup);
+ nspOid = nspform->oid;
AlterSchemaOwner_internal(tup, rel, newOwnerId);
@@ -372,7 +376,7 @@ AlterSchemaOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerId)
AclResult aclresult;
/* Otherwise, must be owner of the existing object */
- if (!pg_namespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ if (!pg_namespace_ownercheck(nspForm->oid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_SCHEMA,
NameStr(nspForm->nspname));
@@ -422,10 +426,10 @@ AlterSchemaOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerId)
heap_freetuple(newtuple);
/* Update owner dependency reference */
- changeDependencyOnOwner(NamespaceRelationId, HeapTupleGetOid(tup),
+ changeDependencyOnOwner(NamespaceRelationId, nspForm->oid,
newOwnerId);
}
InvokeObjectPostAlterHook(NamespaceRelationId,
- HeapTupleGetOid(tup), 0);
+ nspForm->oid, 0);
}
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index 6d89925b237..f9dca39d3db 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -1788,7 +1788,7 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
errmsg("permission denied for sequence %s",
get_rel_name(relid))));
- tupdesc = CreateTemplateTupleDesc(7, false);
+ tupdesc = CreateTemplateTupleDesc(7);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "start_value",
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "minimum_value",
diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c
index 3bb0d24cd20..bfc0f1d1fa1 100644
--- a/src/backend/commands/statscmds.c
+++ b/src/backend/commands/statscmds.c
@@ -15,6 +15,7 @@
#include "postgres.h"
#include "access/relscan.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
@@ -305,11 +306,17 @@ CreateStatistics(CreateStatsStmt *stmt)
Assert(ntypes > 0 && ntypes <= lengthof(types));
stxkind = construct_array(types, ntypes, CHAROID, 1, true, 'c');
+ statrel = heap_open(StatisticExtRelationId, RowExclusiveLock);
+
/*
* Everything seems fine, so let's build the pg_statistic_ext tuple.
*/
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+
+ statoid = GetNewOidWithIndex(statrel, StatisticExtOidIndexId,
+ Anum_pg_statistic_ext_oid);
+ values[Anum_pg_statistic_ext_oid - 1] = ObjectIdGetDatum(statoid);
values[Anum_pg_statistic_ext_stxrelid - 1] = ObjectIdGetDatum(relid);
values[Anum_pg_statistic_ext_stxname - 1] = NameGetDatum(&stxname);
values[Anum_pg_statistic_ext_stxnamespace - 1] = ObjectIdGetDatum(namespaceId);
@@ -322,10 +329,10 @@ CreateStatistics(CreateStatsStmt *stmt)
nulls[Anum_pg_statistic_ext_stxdependencies - 1] = true;
/* insert it into pg_statistic_ext */
- statrel = heap_open(StatisticExtRelationId, RowExclusiveLock);
htup = heap_form_tuple(statrel->rd_att, values, nulls);
- statoid = CatalogTupleInsert(statrel, htup);
+ CatalogTupleInsert(statrel, htup);
heap_freetuple(htup);
+
relation_close(statrel, RowExclusiveLock);
/*
@@ -467,7 +474,7 @@ ChooseExtendedStatisticName(const char *name1, const char *name2,
stxname = makeObjectName(name1, name2, modlabel);
- existingstats = GetSysCacheOid2(STATEXTNAMENSP,
+ existingstats = GetSysCacheOid2(STATEXTNAMENSP, Anum_pg_statistic_ext_oid,
PointerGetDatum(stxname),
ObjectIdGetDatum(namespaceid));
if (!OidIsValid(existingstats))
diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c
index 0efbfec4751..9021463a4c7 100644
--- a/src/backend/commands/subscriptioncmds.c
+++ b/src/backend/commands/subscriptioncmds.c
@@ -20,6 +20,7 @@
#include "access/htup_details.h"
#include "access/xact.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
@@ -349,8 +350,8 @@ CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
rel = heap_open(SubscriptionRelationId, RowExclusiveLock);
/* Check if name is used */
- subid = GetSysCacheOid2(SUBSCRIPTIONNAME, MyDatabaseId,
- CStringGetDatum(stmt->subname));
+ subid = GetSysCacheOid2(SUBSCRIPTIONNAME, Anum_pg_subscription_oid,
+ MyDatabaseId, CStringGetDatum(stmt->subname));
if (OidIsValid(subid))
{
ereport(ERROR,
@@ -379,6 +380,9 @@ CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ subid = GetNewOidWithIndex(rel, SubscriptionObjectIndexId,
+ Anum_pg_subscription_oid);
+ values[Anum_pg_subscription_oid - 1] = ObjectIdGetDatum(subid);
values[Anum_pg_subscription_subdbid - 1] = ObjectIdGetDatum(MyDatabaseId);
values[Anum_pg_subscription_subname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(stmt->subname));
@@ -399,7 +403,7 @@ CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
/* Insert tuple into catalog. */
- subid = CatalogTupleInsert(rel, tup);
+ CatalogTupleInsert(rel, tup);
heap_freetuple(tup);
recordDependencyOnOwner(SubscriptionRelationId, subid, owner);
@@ -620,6 +624,7 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
Oid subid;
bool update_tuple = false;
Subscription *sub;
+ Form_pg_subscription form;
rel = heap_open(SubscriptionRelationId, RowExclusiveLock);
@@ -633,12 +638,14 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
errmsg("subscription \"%s\" does not exist",
stmt->subname)));
+ form = (Form_pg_subscription) GETSTRUCT(tup);
+ subid = form->oid;
+
/* must be owner */
- if (!pg_subscription_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ if (!pg_subscription_ownercheck(subid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_SUBSCRIPTION,
stmt->subname);
- subid = HeapTupleGetOid(tup);
sub = GetSubscription(subid, false);
/* Lock the subscription so nobody else can do anything with it. */
@@ -823,6 +830,7 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
RepOriginId originid;
WalReceiverConn *wrconn = NULL;
StringInfoData cmd;
+ Form_pg_subscription form;
/*
* Lock pg_subscription with AccessExclusiveLock to ensure that the
@@ -850,7 +858,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
return;
}
- subid = HeapTupleGetOid(tup);
+ form = (Form_pg_subscription) GETSTRUCT(tup);
+ subid = form->oid;
/* must be owner */
if (!pg_subscription_ownercheck(subid, GetUserId()))
@@ -1021,7 +1030,7 @@ AlterSubscriptionOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
if (form->subowner == newOwnerId)
return;
- if (!pg_subscription_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ if (!pg_subscription_ownercheck(form->oid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_SUBSCRIPTION,
NameStr(form->subname));
@@ -1038,11 +1047,11 @@ AlterSubscriptionOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
/* Update owner dependency reference */
changeDependencyOnOwner(SubscriptionRelationId,
- HeapTupleGetOid(tup),
+ form->oid,
newOwnerId);
InvokeObjectPostAlterHook(SubscriptionRelationId,
- HeapTupleGetOid(tup), 0);
+ form->oid, 0);
}
/*
@@ -1055,6 +1064,7 @@ AlterSubscriptionOwner(const char *name, Oid newOwnerId)
HeapTuple tup;
Relation rel;
ObjectAddress address;
+ Form_pg_subscription form;
rel = heap_open(SubscriptionRelationId, RowExclusiveLock);
@@ -1066,7 +1076,8 @@ AlterSubscriptionOwner(const char *name, Oid newOwnerId)
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("subscription \"%s\" does not exist", name)));
- subid = HeapTupleGetOid(tup);
+ form = (Form_pg_subscription) GETSTRUCT(tup);
+ subid = form->oid;
AlterSubscriptionOwner_internal(rel, tup, newOwnerId);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a15e6045075..a1137a3bf09 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -305,8 +305,7 @@ static void truncate_check_activity(Relation rel);
static void RangeVarCallbackForTruncate(const RangeVar *relation,
Oid relId, Oid oldRelId, void *arg);
static List *MergeAttributes(List *schema, List *supers, char relpersistence,
- bool is_partition, List **supOids, List **supconstr,
- int *supOidCount);
+ bool is_partition, List **supOids, List **supconstr);
static bool MergeCheckConstraint(List *constraints, char *name, Node *expr);
static void MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel);
static void MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel);
@@ -363,15 +362,13 @@ static List *find_typed_table_dependencies(Oid typeOid, const char *typeName,
static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode);
static ObjectAddress ATExecAddColumn(List **wqueue, AlteredTableInfo *tab,
- Relation rel, ColumnDef *colDef, bool isOid,
+ Relation rel, ColumnDef *colDef,
bool recurse, bool recursing,
bool if_not_exists, LOCKMODE lockmode);
static bool check_for_column_name_collision(Relation rel, const char *colname,
bool if_not_exists);
static void add_column_datatype_dependency(Oid relid, int32 attnum, Oid typid);
static void add_column_collation_dependency(Oid relid, int32 attnum, Oid collid);
-static void ATPrepAddOids(List **wqueue, Relation rel, bool recurse,
- AlterTableCmd *cmd, LOCKMODE lockmode);
static void ATPrepDropNotNull(Relation rel, bool recurse, bool recursing);
static ObjectAddress ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode);
static void ATPrepSetNotNull(Relation rel, bool recurse, bool recursing);
@@ -531,8 +528,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
TupleDesc descriptor;
List *inheritOids;
List *old_constraints;
- bool localHasOids;
- int parentOidCount;
List *rawDefaults;
List *cookedDefaults;
Datum reloptions;
@@ -654,7 +649,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
MergeAttributes(stmt->tableElts, stmt->inhRelations,
stmt->relation->relpersistence,
stmt->partbound != NULL,
- &inheritOids, &old_constraints, &parentOidCount);
+ &inheritOids, &old_constraints);
/*
* Create a tuple descriptor from the relation schema. Note that this
@@ -664,29 +659,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
descriptor = BuildDescForRelation(stmt->tableElts);
/*
- * Notice that we allow OIDs here only for plain tables and partitioned
- * tables, even though some other relkinds can 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().
- */
- localHasOids = interpretOidsOption(stmt->options,
- (relkind == RELKIND_RELATION ||
- relkind == RELKIND_PARTITIONED_TABLE));
- descriptor->tdhasoid = (localHasOids || parentOidCount > 0);
-
- /*
- * If a partitioned table doesn't have the system OID column, then none of
- * its partitions should have it.
- */
- if (stmt->partbound && parentOidCount == 0 && localHasOids)
- ereport(ERROR,
- (errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("cannot create table with OIDs as partition of table without OIDs")));
-
- /*
* Find columns with default values and prepare for insertion of the
* defaults. Pre-cooked (that is, inherited) defaults go into a list of
* CookedConstraint structs that we'll pass to heap_create_with_catalog,
@@ -764,8 +736,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
stmt->relation->relpersistence,
false,
false,
- localHasOids,
- parentOidCount,
stmt->oncommit,
reloptions,
true,
@@ -1816,7 +1786,6 @@ storage_name(char c)
* 'supOids' receives a list of the OIDs of the parent relations.
* 'supconstr' receives a list of constraints belonging to the parents,
* updated as necessary to be valid for the child.
- * 'supOidCount' is set to the number of parents that have OID columns.
*
* Return value:
* Completed schema list.
@@ -1862,14 +1831,12 @@ storage_name(char c)
*/
static List *
MergeAttributes(List *schema, List *supers, char relpersistence,
- bool is_partition, List **supOids, List **supconstr,
- int *supOidCount)
+ bool is_partition, List **supOids, List **supconstr)
{
ListCell *entry;
List *inhSchema = NIL;
List *parentOids = NIL;
List *constraints = NIL;
- int parentsWithOids = 0;
bool have_bogus_defaults = false;
int child_attno;
static Node bogus_marker = {0}; /* marks conflicting defaults */
@@ -2077,9 +2044,6 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
parentOids = lappend_oid(parentOids, RelationGetRelid(relation));
- if (relation->rd_rel->relhasoids)
- parentsWithOids++;
-
tupleDesc = RelationGetDescr(relation);
constr = tupleDesc->constr;
@@ -2498,7 +2462,6 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
*supOids = parentOids;
*supconstr = constraints;
- *supOidCount = parentsWithOids;
return schema;
}
@@ -3424,7 +3387,6 @@ AlterTableGetLockLevel(List *cmds)
* to SELECT */
case AT_SetTableSpace: /* must rewrite heap */
case AT_AlterColumnType: /* must rewrite heap */
- case AT_AddOids: /* must rewrite heap */
cmd_lockmode = AccessExclusiveLock;
break;
@@ -3453,7 +3415,7 @@ AlterTableGetLockLevel(List *cmds)
*/
case AT_DropColumn: /* change visible to SELECT */
case AT_AddColumnToView: /* CREATE VIEW */
- case AT_DropOids: /* calls AT_DropColumn */
+ case AT_DropOids: /* used to equiv to DropColumn */
case AT_EnableAlwaysRule: /* may change SELECT rules */
case AT_EnableReplicaRule: /* may change SELECT rules */
case AT_EnableRule: /* may change SELECT rules */
@@ -3862,25 +3824,8 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
}
pass = AT_PASS_MISC;
break;
- case AT_AddOids: /* SET WITH OIDS */
- ATSimplePermissions(rel, ATT_TABLE | ATT_FOREIGN_TABLE);
- if (!rel->rd_rel->relhasoids || recursing)
- ATPrepAddOids(wqueue, rel, recurse, cmd, lockmode);
- /* Recursion occurs during execution phase */
- pass = AT_PASS_ADD_COL;
- break;
case AT_DropOids: /* SET WITHOUT OIDS */
ATSimplePermissions(rel, ATT_TABLE | ATT_FOREIGN_TABLE);
- /* Performs own recursion */
- if (rel->rd_rel->relhasoids)
- {
- AlterTableCmd *dropCmd = makeNode(AlterTableCmd);
-
- dropCmd->subtype = AT_DropColumn;
- dropCmd->name = pstrdup("oid");
- dropCmd->behavior = cmd->behavior;
- ATPrepCmd(wqueue, rel, dropCmd, recurse, false, lockmode);
- }
pass = AT_PASS_DROP;
break;
case AT_SetTableSpace: /* SET TABLESPACE */
@@ -4068,12 +4013,12 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
case AT_AddColumn: /* ADD COLUMN */
case AT_AddColumnToView: /* add column via CREATE OR REPLACE VIEW */
address = ATExecAddColumn(wqueue, tab, rel, (ColumnDef *) cmd->def,
- false, false, false,
+ false, false,
false, lockmode);
break;
case AT_AddColumnRecurse:
address = ATExecAddColumn(wqueue, tab, rel, (ColumnDef *) cmd->def,
- false, true, false,
+ true, false,
cmd->missing_ok, lockmode);
break;
case AT_ColumnDefault: /* ALTER COLUMN DEFAULT */
@@ -4197,28 +4142,8 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
case AT_SetLogged: /* SET LOGGED */
case AT_SetUnLogged: /* SET UNLOGGED */
break;
- case AT_AddOids: /* SET WITH OIDS */
- /* Use the ADD COLUMN code, unless prep decided to do nothing */
- if (cmd->def != NULL)
- address =
- ATExecAddColumn(wqueue, tab, rel, (ColumnDef *) cmd->def,
- true, false, false,
- cmd->missing_ok, lockmode);
- break;
- case AT_AddOidsRecurse: /* SET WITH OIDS */
- /* Use the ADD COLUMN code, unless prep decided to do nothing */
- if (cmd->def != NULL)
- address =
- ATExecAddColumn(wqueue, tab, rel, (ColumnDef *) cmd->def,
- true, true, false,
- cmd->missing_ok, lockmode);
- break;
case AT_DropOids: /* SET WITHOUT OIDS */
-
- /*
- * Nothing to do here; we'll have generated a DropColumn
- * subcommand to do the real work
- */
+ /* nothing to do here, oid columns don't exist anymore */
break;
case AT_SetTableSpace: /* SET TABLESPACE */
/*
@@ -4774,12 +4699,8 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
{
if (tab->rewrite > 0)
{
- Oid tupOid = InvalidOid;
-
/* Extract data from old tuple */
heap_deform_tuple(tuple, oldTupDesc, values, isnull);
- if (oldTupDesc->tdhasoid)
- tupOid = HeapTupleGetOid(tuple);
/* Set dropped attributes to null in new tuple */
foreach(lc, dropped_attrs)
@@ -4807,10 +4728,6 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
*/
tuple = heap_form_tuple(newTupDesc, values, isnull);
- /* Preserve OID, if any */
- if (newTupDesc->tdhasoid)
- HeapTupleSetOid(tuple, tupOid);
-
/*
* Constraints might reference the tableoid column, so
* initialize t_tableOid before evaluating them.
@@ -5293,6 +5210,8 @@ find_typed_table_dependencies(Oid typeOid, const char *typeName, DropBehavior be
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
+ Form_pg_class classform = (Form_pg_class) GETSTRUCT(tuple);
+
if (behavior == DROP_RESTRICT)
ereport(ERROR,
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
@@ -5300,7 +5219,7 @@ find_typed_table_dependencies(Oid typeOid, const char *typeName, DropBehavior be
typeName),
errhint("Use ALTER ... CASCADE to alter the typed tables too.")));
else
- result = lappend_oid(result, HeapTupleGetOid(tuple));
+ result = lappend_oid(result, classform->oid);
}
heap_endscan(scan);
@@ -5345,7 +5264,7 @@ check_of_type(HeapTuple typetuple)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("type %s is not a composite type",
- format_type_be(HeapTupleGetOid(typetuple)))));
+ format_type_be(typ->oid))));
}
@@ -5385,7 +5304,7 @@ ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
*/
static ObjectAddress
ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
- ColumnDef *colDef, bool isOid,
+ ColumnDef *colDef,
bool recurse, bool recursing,
bool if_not_exists, LOCKMODE lockmode)
{
@@ -5455,13 +5374,6 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
get_collation_name(ccollid),
get_collation_name(childatt->attcollation))));
- /* If it's OID, child column must actually be OID */
- if (isOid && childatt->attnum != ObjectIdAttributeNumber)
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("child table \"%s\" has a conflicting \"%s\" column",
- RelationGetRelationName(rel), colDef->colname)));
-
/* Bump the existing child att's inhcount */
childatt->attinhcount++;
CatalogTupleUpdate(attrdesc, &tuple->t_self, tuple);
@@ -5506,21 +5418,16 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
}
/* Determine the new attribute's number */
- if (isOid)
- newattnum = ObjectIdAttributeNumber;
- else
- {
- newattnum = ((Form_pg_class) GETSTRUCT(reltup))->relnatts + 1;
- if (newattnum > MaxHeapAttributeNumber)
- ereport(ERROR,
- (errcode(ERRCODE_TOO_MANY_COLUMNS),
- errmsg("tables can have at most %d columns",
- MaxHeapAttributeNumber)));
- }
+ newattnum = ((Form_pg_class) GETSTRUCT(reltup))->relnatts + 1;
+ if (newattnum > MaxHeapAttributeNumber)
+ ereport(ERROR,
+ (errcode(ERRCODE_TOO_MANY_COLUMNS),
+ errmsg("tables can have at most %d columns",
+ MaxHeapAttributeNumber)));
typeTuple = typenameType(NULL, colDef->typeName, &typmod);
tform = (Form_pg_type) GETSTRUCT(typeTuple);
- typeOid = HeapTupleGetOid(typeTuple);
+ typeOid = tform->oid;
aclresult = pg_type_aclcheck(typeOid, GetUserId(), ACL_USAGE);
if (aclresult != ACLCHECK_OK)
@@ -5564,10 +5471,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
/*
* Update pg_class tuple as appropriate
*/
- if (isOid)
- ((Form_pg_class) GETSTRUCT(reltup))->relhasoids = true;
- else
- ((Form_pg_class) GETSTRUCT(reltup))->relnatts = newattnum;
+ ((Form_pg_class) GETSTRUCT(reltup))->relnatts = newattnum;
CatalogTupleUpdate(pgclass, &reltup->t_self, reltup);
@@ -5716,13 +5620,6 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
}
/*
- * If we are adding an OID column, we have to tell Phase 3 to rewrite the
- * table to fix that.
- */
- if (isOid)
- tab->rewrite |= AT_REWRITE_ALTER_OID;
-
- /*
* Add needed dependency entries for the new column.
*/
add_column_datatype_dependency(myrelid, newattnum, attribute.atttypid);
@@ -5767,7 +5664,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
/* Recurse to child; return value is ignored */
ATExecAddColumn(wqueue, childtab, childrel,
- colDef, isOid, recurse, true,
+ colDef, recurse, true,
if_not_exists, lockmode);
heap_close(childrel, NoLock);
@@ -5872,35 +5769,6 @@ add_column_collation_dependency(Oid relid, int32 attnum, Oid collid)
}
/*
- * ALTER TABLE SET WITH OIDS
- *
- * Basically this is an ADD COLUMN for the special OID column. We have
- * to cons up a ColumnDef node because the ADD COLUMN code needs one.
- */
-static void
-ATPrepAddOids(List **wqueue, Relation rel, bool recurse, AlterTableCmd *cmd, LOCKMODE lockmode)
-{
- /* If we're recursing to a child table, the ColumnDef is already set up */
- if (cmd->def == NULL)
- {
- ColumnDef *cdef = makeNode(ColumnDef);
-
- cdef->colname = pstrdup("oid");
- cdef->typeName = makeTypeNameFromOid(OIDOID, -1);
- cdef->inhcount = 0;
- cdef->is_local = true;
- cdef->is_not_null = true;
- cdef->storage = 0;
- cdef->location = -1;
- cmd->def = (Node *) cdef;
- }
- ATPrepAddColumn(wqueue, rel, recurse, false, false, cmd, lockmode);
-
- if (recurse)
- cmd->subtype = AT_AddOidsRecurse;
-}
-
-/*
* ALTER TABLE ALTER COLUMN DROP NOT NULL
*
* Return the address of the modified column. If the column was already
@@ -6801,8 +6669,8 @@ ATExecDropColumn(List **wqueue, Relation rel, const char *colName,
attnum = targetatt->attnum;
- /* Can't drop a system attribute, except OID */
- if (attnum <= 0 && attnum != ObjectIdAttributeNumber)
+ /* Can't drop a system attribute */
+ if (attnum <= 0)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot drop system column \"%s\"",
@@ -6932,39 +6800,6 @@ ATExecDropColumn(List **wqueue, Relation rel, const char *colName,
performDeletion(&object, behavior, 0);
- /*
- * If we dropped the OID column, must adjust pg_class.relhasoids and tell
- * Phase 3 to physically get rid of the column. We formerly left the
- * column in place physically, but this caused subtle problems. See
- * http://archives.postgresql.org/pgsql-hackers/2009-02/msg00363.php
- */
- if (attnum == ObjectIdAttributeNumber)
- {
- Relation class_rel;
- Form_pg_class tuple_class;
- AlteredTableInfo *tab;
-
- class_rel = heap_open(RelationRelationId, RowExclusiveLock);
-
- tuple = SearchSysCacheCopy1(RELOID,
- ObjectIdGetDatum(RelationGetRelid(rel)));
- if (!HeapTupleIsValid(tuple))
- elog(ERROR, "cache lookup failed for relation %u",
- RelationGetRelid(rel));
- tuple_class = (Form_pg_class) GETSTRUCT(tuple);
-
- tuple_class->relhasoids = false;
- CatalogTupleUpdate(class_rel, &tuple->t_self, tuple);
-
- heap_close(class_rel, RowExclusiveLock);
-
- /* Find or create work queue entry for this table */
- tab = ATGetQueueEntry(wqueue, rel);
-
- /* Tell Phase 3 to physically remove the OID column */
- tab->rewrite |= AT_REWRITE_ALTER_OID;
- }
-
return object;
}
@@ -7878,7 +7713,7 @@ ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
CatalogTupleUpdate(conrel, &copyTuple->t_self, copyTuple);
InvokeObjectPostAlterHook(ConstraintRelationId,
- HeapTupleGetOid(contuple), 0);
+ currcon->oid, 0);
heap_freetuple(copyTuple);
@@ -7891,7 +7726,7 @@ ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
ScanKeyInit(&tgkey,
Anum_pg_trigger_tgconstraint,
BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(HeapTupleGetOid(contuple)));
+ ObjectIdGetDatum(currcon->oid));
tgscan = systable_beginscan(tgrel, TriggerConstraintIndexId, true,
NULL, 1, &tgkey);
@@ -7930,8 +7765,7 @@ ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
copy_tg->tginitdeferred = cmdcon->initdeferred;
CatalogTupleUpdate(tgrel, &copyTuple->t_self, copyTuple);
- InvokeObjectPostAlterHook(TriggerRelationId,
- HeapTupleGetOid(tgtuple), 0);
+ InvokeObjectPostAlterHook(TriggerRelationId, currcon->oid, 0);
heap_freetuple(copyTuple);
}
@@ -7952,8 +7786,7 @@ ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
CacheInvalidateRelcacheByRelid(lfirst_oid(lc));
}
- ObjectAddressSet(address, ConstraintRelationId,
- HeapTupleGetOid(contuple));
+ ObjectAddressSet(address, ConstraintRelationId, currcon->oid);
}
else
address = InvalidObjectAddress;
@@ -8043,7 +7876,7 @@ ATExecValidateConstraint(Relation rel, char *constrName, bool recurse,
validateForeignKeyConstraint(constrName, rel, refrel,
con->conindid,
- HeapTupleGetOid(tuple));
+ con->oid);
heap_close(refrel, NoLock);
/*
@@ -8116,13 +7949,11 @@ ATExecValidateConstraint(Relation rel, char *constrName, bool recurse,
copy_con->convalidated = true;
CatalogTupleUpdate(conrel, &copyTuple->t_self, copyTuple);
- InvokeObjectPostAlterHook(ConstraintRelationId,
- HeapTupleGetOid(tuple), 0);
+ InvokeObjectPostAlterHook(ConstraintRelationId, con->oid, 0);
heap_freetuple(copyTuple);
- ObjectAddressSet(address, ConstraintRelationId,
- HeapTupleGetOid(tuple));
+ ObjectAddressSet(address, ConstraintRelationId, con->oid);
}
else
address = InvalidObjectAddress; /* already validated */
@@ -8520,7 +8351,7 @@ validateCheckConstraint(Relation rel, HeapTuple constrtup)
&isnull);
if (isnull)
elog(ERROR, "null conbin for constraint %u",
- HeapTupleGetOid(constrtup));
+ constrForm->oid);
conbin = TextDatumGetCString(val);
origexpr = (Expr *) stringToNode(conbin);
exprstate = ExecPrepareExpr(origexpr, estate);
@@ -8944,7 +8775,7 @@ ATExecDropConstraint(Relation rel, const char *constrName,
* Perform the actual constraint deletion
*/
conobj.classId = ConstraintRelationId;
- conobj.objectId = HeapTupleGetOid(tuple);
+ conobj.objectId = con->oid;
conobj.objectSubId = 0;
performDeletion(&conobj, behavior, 0);
@@ -9419,7 +9250,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
/* Look up the target type (should not fail, since prep found it) */
typeTuple = typenameType(NULL, typeName, &targettypmod);
tform = (Form_pg_type) GETSTRUCT(typeTuple);
- targettype = HeapTupleGetOid(typeTuple);
+ targettype = tform->oid;
/* And the collation */
targetcollid = GetColumnDefCollation(NULL, def, targettype);
@@ -11229,10 +11060,8 @@ AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
scan = heap_beginscan_catalog(rel, 1, key);
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
- Oid relOid = HeapTupleGetOid(tuple);
- Form_pg_class relForm;
-
- relForm = (Form_pg_class) GETSTRUCT(tuple);
+ Form_pg_class relForm = (Form_pg_class) GETSTRUCT(tuple);
+ Oid relOid = relForm->oid;
/*
* Do not move objects in pg_catalog as part of this, if an admin
@@ -11536,14 +11365,6 @@ ATExecAddInherit(Relation child_rel, RangeVar *parent, LOCKMODE lockmode)
parent->relname,
RelationGetRelationName(child_rel))));
- /* If parent has OIDs then child must have OIDs */
- if (parent_rel->rd_rel->relhasoids && !child_rel->rd_rel->relhasoids)
- ereport(ERROR,
- (errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("table \"%s\" without OIDs cannot inherit from table \"%s\" with OIDs",
- RelationGetRelationName(child_rel),
- RelationGetRelationName(parent_rel))));
-
/*
* If child_rel has row-level triggers with transition tables, we
* currently don't allow it to become an inheritance child. See also
@@ -11656,7 +11477,7 @@ decompile_conbin(HeapTuple contup, TupleDesc tupdesc)
con = (Form_pg_constraint) GETSTRUCT(contup);
attr = heap_getattr(contup, Anum_pg_constraint_conbin, tupdesc, &isnull);
if (isnull)
- elog(ERROR, "null conbin for constraint %u", HeapTupleGetOid(contup));
+ elog(ERROR, "null conbin for constraint %u", con->oid);
expr = DirectFunctionCall2(pg_get_expr, attr,
ObjectIdGetDatum(con->conrelid));
@@ -11790,45 +11611,6 @@ MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel)
}
}
- /*
- * If the parent has an OID column, so must the child, and we'd better
- * update the child's attinhcount and attislocal the same as for normal
- * columns. We needn't check data type or not-nullness though.
- */
- if (tupleDesc->tdhasoid)
- {
- /*
- * Here we match by column number not name; the match *must* be the
- * system column, not some random column named "oid".
- */
- tuple = SearchSysCacheCopy2(ATTNUM,
- ObjectIdGetDatum(RelationGetRelid(child_rel)),
- Int16GetDatum(ObjectIdAttributeNumber));
- if (HeapTupleIsValid(tuple))
- {
- Form_pg_attribute childatt = (Form_pg_attribute) GETSTRUCT(tuple);
-
- /* See comments above; these changes should be the same */
- childatt->attinhcount++;
-
- if (child_is_partition)
- {
- Assert(childatt->attinhcount == 1);
- childatt->attislocal = false;
- }
-
- CatalogTupleUpdate(attrrel, &tuple->t_self, tuple);
- heap_freetuple(tuple);
- }
- else
- {
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("child table is missing column \"%s\"",
- "oid")));
- }
- }
-
heap_close(attrrel, RowExclusiveLock);
}
@@ -12258,6 +12040,7 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
{
Oid relid = RelationGetRelid(rel);
Type typetuple;
+ Form_pg_type typeform;
Oid typeid;
Relation inheritsRelation,
relationRelation;
@@ -12274,7 +12057,8 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
/* Validate the type. */
typetuple = typenameType(NULL, ofTypename, NULL);
check_of_type(typetuple);
- typeid = HeapTupleGetOid(typetuple);
+ typeform = (Form_pg_type) GETSTRUCT(typetuple);
+ typeid = typeform->oid;
/* Fail if the table has any inheritance parents. */
inheritsRelation = heap_open(InheritsRelationId, AccessShareLock);
@@ -12294,7 +12078,6 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
/*
* Check the tuple descriptors for compatibility. Unlike inheritance, we
* require that the order also match. However, attnotnull need not match.
- * Also unlike inheritance, we do not require matching relhasoids.
*/
typeTupleDesc = lookup_rowtype_tupdesc(typeid, -1);
tableTupleDesc = RelationGetDescr(rel);
@@ -12619,10 +12402,6 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode
int16 attno = indexRel->rd_index->indkey.values[key];
Form_pg_attribute attr;
- /* Allow OID column to be indexed; it's certainly not nullable */
- if (attno == ObjectIdAttributeNumber)
- continue;
-
/*
* Reject any other system columns. (Going forward, we'll disallow
* indexes containing such columns in the first place, but they might
@@ -14292,22 +14071,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot attach temporary relation of another session as partition")));
- /* If parent has OIDs then child must have OIDs */
- if (rel->rd_rel->relhasoids && !attachrel->rd_rel->relhasoids)
- ereport(ERROR,
- (errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("cannot attach table \"%s\" without OIDs as partition of"
- " table \"%s\" with OIDs", RelationGetRelationName(attachrel),
- RelationGetRelationName(rel))));
-
- /* OTOH, if parent doesn't have them, do not allow in attachrel either */
- if (attachrel->rd_rel->relhasoids && !rel->rd_rel->relhasoids)
- ereport(ERROR,
- (errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("cannot attach table \"%s\" with OIDs as partition of table"
- " \"%s\" without OIDs", RelationGetRelationName(attachrel),
- RelationGetRelationName(rel))));
-
/* Check if there are any columns in attachrel that aren't in the parent */
tupleDesc = RelationGetDescr(attachrel);
natts = tupleDesc->natts;
@@ -14728,7 +14491,7 @@ CloneRowTriggersToPartition(Relation parent, Relation partition)
CreateTrigger(trigStmt, NULL, RelationGetRelid(partition),
trigForm->tgconstrrelid, InvalidOid, InvalidOid,
- trigForm->tgfoid, HeapTupleGetOid(tuple), qual,
+ trigForm->tgfoid, trigForm->oid, qual,
false, true);
MemoryContextReset(perTupCxt);
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index f7e9160a4f6..4a714f6e2be 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -327,6 +327,9 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
MemSet(nulls, false, sizeof(nulls));
+ tablespaceoid = GetNewOidWithIndex(rel, TablespaceOidIndexId,
+ Anum_pg_tablespace_oid);
+ values[Anum_pg_tablespace_oid - 1] = ObjectIdGetDatum(tablespaceoid);
values[Anum_pg_tablespace_spcname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(stmt->tablespacename));
values[Anum_pg_tablespace_spcowner - 1] =
@@ -345,7 +348,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
tuple = heap_form_tuple(rel->rd_att, values, nulls);
- tablespaceoid = CatalogTupleInsert(rel, tuple);
+ CatalogTupleInsert(rel, tuple);
heap_freetuple(tuple);
@@ -406,6 +409,7 @@ DropTableSpace(DropTableSpaceStmt *stmt)
HeapScanDesc scandesc;
Relation rel;
HeapTuple tuple;
+ Form_pg_tablespace spcform;
ScanKeyData entry[1];
Oid tablespaceoid;
@@ -442,7 +446,8 @@ DropTableSpace(DropTableSpaceStmt *stmt)
return;
}
- tablespaceoid = HeapTupleGetOid(tuple);
+ spcform = (Form_pg_tablespace) GETSTRUCT(tuple);
+ tablespaceoid = spcform->oid;
/* Must be tablespace owner */
if (!pg_tablespace_ownercheck(tablespaceoid, GetUserId()))
@@ -935,14 +940,14 @@ RenameTableSpace(const char *oldname, const char *newname)
errmsg("tablespace \"%s\" does not exist",
oldname)));
- tspId = HeapTupleGetOid(tup);
newtuple = heap_copytuple(tup);
newform = (Form_pg_tablespace) GETSTRUCT(newtuple);
+ tspId = newform->oid;
heap_endscan(scan);
/* Must be owner */
- if (!pg_tablespace_ownercheck(HeapTupleGetOid(newtuple), GetUserId()))
+ if (!pg_tablespace_ownercheck(tspId, GetUserId()))
aclcheck_error(ACLCHECK_NO_PRIV, OBJECT_TABLESPACE, oldname);
/* Validate new name */
@@ -1015,10 +1020,10 @@ AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
errmsg("tablespace \"%s\" does not exist",
stmt->tablespacename)));
- tablespaceoid = HeapTupleGetOid(tup);
+ tablespaceoid = ((Form_pg_tablespace) GETSTRUCT(tup))->oid;
/* Must be owner of the existing object */
- if (!pg_tablespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ if (!pg_tablespace_ownercheck(tablespaceoid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_TABLESPACE,
stmt->tablespacename);
@@ -1044,7 +1049,7 @@ AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
/* Update system catalog. */
CatalogTupleUpdate(rel, &newtuple->t_self, newtuple);
- InvokeObjectPostAlterHook(TableSpaceRelationId, HeapTupleGetOid(tup), 0);
+ InvokeObjectPostAlterHook(TableSpaceRelationId, tablespaceoid, 0);
heap_freetuple(newtuple);
@@ -1403,7 +1408,7 @@ get_tablespace_oid(const char *tablespacename, bool missing_ok)
/* We assume that there can be at most one matching tuple */
if (HeapTupleIsValid(tuple))
- result = HeapTupleGetOid(tuple);
+ result = ((Form_pg_tablespace) GETSTRUCT(tuple))->oid;
else
result = InvalidOid;
@@ -1441,7 +1446,7 @@ get_tablespace_name(Oid spc_oid)
rel = heap_open(TableSpaceRelationId, AccessShareLock);
ScanKeyInit(&entry[0],
- ObjectIdAttributeNumber,
+ Anum_pg_tablespace_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(spc_oid));
scandesc = heap_beginscan_catalog(rel, 1, entry);
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index b91ebdb3d04..bcdd86ce92f 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -764,7 +764,8 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
*/
tgrel = heap_open(TriggerRelationId, RowExclusiveLock);
- trigoid = GetNewOid(tgrel);
+ trigoid = GetNewOidWithIndex(tgrel, TriggerOidIndexId,
+ Anum_pg_trigger_oid);
/*
* If trigger is internally generated, modify the provided trigger name to
@@ -824,6 +825,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
*/
memset(nulls, false, sizeof(nulls));
+ values[Anum_pg_trigger_oid - 1] = ObjectIdGetDatum(trigoid);
values[Anum_pg_trigger_tgrelid - 1] = ObjectIdGetDatum(RelationGetRelid(rel));
values[Anum_pg_trigger_tgname - 1] = DirectFunctionCall1(namein,
CStringGetDatum(trigname));
@@ -940,9 +942,6 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
tuple = heap_form_tuple(tgrel->rd_att, values, nulls);
- /* force tuple to have the desired OID */
- HeapTupleSetOid(tuple, trigoid);
-
/*
* Insert tuple into pg_trigger.
*/
@@ -1494,7 +1493,7 @@ RemoveTriggerById(Oid trigOid)
* Find the trigger to delete.
*/
ScanKeyInit(&skey[0],
- ObjectIdAttributeNumber,
+ Anum_pg_trigger_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(trigOid));
@@ -1595,7 +1594,7 @@ get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
}
else
{
- oid = HeapTupleGetOid(tup);
+ oid = ((Form_pg_trigger) GETSTRUCT(tup))->oid;
}
systable_endscan(tgscan);
@@ -1722,20 +1721,22 @@ renametrig(RenameStmt *stmt)
NULL, 2, key);
if (HeapTupleIsValid(tuple = systable_getnext(tgscan)))
{
- tgoid = HeapTupleGetOid(tuple);
+ Form_pg_trigger trigform = (Form_pg_trigger) GETSTRUCT(tuple);
+
+ tgoid = trigform->oid;
/*
* Update pg_trigger tuple with new tgname.
*/
tuple = heap_copytuple(tuple); /* need a modifiable copy */
- namestrcpy(&((Form_pg_trigger) GETSTRUCT(tuple))->tgname,
+ namestrcpy(&trigform->tgname,
stmt->newname);
CatalogTupleUpdate(tgrel, &tuple->t_self, tuple);
InvokeObjectPostAlterHook(TriggerRelationId,
- HeapTupleGetOid(tuple), 0);
+ tgoid, 0);
/*
* Invalidate relation's relcache entry so that other backends (and
@@ -1874,7 +1875,7 @@ EnableDisableTrigger(Relation rel, const char *tgname,
}
InvokeObjectPostAlterHook(TriggerRelationId,
- HeapTupleGetOid(tuple), 0);
+ oldtrig->oid, 0);
}
systable_endscan(tgscan);
@@ -1958,7 +1959,7 @@ RelationBuildTriggers(Relation relation)
}
build = &(triggers[numtrigs]);
- build->tgoid = HeapTupleGetOid(htup);
+ build->tgoid = pg_trigger->oid;
build->tgname = DatumGetCString(DirectFunctionCall1(nameout,
NameGetDatum(&pg_trigger->tgname)));
build->tgfoid = pg_trigger->tgfoid;
@@ -5463,8 +5464,7 @@ AfterTriggerSetState(ConstraintsSetStmt *stmt)
Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup);
if (con->condeferrable)
- conoidlist = lappend_oid(conoidlist,
- HeapTupleGetOid(tup));
+ conoidlist = lappend_oid(conoidlist, con->oid);
else if (stmt->deferred)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
@@ -5516,7 +5516,11 @@ AfterTriggerSetState(ConstraintsSetStmt *stmt)
scan = systable_beginscan(conrel, ConstraintParentIndexId, true, NULL, 1, &key);
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
- conoidlist = lappend_oid(conoidlist, HeapTupleGetOid(tuple));
+ {
+ Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tuple);
+
+ conoidlist = lappend_oid(conoidlist, con->oid);
+ }
systable_endscan(scan);
}
@@ -5558,8 +5562,7 @@ AfterTriggerSetState(ConstraintsSetStmt *stmt)
* actions.
*/
if (pg_trigger->tgdeferrable)
- tgoidlist = lappend_oid(tgoidlist,
- HeapTupleGetOid(htup));
+ tgoidlist = lappend_oid(tgoidlist, pg_trigger->oid);
found = true;
}
diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c
index 3a843512d13..06404353d22 100644
--- a/src/backend/commands/tsearchcmds.c
+++ b/src/backend/commands/tsearchcmds.c
@@ -21,6 +21,7 @@
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/xact.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
@@ -132,7 +133,7 @@ makeParserDependencies(HeapTuple tuple)
referenced;
myself.classId = TSParserRelationId;
- myself.objectId = HeapTupleGetOid(tuple);
+ myself.objectId = prs->oid;
myself.objectSubId = 0;
/* dependency on namespace */
@@ -191,6 +192,8 @@ DefineTSParser(List *names, List *parameters)
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to create text search parsers")));
+ prsRel = heap_open(TSParserRelationId, RowExclusiveLock);
+
/* Convert list of names to a name and namespace */
namespaceoid = QualifiedNameGetCreationNamespace(names, &prsname);
@@ -198,6 +201,9 @@ DefineTSParser(List *names, List *parameters)
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ prsOid = GetNewOidWithIndex(prsRel, TSParserOidIndexId,
+ Anum_pg_ts_parser_oid);
+ values[Anum_pg_ts_parser_oid - 1] = ObjectIdGetDatum(prsOid);
namestrcpy(&pname, prsname);
values[Anum_pg_ts_parser_prsname - 1] = NameGetDatum(&pname);
values[Anum_pg_ts_parser_prsnamespace - 1] = ObjectIdGetDatum(namespaceoid);
@@ -267,11 +273,9 @@ DefineTSParser(List *names, List *parameters)
/*
* Looks good, insert
*/
- prsRel = heap_open(TSParserRelationId, RowExclusiveLock);
-
tup = heap_form_tuple(prsRel->rd_att, values, nulls);
- prsOid = CatalogTupleInsert(prsRel, tup);
+ CatalogTupleInsert(prsRel, tup);
address = makeParserDependencies(tup);
@@ -323,7 +327,7 @@ makeDictionaryDependencies(HeapTuple tuple)
referenced;
myself.classId = TSDictionaryRelationId;
- myself.objectId = HeapTupleGetOid(tuple);
+ myself.objectId = dict->oid;
myself.objectSubId = 0;
/* dependency on namespace */
@@ -459,12 +463,18 @@ DefineTSDictionary(List *names, List *parameters)
verify_dictoptions(templId, dictoptions);
+
+ dictRel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
+
/*
* Looks good, insert
*/
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ dictOid = GetNewOidWithIndex(dictRel, TSDictionaryOidIndexId,
+ Anum_pg_ts_dict_oid);
+ values[Anum_pg_ts_dict_oid - 1] = ObjectIdGetDatum(dictOid);
namestrcpy(&dname, dictname);
values[Anum_pg_ts_dict_dictname - 1] = NameGetDatum(&dname);
values[Anum_pg_ts_dict_dictnamespace - 1] = ObjectIdGetDatum(namespaceoid);
@@ -476,11 +486,9 @@ DefineTSDictionary(List *names, List *parameters)
else
nulls[Anum_pg_ts_dict_dictinitoption - 1] = true;
- dictRel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
-
tup = heap_form_tuple(dictRel->rd_att, values, nulls);
- dictOid = CatalogTupleInsert(dictRel, tup);
+ CatalogTupleInsert(dictRel, tup);
address = makeDictionaryDependencies(tup);
@@ -694,7 +702,7 @@ makeTSTemplateDependencies(HeapTuple tuple)
referenced;
myself.classId = TSTemplateRelationId;
- myself.objectId = HeapTupleGetOid(tuple);
+ myself.objectId = tmpl->oid;
myself.objectSubId = 0;
/* dependency on namespace */
@@ -748,12 +756,17 @@ DefineTSTemplate(List *names, List *parameters)
/* Convert list of names to a name and namespace */
namespaceoid = QualifiedNameGetCreationNamespace(names, &tmplname);
+ tmplRel = heap_open(TSTemplateRelationId, RowExclusiveLock);
+
for (i = 0; i < Natts_pg_ts_template; i++)
{
nulls[i] = false;
values[i] = ObjectIdGetDatum(InvalidOid);
}
+ tmplOid = GetNewOidWithIndex(tmplRel, TSTemplateOidIndexId,
+ Anum_pg_ts_dict_oid);
+ values[Anum_pg_ts_template_oid - 1] = ObjectIdGetDatum(tmplOid);
namestrcpy(&dname, tmplname);
values[Anum_pg_ts_template_tmplname - 1] = NameGetDatum(&dname);
values[Anum_pg_ts_template_tmplnamespace - 1] = ObjectIdGetDatum(namespaceoid);
@@ -795,12 +808,9 @@ DefineTSTemplate(List *names, List *parameters)
/*
* Looks good, insert
*/
-
- tmplRel = heap_open(TSTemplateRelationId, RowExclusiveLock);
-
tup = heap_form_tuple(tmplRel->rd_att, values, nulls);
- tmplOid = CatalogTupleInsert(tmplRel, tup);
+ CatalogTupleInsert(tmplRel, tup);
address = makeTSTemplateDependencies(tup);
@@ -879,7 +889,7 @@ makeConfigurationDependencies(HeapTuple tuple, bool removeOld,
referenced;
myself.classId = TSConfigRelationId;
- myself.objectId = HeapTupleGetOid(tuple);
+ myself.objectId = cfg->oid;
myself.objectSubId = 0;
/* for ALTER case, first flush old dependencies, except extension deps */
@@ -1042,23 +1052,26 @@ DefineTSConfiguration(List *names, List *parameters, ObjectAddress *copied)
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("text search parser is required")));
+ cfgRel = heap_open(TSConfigRelationId, RowExclusiveLock);
+
/*
* Looks good, build tuple and insert
*/
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
+ cfgOid = GetNewOidWithIndex(cfgRel, TSConfigOidIndexId,
+ Anum_pg_ts_config_oid);
+ values[Anum_pg_ts_config_oid - 1] = ObjectIdGetDatum(cfgOid);
namestrcpy(&cname, cfgname);
values[Anum_pg_ts_config_cfgname - 1] = NameGetDatum(&cname);
values[Anum_pg_ts_config_cfgnamespace - 1] = ObjectIdGetDatum(namespaceoid);
values[Anum_pg_ts_config_cfgowner - 1] = ObjectIdGetDatum(GetUserId());
values[Anum_pg_ts_config_cfgparser - 1] = ObjectIdGetDatum(prsOid);
- cfgRel = heap_open(TSConfigRelationId, RowExclusiveLock);
-
tup = heap_form_tuple(cfgRel->rd_att, values, nulls);
- cfgOid = CatalogTupleInsert(cfgRel, tup);
+ CatalogTupleInsert(cfgRel, tup);
if (OidIsValid(sourceOid))
{
@@ -1185,10 +1198,10 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
errmsg("text search configuration \"%s\" does not exist",
NameListToString(stmt->cfgname))));
- cfgId = HeapTupleGetOid(tup);
+ cfgId = ((Form_pg_ts_config) GETSTRUCT(tup))->oid;
/* must be owner */
- if (!pg_ts_config_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ if (!pg_ts_config_ownercheck(cfgId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_TSCONFIGURATION,
NameListToString(stmt->cfgname));
@@ -1203,8 +1216,7 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
/* Update dependencies */
makeConfigurationDependencies(tup, true, relMap);
- InvokeObjectPostAlterHook(TSConfigRelationId,
- HeapTupleGetOid(tup), 0);
+ InvokeObjectPostAlterHook(TSConfigRelationId, cfgId, 0);
ObjectAddressSet(address, TSConfigRelationId, cfgId);
@@ -1277,7 +1289,8 @@ static void
MakeConfigurationMapping(AlterTSConfigurationStmt *stmt,
HeapTuple tup, Relation relMap)
{
- Oid cfgId = HeapTupleGetOid(tup);
+ Form_pg_ts_config tsform;
+ Oid cfgId;
ScanKeyData skey[2];
SysScanDesc scan;
HeapTuple maptup;
@@ -1290,7 +1303,9 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt,
int ndict;
ListCell *c;
- prsId = ((Form_pg_ts_config) GETSTRUCT(tup))->cfgparser;
+ tsform = (Form_pg_ts_config) GETSTRUCT(tup);
+ cfgId = tsform->oid;
+ prsId = tsform->cfgparser;
tokens = getTokenTypes(prsId, stmt->tokentype);
ntoken = list_length(stmt->tokentype);
@@ -1438,7 +1453,8 @@ static void
DropConfigurationMapping(AlterTSConfigurationStmt *stmt,
HeapTuple tup, Relation relMap)
{
- Oid cfgId = HeapTupleGetOid(tup);
+ Form_pg_ts_config tsform;
+ Oid cfgId;
ScanKeyData skey[2];
SysScanDesc scan;
HeapTuple maptup;
@@ -1447,7 +1463,9 @@ DropConfigurationMapping(AlterTSConfigurationStmt *stmt,
int *tokens;
ListCell *c;
- prsId = ((Form_pg_ts_config) GETSTRUCT(tup))->cfgparser;
+ tsform = (Form_pg_ts_config) GETSTRUCT(tup);
+ cfgId = tsform->oid;
+ prsId = tsform->cfgparser;
tokens = getTokenTypes(prsId, stmt->tokentype);
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 285a0be6436..1ffc8231d46 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -195,7 +195,7 @@ DefineType(ParseState *pstate, List *names, List *parameters)
* Look to see if type already exists (presumably as a shell; if not,
* TypeCreate will complain).
*/
- typoid = GetSysCacheOid2(TYPENAMENSP,
+ typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
CStringGetDatum(typeName),
ObjectIdGetDatum(typeNamespace));
@@ -776,7 +776,7 @@ DefineDomain(CreateDomainStmt *stmt)
* Check for collision with an existing type name. If there is one and
* it's an autogenerated array, we can rename it out of the way.
*/
- old_type_oid = GetSysCacheOid2(TYPENAMENSP,
+ old_type_oid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
CStringGetDatum(domainName),
ObjectIdGetDatum(domainNamespace));
if (OidIsValid(old_type_oid))
@@ -792,7 +792,7 @@ DefineDomain(CreateDomainStmt *stmt)
*/
typeTup = typenameType(NULL, stmt->typeName, &basetypeMod);
baseType = (Form_pg_type) GETSTRUCT(typeTup);
- basetypeoid = HeapTupleGetOid(typeTup);
+ basetypeoid = baseType->oid;
/*
* Base type must be a plain base type, a composite type, another domain,
@@ -1175,7 +1175,7 @@ DefineEnum(CreateEnumStmt *stmt)
* Check for collision with an existing type name. If there is one and
* it's an autogenerated array, we can rename it out of the way.
*/
- old_type_oid = GetSysCacheOid2(TYPENAMENSP,
+ old_type_oid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
CStringGetDatum(enumName),
ObjectIdGetDatum(enumNamespace));
if (OidIsValid(old_type_oid))
@@ -1330,11 +1330,11 @@ checkEnumOwner(HeapTuple tup)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("%s is not an enum",
- format_type_be(HeapTupleGetOid(tup)))));
+ format_type_be(typTup->oid))));
/* Permission check: must own type */
- if (!pg_type_ownercheck(HeapTupleGetOid(tup), GetUserId()))
- aclcheck_error_type(ACLCHECK_NOT_OWNER, HeapTupleGetOid(tup));
+ if (!pg_type_ownercheck(typTup->oid, GetUserId()))
+ aclcheck_error_type(ACLCHECK_NOT_OWNER, typTup->oid);
}
@@ -1380,7 +1380,7 @@ DefineRange(CreateRangeStmt *stmt)
/*
* Look to see if type already exists.
*/
- typoid = GetSysCacheOid2(TYPENAMENSP,
+ typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
CStringGetDatum(typeName),
ObjectIdGetDatum(typeNamespace));
@@ -2090,7 +2090,8 @@ AssignTypeArrayOid(void)
{
Relation pg_type = heap_open(TypeRelationId, AccessShareLock);
- type_array_oid = GetNewOid(pg_type);
+ type_array_oid = GetNewOidWithIndex(pg_type, TypeOidIndexId,
+ Anum_pg_type_oid);
heap_close(pg_type, AccessShareLock);
}
@@ -2142,7 +2143,7 @@ DefineCompositeType(RangeVar *typevar, List *coldeflist)
NoLock, NULL);
RangeVarAdjustRelationPersistence(createStmt->relation, typeNamespace);
old_type_oid =
- GetSysCacheOid2(TYPENAMENSP,
+ GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
CStringGetDatum(createStmt->relation->relname),
ObjectIdGetDatum(typeNamespace));
if (OidIsValid(old_type_oid))
@@ -2482,7 +2483,7 @@ AlterDomainDropConstraint(List *names, const char *constrName,
ObjectAddress conobj;
conobj.classId = ConstraintRelationId;
- conobj.objectId = HeapTupleGetOid(contup);
+ conobj.objectId = ((Form_pg_constraint) GETSTRUCT(contup))->oid;
conobj.objectSubId = 0;
performDeletion(&conobj, behavior, 0);
@@ -2700,7 +2701,7 @@ AlterDomainValidateConstraint(List *names, const char *constrName)
&isnull);
if (isnull)
elog(ERROR, "null conbin for constraint %u",
- HeapTupleGetOid(tuple));
+ con->oid);
conbin = TextDatumGetCString(val);
validateDomainConstraint(domainoid, conbin);
@@ -2713,8 +2714,7 @@ AlterDomainValidateConstraint(List *names, const char *constrName)
copy_con->convalidated = true;
CatalogTupleUpdate(conrel, &copyTuple->t_self, copyTuple);
- InvokeObjectPostAlterHook(ConstraintRelationId,
- HeapTupleGetOid(copyTuple), 0);
+ InvokeObjectPostAlterHook(ConstraintRelationId, con->oid, 0);
ObjectAddressSet(address, TypeRelationId, domainoid);
@@ -3027,11 +3027,11 @@ checkDomainOwner(HeapTuple tup)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("%s is not a domain",
- format_type_be(HeapTupleGetOid(tup)))));
+ format_type_be(typTup->oid))));
/* Permission check: must own type */
- if (!pg_type_ownercheck(HeapTupleGetOid(tup), GetUserId()))
- aclcheck_error_type(ACLCHECK_NOT_OWNER, HeapTupleGetOid(tup));
+ if (!pg_type_ownercheck(typTup->oid, GetUserId()))
+ aclcheck_error_type(ACLCHECK_NOT_OWNER, typTup->oid);
}
/*
@@ -3342,8 +3342,8 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
if (!superuser())
{
/* Otherwise, must be owner of the existing object */
- if (!pg_type_ownercheck(HeapTupleGetOid(tup), GetUserId()))
- aclcheck_error_type(ACLCHECK_NOT_OWNER, HeapTupleGetOid(tup));
+ if (!pg_type_ownercheck(typTup->oid, GetUserId()))
+ aclcheck_error_type(ACLCHECK_NOT_OWNER, typTup->oid);
/* Must be able to become new owner */
check_is_member_of_role(GetUserId(), newOwnerId);
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 71c5caa41b9..12afa18709e 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -423,8 +423,6 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
new_record[Anum_pg_authid_rolbypassrls - 1] = BoolGetDatum(bypassrls);
- tuple = heap_form_tuple(pg_authid_dsc, new_record, new_record_nulls);
-
/*
* pg_largeobject_metadata contains pg_authid.oid's, so we use the
* binary-upgrade override.
@@ -436,14 +434,23 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("pg_authid OID value not set when in binary upgrade mode")));
- HeapTupleSetOid(tuple, binary_upgrade_next_pg_authid_oid);
+ roleid = binary_upgrade_next_pg_authid_oid;
binary_upgrade_next_pg_authid_oid = InvalidOid;
}
+ else
+ {
+ roleid = GetNewOidWithIndex(pg_authid_rel, AuthIdOidIndexId,
+ Anum_pg_authid_oid);
+ }
+
+ new_record[Anum_pg_authid_oid - 1] = ObjectIdGetDatum(roleid);
+
+ tuple = heap_form_tuple(pg_authid_dsc, new_record, new_record_nulls);
/*
* Insert new record in the pg_authid table
*/
- roleid = CatalogTupleInsert(pg_authid_rel, tuple);
+ CatalogTupleInsert(pg_authid_rel, tuple);
/*
* Advance command counter so we can see new record; else tests in
@@ -459,8 +466,9 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
{
RoleSpec *oldrole = lfirst(item);
HeapTuple oldroletup = get_rolespec_tuple(oldrole);
- Oid oldroleid = HeapTupleGetOid(oldroletup);
- char *oldrolename = NameStr(((Form_pg_authid) GETSTRUCT(oldroletup))->rolname);
+ Form_pg_authid oldroleform = (Form_pg_authid) GETSTRUCT(oldroletup);
+ Oid oldroleid = oldroleform->oid;
+ char *oldrolename = NameStr(oldroleform->rolname);
AddRoleMems(oldrolename, oldroleid,
list_make1(makeString(stmt->role)),
@@ -679,7 +687,7 @@ AlterRole(AlterRoleStmt *stmt)
tuple = get_rolespec_tuple(stmt->role);
authform = (Form_pg_authid) GETSTRUCT(tuple);
rolename = pstrdup(NameStr(authform->rolname));
- roleid = HeapTupleGetOid(tuple);
+ roleid = authform->oid;
/*
* To mess with a superuser you gotta be superuser; else you need
@@ -886,6 +894,7 @@ Oid
AlterRoleSet(AlterRoleSetStmt *stmt)
{
HeapTuple roletuple;
+ Form_pg_authid roleform;
Oid databaseid = InvalidOid;
Oid roleid = InvalidOid;
@@ -895,19 +904,20 @@ AlterRoleSet(AlterRoleSetStmt *stmt)
"Cannot alter reserved roles.");
roletuple = get_rolespec_tuple(stmt->role);
- roleid = HeapTupleGetOid(roletuple);
+ roleform = (Form_pg_authid) GETSTRUCT(roletuple);
+ roleid = roleform->oid;
/*
* Obtain a lock on the role and make sure it didn't go away in the
* meantime.
*/
- shdepLockAndCheckObject(AuthIdRelationId, HeapTupleGetOid(roletuple));
+ shdepLockAndCheckObject(AuthIdRelationId, roleid);
/*
* To mess with a superuser you gotta be superuser; else you need
* createrole, or just want to change your own settings
*/
- if (((Form_pg_authid) GETSTRUCT(roletuple))->rolsuper)
+ if (roleform->rolsuper)
{
if (!superuser())
ereport(ERROR,
@@ -916,8 +926,7 @@ AlterRoleSet(AlterRoleSetStmt *stmt)
}
else
{
- if (!have_createrole_privilege() &&
- HeapTupleGetOid(roletuple) != GetUserId())
+ if (!have_createrole_privilege() && roleid != GetUserId())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied")));
@@ -987,6 +996,7 @@ DropRole(DropRoleStmt *stmt)
char *role;
HeapTuple tuple,
tmp_tuple;
+ Form_pg_authid roleform;
ScanKeyData scankey;
char *detail;
char *detail_log;
@@ -1018,7 +1028,8 @@ DropRole(DropRoleStmt *stmt)
continue;
}
- roleid = HeapTupleGetOid(tuple);
+ roleform = (Form_pg_authid) GETSTRUCT(tuple);
+ roleid = roleform->oid;
if (roleid == GetUserId())
ereport(ERROR,
@@ -1038,8 +1049,7 @@ DropRole(DropRoleStmt *stmt)
* roles but not superuser roles. This is mainly to avoid the
* scenario where you accidentally drop the last superuser.
*/
- if (((Form_pg_authid) GETSTRUCT(tuple))->rolsuper &&
- !superuser())
+ if (roleform->rolsuper && !superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to drop superusers")));
@@ -1173,8 +1183,8 @@ RenameRole(const char *oldname, const char *newname)
* effective userid, though.
*/
- roleid = HeapTupleGetOid(oldtuple);
authform = (Form_pg_authid) GETSTRUCT(oldtuple);
+ roleid = authform->oid;
if (roleid == GetSessionUserId())
ereport(ERROR,
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index a86963fc86a..25b3b0312c7 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -757,7 +757,7 @@ get_all_vacuum_rels(int options)
{
Form_pg_class classForm = (Form_pg_class) GETSTRUCT(tuple);
MemoryContext oldcontext;
- Oid relid = HeapTupleGetOid(tuple);
+ Oid relid = classForm->oid;
/* check permissions of relation */
if (!vacuum_is_relation_owner(relid, classForm, options))
@@ -1442,13 +1442,13 @@ vac_truncate_clog(TransactionId frozenXID,
else if (TransactionIdPrecedes(datfrozenxid, frozenXID))
{
frozenXID = datfrozenxid;
- oldestxid_datoid = HeapTupleGetOid(tuple);
+ oldestxid_datoid = dbform->oid;
}
if (MultiXactIdPrecedes(datminmxid, minMulti))
{
minMulti = datminmxid;
- minmulti_datoid = HeapTupleGetOid(tuple);
+ minmulti_datoid = dbform->oid;
}
}
diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c
index 8996d366e91..8134c52253e 100644
--- a/src/backend/commands/vacuumlazy.c
+++ b/src/backend/commands/vacuumlazy.c
@@ -1053,12 +1053,6 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats,
all_visible = false;
break;
case HEAPTUPLE_LIVE:
- /* Tuple is good --- but let's do some validity checks */
- if (onerel->rd_rel->relhasoids &&
- !OidIsValid(HeapTupleGetOid(&tuple)))
- elog(WARNING, "relation \"%s\" TID %u/%u: OID is invalid",
- relname, blkno, offnum);
-
/*
* Count it as live. Not only is this natural, but it's
* also what acquire_sample_rows() does.
diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index c2d7a5bebf6..c7e5a9ca9fa 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -744,6 +744,7 @@ bool
check_session_authorization(char **newval, void **extra, GucSource source)
{
HeapTuple roleTup;
+ Form_pg_authid roleform;
Oid roleid;
bool is_superuser;
role_auth_extra *myextra;
@@ -770,8 +771,9 @@ check_session_authorization(char **newval, void **extra, GucSource source)
return false;
}
- roleid = HeapTupleGetOid(roleTup);
- is_superuser = ((Form_pg_authid) GETSTRUCT(roleTup))->rolsuper;
+ roleform = (Form_pg_authid) GETSTRUCT(roleTup);
+ roleid = roleform->oid;
+ is_superuser = roleform->rolsuper;
ReleaseSysCache(roleTup);
@@ -815,6 +817,7 @@ check_role(char **newval, void **extra, GucSource source)
Oid roleid;
bool is_superuser;
role_auth_extra *myextra;
+ Form_pg_authid roleform;
if (strcmp(*newval, "none") == 0)
{
@@ -842,8 +845,9 @@ check_role(char **newval, void **extra, GucSource source)
return false;
}
- roleid = HeapTupleGetOid(roleTup);
- is_superuser = ((Form_pg_authid) GETSTRUCT(roleTup))->rolsuper;
+ roleform = (Form_pg_authid) GETSTRUCT(roleTup);
+ roleid = roleform->oid;
+ is_superuser = roleform->rolsuper;
ReleaseSysCache(roleTup);
diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c
index b670cad8b1d..00e85ed935f 100644
--- a/src/backend/commands/view.c
+++ b/src/backend/commands/view.c
@@ -283,7 +283,6 @@ checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg("cannot drop columns from view")));
- /* we can ignore tdhasoid */
for (i = 0; i < olddesc->natts; i++)
{