PostgreSQL Source Code  git master
catalog.c File Reference
#include "postgres.h"
#include <fcntl.h>
#include <unistd.h>
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "access/table.h"
#include "access/transam.h"
#include "catalog/catalog.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_database.h"
#include "catalog/pg_db_role_setting.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_pltemplate.h"
#include "catalog/pg_replication_origin.h"
#include "catalog/pg_shdepend.h"
#include "catalog/pg_shdescription.h"
#include "catalog/pg_shseclabel.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_type.h"
#include "catalog/toasting.h"
#include "miscadmin.h"
#include "storage/fd.h"
#include "utils/fmgroids.h"
#include "utils/fmgrprotos.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
Include dependency graph for catalog.c:

Go to the source code of this file.

Functions

bool IsSystemRelation (Relation relation)
 
bool IsSystemClass (Oid relid, Form_pg_class reltuple)
 
bool IsCatalogRelation (Relation relation)
 
bool IsCatalogRelationOid (Oid relid)
 
bool IsToastRelation (Relation relation)
 
bool IsToastClass (Form_pg_class reltuple)
 
bool IsCatalogNamespace (Oid namespaceId)
 
bool IsToastNamespace (Oid namespaceId)
 
bool IsReservedName (const char *name)
 
bool IsSharedRelation (Oid relationId)
 
Oid GetNewOidWithIndex (Relation relation, Oid indexId, AttrNumber oidcolumn)
 
Oid GetNewRelFileNode (Oid reltablespace, Relation pg_class, char relpersistence)
 
Datum pg_nextoid (PG_FUNCTION_ARGS)
 

Function Documentation

◆ GetNewOidWithIndex()

Oid GetNewOidWithIndex ( Relation  relation,
Oid  indexId,
AttrNumber  oidcolumn 
)

Definition at line 322 of file catalog.c.

References Assert, BTEqualStrategyNumber, CHECK_FOR_INTERRUPTS, GetNewObjectId(), HeapTupleIsValid, IsBinaryUpgrade, IsBootstrapProcessingMode, IsSystemRelation(), sort-test::key, ObjectIdGetDatum, RelationGetRelid, ScanKeyInit(), SnapshotAny, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AddEnumLabel(), AssignTypeArrayOid(), CollationCreate(), ConversionCreate(), create_proc_lang(), CreateAccessMethod(), CreateCast(), CreateConstraintEntry(), createdb(), CreateForeignDataWrapper(), CreateForeignServer(), CreateOpFamily(), CreatePolicy(), CreatePublication(), CreateRole(), CreateStatistics(), CreateSubscription(), CreateTableSpace(), CreateTransform(), CreateTrigger(), CreateUserMapping(), DefineOpClass(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), EnumValuesCreate(), GetNewRelFileNode(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertRule(), LargeObjectCreate(), NamespaceCreate(), OperatorCreate(), OperatorShellMake(), pg_nextoid(), ProcedureCreate(), publication_add_relation(), SetDefaultACL(), StoreAttrDefault(), storeOperators(), storeProcedures(), toast_save_datum(), TypeCreate(), and TypeShellMake().

323 {
324  Oid newOid;
325  SysScanDesc scan;
327  bool collides;
328 
329  /* Only system relations are supported */
330  Assert(IsSystemRelation(relation));
331 
332  /* In bootstrap mode, we don't have any indexes to use */
334  return GetNewObjectId();
335 
336  /*
337  * We should never be asked to generate a new pg_type OID during
338  * pg_upgrade; doing so would risk collisions with the OIDs it wants to
339  * assign. Hitting this assert means there's some path where we failed to
340  * ensure that a type OID is determined by commands in the dump script.
341  */
342  Assert(!IsBinaryUpgrade || RelationGetRelid(relation) != TypeRelationId);
343 
344  /* Generate new OIDs until we find one not in the table */
345  do
346  {
348 
349  newOid = GetNewObjectId();
350 
351  ScanKeyInit(&key,
352  oidcolumn,
353  BTEqualStrategyNumber, F_OIDEQ,
354  ObjectIdGetDatum(newOid));
355 
356  /* see notes above about using SnapshotAny */
357  scan = systable_beginscan(relation, indexId, true,
358  SnapshotAny, 1, &key);
359 
360  collides = HeapTupleIsValid(systable_getnext(scan));
361 
362  systable_endscan(scan);
363  } while (collides);
364 
365  return newOid;
366 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
bool IsSystemRelation(Relation relation)
Definition: catalog.c:69
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
bool IsBinaryUpgrade
Definition: globals.c:110
Oid GetNewObjectId(void)
Definition: varsup.c:509
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:739
#define SnapshotAny
Definition: snapmgr.h:69
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:374
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
#define RelationGetRelid(relation)
Definition: rel.h:422
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ GetNewRelFileNode()

Oid GetNewRelFileNode ( Oid  reltablespace,
Relation  pg_class,
char  relpersistence 
)

Definition at line 385 of file catalog.c.

References Assert, RelFileNodeBackend::backend, BackendIdForTempRelations, CHECK_FOR_INTERRUPTS, ClassOidIndexId, RelFileNode::dbNode, elog, ERROR, GetNewObjectId(), GetNewOidWithIndex(), InvalidBackendId, InvalidOid, IsBinaryUpgrade, MAIN_FORKNUM, MyDatabaseId, MyDatabaseTableSpace, RelFileNodeBackend::node, pfree(), RelFileNode::relNode, relpath, and RelFileNode::spcNode.

Referenced by ATExecSetTableSpace(), heap_create_with_catalog(), index_create(), and RelationSetNewRelfilenode().

386 {
387  RelFileNodeBackend rnode;
388  char *rpath;
389  bool collides;
390  BackendId backend;
391 
392  /*
393  * If we ever get here during pg_upgrade, there's something wrong; all
394  * relfilenode assignments during a binary-upgrade run should be
395  * determined by commands in the dump script.
396  */
398 
399  switch (relpersistence)
400  {
401  case RELPERSISTENCE_TEMP:
402  backend = BackendIdForTempRelations();
403  break;
404  case RELPERSISTENCE_UNLOGGED:
405  case RELPERSISTENCE_PERMANENT:
406  backend = InvalidBackendId;
407  break;
408  default:
409  elog(ERROR, "invalid relpersistence: %c", relpersistence);
410  return InvalidOid; /* placate compiler */
411  }
412 
413  /* This logic should match RelationInitPhysicalAddr */
414  rnode.node.spcNode = reltablespace ? reltablespace : MyDatabaseTableSpace;
415  rnode.node.dbNode = (rnode.node.spcNode == GLOBALTABLESPACE_OID) ? InvalidOid : MyDatabaseId;
416 
417  /*
418  * The relpath will vary based on the backend ID, so we must initialize
419  * that properly here to make sure that any collisions based on filename
420  * are properly detected.
421  */
422  rnode.backend = backend;
423 
424  do
425  {
427 
428  /* Generate the OID */
429  if (pg_class)
431  Anum_pg_class_oid);
432  else
433  rnode.node.relNode = GetNewObjectId();
434 
435  /* Check for existing file of same name */
436  rpath = relpath(rnode, MAIN_FORKNUM);
437 
438  if (access(rpath, F_OK) == 0)
439  {
440  /* definite collision */
441  collides = true;
442  }
443  else
444  {
445  /*
446  * Here we have a little bit of a dilemma: if errno is something
447  * other than ENOENT, should we declare a collision and loop? In
448  * practice it seems best to go ahead regardless of the errno. If
449  * there is a colliding file we will get an smgr failure when we
450  * attempt to create the new relation file.
451  */
452  collides = false;
453  }
454 
455  pfree(rpath);
456  } while (collides);
457 
458  return rnode.node.relNode;
459 }
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:322
bool IsBinaryUpgrade
Definition: globals.c:110
Oid MyDatabaseTableSpace
Definition: globals.c:87
Oid GetNewObjectId(void)
Definition: varsup.c:509
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
char relpersistence
Definition: pg_class.h:78
#define BackendIdForTempRelations()
Definition: backendid.h:34
#define ClassOidIndexId
Definition: indexing.h:114
#define InvalidBackendId
Definition: backendid.h:23
int BackendId
Definition: backendid.h:21
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
RelFileNode node
Definition: relfilenode.h:74
#define Assert(condition)
Definition: c.h:739
BackendId backend
Definition: relfilenode.h:75
#define elog(elevel,...)
Definition: elog.h:228
#define relpath(rnode, forknum)
Definition: relpath.h:87
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99

◆ IsCatalogNamespace()

bool IsCatalogNamespace ( Oid  namespaceId)

Definition at line 178 of file catalog.c.

Referenced by AlterTableMoveAll(), heap_create(), and RelationBuildLocalRelation().

179 {
180  return namespaceId == PG_CATALOG_NAMESPACE;
181 }

◆ IsCatalogRelation()

bool IsCatalogRelation ( Relation  relation)

◆ IsCatalogRelationOid()

bool IsCatalogRelationOid ( Oid  relid)

Definition at line 116 of file catalog.c.

References FirstBootstrapObjectId.

Referenced by check_relation_privileges(), is_publishable_class(), IsCatalogRelation(), IsSystemClass(), ReindexMultipleTables(), and ReindexRelationConcurrently().

117 {
118  /*
119  * We consider a relation to be a system catalog if it has an OID that was
120  * manually assigned or assigned by genbki.pl. This includes all the
121  * defined catalogs, their indexes, and their TOAST tables and indexes.
122  *
123  * This rule excludes the relations in information_schema, which are not
124  * integral to the system and can be treated the same as user relations.
125  * (Since it's valid to drop and recreate information_schema, any rule
126  * that did not act this way would be wrong.)
127  *
128  * This test is reliable since an OID wraparound will skip this range of
129  * OIDs; see GetNewObjectId().
130  */
131  return (relid < (Oid) FirstBootstrapObjectId);
132 }
unsigned int Oid
Definition: postgres_ext.h:31
#define FirstBootstrapObjectId
Definition: transam.h:140

◆ IsReservedName()

bool IsReservedName ( const char *  name)

Definition at line 213 of file catalog.c.

Referenced by check_rolespec_name(), CreateRole(), CreateSchemaCommand(), CreateTableSpace(), pg_replication_origin_create(), RenameRole(), RenameSchema(), and RenameTableSpace().

214 {
215  /* ugly coding for speed */
216  return (name[0] == 'p' &&
217  name[1] == 'g' &&
218  name[2] == '_');
219 }
const char * name
Definition: encode.c:521

◆ IsSharedRelation()

bool IsSharedRelation ( Oid  relationId)

Definition at line 239 of file catalog.c.

References AuthIdOidIndexId, AuthIdRolnameIndexId, AuthMemMemRoleIndexId, AuthMemRoleMemIndexId, DatabaseNameIndexId, DatabaseOidIndexId, DbRoleSettingDatidRolidIndexId, PgAuthidToastIndex, PgAuthidToastTable, PgDatabaseToastIndex, PgDatabaseToastTable, PgDbRoleSettingToastIndex, PgDbRoleSettingToastTable, PgPlTemplateToastIndex, PgPlTemplateToastTable, PgReplicationOriginToastIndex, PgReplicationOriginToastTable, PgShdescriptionToastIndex, PgShdescriptionToastTable, PgShseclabelToastIndex, PgShseclabelToastTable, PgSubscriptionToastIndex, PgSubscriptionToastTable, PgTablespaceToastIndex, PgTablespaceToastTable, PLTemplateNameIndexId, ReplicationOriginIdentIndex, ReplicationOriginNameIndex, SharedDependDependerIndexId, SharedDependReferenceIndexId, SharedDescriptionObjIndexId, SharedSecLabelObjectIndexId, SubscriptionNameIndexId, SubscriptionObjectIndexId, TablespaceNameIndexId, and TablespaceOidIndexId.

Referenced by CacheInvalidateCatalog(), CacheInvalidateHeapTuple(), classIdGetDbId(), DeleteSecurityLabel(), get_object_address(), GetSecurityLabel(), RelationBuildLocalRelation(), SetLocktagRelationOid(), SetSecurityLabel(), and UpdateLogicalMappings().

240 {
241  /* These are the shared catalogs (look for BKI_SHARED_RELATION) */
242  if (relationId == AuthIdRelationId ||
243  relationId == AuthMemRelationId ||
244  relationId == DatabaseRelationId ||
245  relationId == PLTemplateRelationId ||
246  relationId == SharedDescriptionRelationId ||
247  relationId == SharedDependRelationId ||
248  relationId == SharedSecLabelRelationId ||
249  relationId == TableSpaceRelationId ||
250  relationId == DbRoleSettingRelationId ||
251  relationId == ReplicationOriginRelationId ||
252  relationId == SubscriptionRelationId)
253  return true;
254  /* These are their indexes (see indexing.h) */
255  if (relationId == AuthIdRolnameIndexId ||
256  relationId == AuthIdOidIndexId ||
257  relationId == AuthMemRoleMemIndexId ||
258  relationId == AuthMemMemRoleIndexId ||
259  relationId == DatabaseNameIndexId ||
260  relationId == DatabaseOidIndexId ||
261  relationId == PLTemplateNameIndexId ||
262  relationId == SharedDescriptionObjIndexId ||
263  relationId == SharedDependDependerIndexId ||
264  relationId == SharedDependReferenceIndexId ||
265  relationId == SharedSecLabelObjectIndexId ||
266  relationId == TablespaceOidIndexId ||
267  relationId == TablespaceNameIndexId ||
268  relationId == DbRoleSettingDatidRolidIndexId ||
269  relationId == ReplicationOriginIdentIndex ||
270  relationId == ReplicationOriginNameIndex ||
271  relationId == SubscriptionObjectIndexId ||
272  relationId == SubscriptionNameIndexId)
273  return true;
274  /* These are their toast tables and toast indexes (see toasting.h) */
275  if (relationId == PgAuthidToastTable ||
276  relationId == PgAuthidToastIndex ||
277  relationId == PgDatabaseToastTable ||
278  relationId == PgDatabaseToastIndex ||
279  relationId == PgDbRoleSettingToastTable ||
280  relationId == PgDbRoleSettingToastIndex ||
281  relationId == PgPlTemplateToastTable ||
282  relationId == PgPlTemplateToastIndex ||
283  relationId == PgReplicationOriginToastTable ||
284  relationId == PgReplicationOriginToastIndex ||
285  relationId == PgShdescriptionToastTable ||
286  relationId == PgShdescriptionToastIndex ||
287  relationId == PgShseclabelToastTable ||
288  relationId == PgShseclabelToastIndex ||
289  relationId == PgSubscriptionToastTable ||
290  relationId == PgSubscriptionToastIndex ||
291  relationId == PgTablespaceToastTable ||
292  relationId == PgTablespaceToastIndex)
293  return true;
294  return false;
295 }
#define PgShseclabelToastIndex
Definition: toasting.h:100
#define SharedDependDependerIndexId
Definition: indexing.h:226
#define PgAuthidToastTable
Definition: toasting.h:81
#define PgTablespaceToastTable
Definition: toasting.h:105
#define DbRoleSettingDatidRolidIndexId
Definition: indexing.h:317
#define PgShseclabelToastTable
Definition: toasting.h:99
#define AuthIdOidIndexId
Definition: indexing.h:101
#define PgSubscriptionToastTable
Definition: toasting.h:102
#define PgDatabaseToastTable
Definition: toasting.h:84
#define PgTablespaceToastIndex
Definition: toasting.h:106
#define ReplicationOriginIdentIndex
Definition: indexing.h:340
#define TablespaceOidIndexId
Definition: indexing.h:244
#define PgPlTemplateToastTable
Definition: toasting.h:90
#define PgShdescriptionToastTable
Definition: toasting.h:96
#define PgReplicationOriginToastTable
Definition: toasting.h:93
#define DatabaseOidIndexId
Definition: indexing.h:146
#define PgShdescriptionToastIndex
Definition: toasting.h:97
#define PgDbRoleSettingToastTable
Definition: toasting.h:87
#define AuthMemRoleMemIndexId
Definition: indexing.h:104
#define PLTemplateNameIndexId
Definition: indexing.h:210
#define PgPlTemplateToastIndex
Definition: toasting.h:91
#define SharedDescriptionObjIndexId
Definition: indexing.h:156
#define PgDatabaseToastIndex
Definition: toasting.h:85
#define PgAuthidToastIndex
Definition: toasting.h:82
#define PgReplicationOriginToastIndex
Definition: toasting.h:94
#define AuthMemMemRoleIndexId
Definition: indexing.h:106
#define DatabaseNameIndexId
Definition: indexing.h:144
#define SharedSecLabelObjectIndexId
Definition: indexing.h:323
#define TablespaceNameIndexId
Definition: indexing.h:246
#define SubscriptionNameIndexId
Definition: indexing.h:364
#define PgSubscriptionToastIndex
Definition: toasting.h:103
#define ReplicationOriginNameIndex
Definition: indexing.h:343
#define SharedDependReferenceIndexId
Definition: indexing.h:228
#define PgDbRoleSettingToastIndex
Definition: toasting.h:88
#define AuthIdRolnameIndexId
Definition: indexing.h:99
#define SubscriptionObjectIndexId
Definition: indexing.h:361

◆ IsSystemClass()

bool IsSystemClass ( Oid  relid,
Form_pg_class  reltuple 
)

Definition at line 81 of file catalog.c.

References IsCatalogRelationOid(), and IsToastClass().

Referenced by IsSystemRelation(), pg_class_aclmask(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), ReindexMultipleTables(), renameatt_check(), swap_relation_files(), and truncate_check_rel().

82 {
83  /* IsCatalogRelationOid is a bit faster, so test that first */
84  return (IsCatalogRelationOid(relid) || IsToastClass(reltuple));
85 }
bool IsCatalogRelationOid(Oid relid)
Definition: catalog.c:116
bool IsToastClass(Form_pg_class reltuple)
Definition: catalog.c:161

◆ IsSystemRelation()

◆ IsToastClass()

bool IsToastClass ( Form_pg_class  reltuple)

Definition at line 161 of file catalog.c.

References IsToastNamespace().

Referenced by IsSystemClass().

162 {
163  Oid relnamespace = reltuple->relnamespace;
164 
165  return IsToastNamespace(relnamespace);
166 }
bool IsToastNamespace(Oid namespaceId)
Definition: catalog.c:196
unsigned int Oid
Definition: postgres_ext.h:31

◆ IsToastNamespace()

bool IsToastNamespace ( Oid  namespaceId)

Definition at line 196 of file catalog.c.

References isTempToastNamespace().

Referenced by AlterTableMoveAll(), heap_create(), IsToastClass(), and IsToastRelation().

197 {
198  return (namespaceId == PG_TOAST_NAMESPACE) ||
199  isTempToastNamespace(namespaceId);
200 }
bool isTempToastNamespace(Oid namespaceId)
Definition: namespace.c:3161

◆ IsToastRelation()

bool IsToastRelation ( Relation  relation)

Definition at line 141 of file catalog.c.

References IsToastNamespace(), and RelationGetNamespace.

Referenced by CacheInvalidateHeapTuple(), heap_abort_speculative(), ReorderBufferCommit(), and ReorderBufferToastAppendChunk().

142 {
143  /*
144  * What we actually check is whether the relation belongs to a pg_toast
145  * namespace. This should be equivalent because of restrictions that are
146  * enforced elsewhere against creating user relations in, or moving
147  * relations into/out of, a pg_toast namespace. Notice also that this
148  * will not say "true" for toast tables belonging to other sessions' temp
149  * tables; we expect that other mechanisms will prevent access to those.
150  */
151  return IsToastNamespace(RelationGetNamespace(relation));
152 }
bool IsToastNamespace(Oid namespaceId)
Definition: catalog.c:196
#define RelationGetNamespace(relation)
Definition: rel.h:463

◆ pg_nextoid()

Datum pg_nextoid ( PG_FUNCTION_ARGS  )

Definition at line 469 of file catalog.c.

References attname, ereport, errcode(), errmsg(), ERROR, GetNewOidWithIndex(), GETSTRUCT, HeapTupleIsValid, idx(), index_close(), index_open(), IndexRelationGetNumberOfKeyAttributes, IsSystemRelation(), NameStr, PG_GETARG_NAME, PG_GETARG_OID, RelationData::rd_index, RelationGetRelationName, RelationGetRelid, ReleaseSysCache(), RowExclusiveLock, SearchSysCacheAttName(), superuser(), table_close(), and table_open().

470 {
471  Oid reloid = PG_GETARG_OID(0);
473  Oid idxoid = PG_GETARG_OID(2);
474  Relation rel;
475  Relation idx;
476  HeapTuple atttuple;
477  Form_pg_attribute attform;
478  AttrNumber attno;
479  Oid newoid;
480 
481  /*
482  * As this function is not intended to be used during normal running, and
483  * only supports system catalogs (which require superuser permissions to
484  * modify), just checking for superuser ought to not obstruct valid
485  * usecases.
486  */
487  if (!superuser())
488  ereport(ERROR,
489  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
490  errmsg("must be superuser to call pg_nextoid()")));
491 
492  rel = table_open(reloid, RowExclusiveLock);
493  idx = index_open(idxoid, RowExclusiveLock);
494 
495  if (!IsSystemRelation(rel))
496  ereport(ERROR,
497  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
498  errmsg("pg_nextoid() can only be used on system catalogs")));
499 
500  if (idx->rd_index->indrelid != RelationGetRelid(rel))
501  ereport(ERROR,
502  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
503  errmsg("index \"%s\" does not belong to table \"%s\"",
505  RelationGetRelationName(rel))));
506 
507  atttuple = SearchSysCacheAttName(reloid, NameStr(*attname));
508  if (!HeapTupleIsValid(atttuple))
509  ereport(ERROR,
510  (errcode(ERRCODE_UNDEFINED_COLUMN),
511  errmsg("column \"%s\" of relation \"%s\" does not exist",
512  NameStr(*attname), RelationGetRelationName(rel))));
513 
514  attform = ((Form_pg_attribute) GETSTRUCT(atttuple));
515  attno = attform->attnum;
516 
517  if (attform->atttypid != OIDOID)
518  ereport(ERROR,
519  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
520  errmsg("column \"%s\" is not of type oid",
521  NameStr(*attname))));
522 
524  idx->rd_index->indkey.values[0] != attno)
525  ereport(ERROR,
526  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
527  errmsg("index \"%s\" is not the index for column \"%s\"",
529  NameStr(*attname))));
530 
531  newoid = GetNewOidWithIndex(rel, idxoid, attno);
532 
533  ReleaseSysCache(atttuple);
536 
537  return newoid;
538 }
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:322
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
bool IsSystemRelation(Relation relation)
Definition: catalog.c:69
int errcode(int sqlerrcode)
Definition: elog.c:608
bool superuser(void)
Definition: superuser.c:46
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:263
unsigned int Oid
Definition: postgres_ext.h:31
Form_pg_index rd_index
Definition: rel.h:143
#define ERROR
Definition: elog.h:43
NameData attname
Definition: pg_attribute.h:40
Definition: c.h:610
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define RowExclusiveLock
Definition: lockdefs.h:38
#define RelationGetRelationName(relation)
Definition: rel.h:456
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
#define IndexRelationGetNumberOfKeyAttributes(relation)
Definition: rel.h:441
#define ereport(elevel, rest)
Definition: elog.h:141
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Definition: syscache.c:1257
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:152
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define NameStr(name)
Definition: c.h:616
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:422
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:126
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273