PostgreSQL Source Code  git master
rel.h File Reference
#include "access/tupdesc.h"
#include "access/xlog.h"
#include "catalog/pg_class.h"
#include "catalog/pg_index.h"
#include "catalog/pg_publication.h"
#include "nodes/bitmapset.h"
#include "partitioning/partdefs.h"
#include "rewrite/prs2lock.h"
#include "storage/block.h"
#include "storage/relfilenode.h"
#include "storage/smgr.h"
#include "utils/relcache.h"
#include "utils/reltrigger.h"
Include dependency graph for rel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LockRelId
 
struct  LockInfoData
 
struct  RelationData
 
struct  ForeignKeyCacheInfo
 
struct  AutoVacOpts
 
struct  StdRdOptions
 
struct  ViewOptions
 

Macros

#define HEAP_MIN_FILLFACTOR   10
 
#define HEAP_DEFAULT_FILLFACTOR   100
 
#define RelationGetToastTupleTarget(relation, defaulttarg)
 
#define RelationGetFillFactor(relation, defaultff)
 
#define RelationGetTargetPageUsage(relation, defaultff)    (BLCKSZ * RelationGetFillFactor(relation, defaultff) / 100)
 
#define RelationGetTargetPageFreeSpace(relation, defaultff)    (BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100)
 
#define RelationIsUsedAsCatalogTable(relation)
 
#define RelationGetParallelWorkers(relation, defaultpw)
 
#define RelationIsSecurityView(relation)
 
#define RelationHasSecurityInvoker(relation)
 
#define RelationHasCheckOption(relation)
 
#define RelationHasLocalCheckOption(relation)
 
#define RelationHasCascadedCheckOption(relation)
 
#define RelationIsValid(relation)   PointerIsValid(relation)
 
#define InvalidRelation   ((Relation) NULL)
 
#define RelationHasReferenceCountZero(relation)    ((bool)((relation)->rd_refcnt == 0))
 
#define RelationGetForm(relation)   ((relation)->rd_rel)
 
#define RelationGetRelid(relation)   ((relation)->rd_id)
 
#define RelationGetNumberOfAttributes(relation)   ((relation)->rd_rel->relnatts)
 
#define IndexRelationGetNumberOfAttributes(relation)    ((relation)->rd_index->indnatts)
 
#define IndexRelationGetNumberOfKeyAttributes(relation)    ((relation)->rd_index->indnkeyatts)
 
#define RelationGetDescr(relation)   ((relation)->rd_att)
 
#define RelationGetRelationName(relation)    (NameStr((relation)->rd_rel->relname))
 
#define RelationGetNamespace(relation)    ((relation)->rd_rel->relnamespace)
 
#define RelationIsMapped(relation)
 
#define RelationCloseSmgr(relation)
 
#define RelationGetTargetBlock(relation)    ( (relation)->rd_smgr != NULL ? (relation)->rd_smgr->smgr_targblock : InvalidBlockNumber )
 
#define RelationSetTargetBlock(relation, targblock)
 
#define RelationIsPermanent(relation)    ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
 
#define RelationNeedsWAL(relation)
 
#define RelationUsesLocalBuffers(relation)    ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
 
#define RELATION_IS_LOCAL(relation)
 
#define RELATION_IS_OTHER_TEMP(relation)
 
#define RelationIsScannable(relation)   ((relation)->rd_rel->relispopulated)
 
#define RelationIsPopulated(relation)   ((relation)->rd_rel->relispopulated)
 
#define RelationIsAccessibleInLogicalDecoding(relation)
 
#define RelationIsLogicallyLogged(relation)
 

Typedefs

typedef struct LockRelId LockRelId
 
typedef struct LockInfoData LockInfoData
 
typedef LockInfoDataLockInfo
 
typedef struct RelationData RelationData
 
typedef struct ForeignKeyCacheInfo ForeignKeyCacheInfo
 
typedef struct AutoVacOpts AutoVacOpts
 
typedef enum StdRdOptIndexCleanup StdRdOptIndexCleanup
 
typedef struct StdRdOptions StdRdOptions
 
typedef enum ViewOptCheckOption ViewOptCheckOption
 
typedef struct ViewOptions ViewOptions
 

Enumerations

enum  StdRdOptIndexCleanup { STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO = 0 , STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF , STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON }
 
enum  ViewOptCheckOption { VIEW_OPTION_CHECK_OPTION_NOT_SET , VIEW_OPTION_CHECK_OPTION_LOCAL , VIEW_OPTION_CHECK_OPTION_CASCADED }
 

Functions

static SMgrRelation RelationGetSmgr (Relation rel)
 
void RelationIncrementReferenceCount (Relation rel)
 
void RelationDecrementReferenceCount (Relation rel)
 

Macro Definition Documentation

◆ HEAP_DEFAULT_FILLFACTOR

#define HEAP_DEFAULT_FILLFACTOR   100

Definition at line 332 of file rel.h.

◆ HEAP_MIN_FILLFACTOR

#define HEAP_MIN_FILLFACTOR   10

Definition at line 331 of file rel.h.

◆ IndexRelationGetNumberOfAttributes

#define IndexRelationGetNumberOfAttributes (   relation)     ((relation)->rd_index->indnatts)

Definition at line 500 of file rel.h.

◆ IndexRelationGetNumberOfKeyAttributes

#define IndexRelationGetNumberOfKeyAttributes (   relation)     ((relation)->rd_index->indnkeyatts)

Definition at line 507 of file rel.h.

◆ InvalidRelation

#define InvalidRelation   ((Relation) NULL)

Definition at line 463 of file rel.h.

◆ RELATION_IS_LOCAL

#define RELATION_IS_LOCAL (   relation)
Value:
((relation)->rd_islocaltemp || \
(relation)->rd_createSubid != InvalidSubTransactionId)
#define InvalidSubTransactionId
Definition: c.h:604

Definition at line 632 of file rel.h.

◆ RELATION_IS_OTHER_TEMP

#define RELATION_IS_OTHER_TEMP (   relation)
Value:
((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \
!(relation)->rd_islocaltemp)

Definition at line 642 of file rel.h.

◆ RelationCloseSmgr

#define RelationCloseSmgr (   relation)
Value:
do { \
if ((relation)->rd_smgr != NULL) \
{ \
smgrclose((relation)->rd_smgr); \
Assert((relation)->rd_smgr == NULL); \
} \
} while (0)

Definition at line 568 of file rel.h.

◆ RelationGetDescr

#define RelationGetDescr (   relation)    ((relation)->rd_att)

Definition at line 514 of file rel.h.

◆ RelationGetFillFactor

#define RelationGetFillFactor (   relation,
  defaultff 
)
Value:
((relation)->rd_options ? \
((StdRdOptions *) (relation)->rd_options)->fillfactor : (defaultff))

Definition at line 346 of file rel.h.

◆ RelationGetForm

#define RelationGetForm (   relation)    ((relation)->rd_rel)

Definition at line 482 of file rel.h.

◆ RelationGetNamespace

#define RelationGetNamespace (   relation)     ((relation)->rd_rel->relnamespace)

Definition at line 529 of file rel.h.

◆ RelationGetNumberOfAttributes

#define RelationGetNumberOfAttributes (   relation)    ((relation)->rd_rel->relnatts)

Definition at line 494 of file rel.h.

◆ RelationGetParallelWorkers

#define RelationGetParallelWorkers (   relation,
  defaultpw 
)
Value:
((relation)->rd_options ? \
((StdRdOptions *) (relation)->rd_options)->parallel_workers : (defaultpw))

Definition at line 380 of file rel.h.

◆ RelationGetRelationName

#define RelationGetRelationName (   relation)     (NameStr((relation)->rd_rel->relname))

Definition at line 522 of file rel.h.

◆ RelationGetRelid

#define RelationGetRelid (   relation)    ((relation)->rd_id)

Definition at line 488 of file rel.h.

◆ RelationGetTargetBlock

#define RelationGetTargetBlock (   relation)     ( (relation)->rd_smgr != NULL ? (relation)->rd_smgr->smgr_targblock : InvalidBlockNumber )

Definition at line 585 of file rel.h.

◆ RelationGetTargetPageFreeSpace

#define RelationGetTargetPageFreeSpace (   relation,
  defaultff 
)     (BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100)

Definition at line 361 of file rel.h.

◆ RelationGetTargetPageUsage

#define RelationGetTargetPageUsage (   relation,
  defaultff 
)     (BLCKSZ * RelationGetFillFactor(relation, defaultff) / 100)

Definition at line 354 of file rel.h.

◆ RelationGetToastTupleTarget

#define RelationGetToastTupleTarget (   relation,
  defaulttarg 
)
Value:
((relation)->rd_options ? \
((StdRdOptions *) (relation)->rd_options)->toast_tuple_target : (defaulttarg))

Definition at line 338 of file rel.h.

◆ RelationHasCascadedCheckOption

#define RelationHasCascadedCheckOption (   relation)
Value:
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
(relation)->rd_options && \
((ViewOptions *) (relation)->rd_options)->check_option == \
VIEW_OPTION_CHECK_OPTION_CASCADED)
#define AssertMacro(condition)
Definition: c.h:816

Definition at line 451 of file rel.h.

◆ RelationHasCheckOption

#define RelationHasCheckOption (   relation)
Value:
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
(relation)->rd_options && \
((ViewOptions *) (relation)->rd_options)->check_option != \
VIEW_OPTION_CHECK_OPTION_NOT_SET)

Definition at line 429 of file rel.h.

◆ RelationHasLocalCheckOption

#define RelationHasLocalCheckOption (   relation)
Value:
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
(relation)->rd_options && \
((ViewOptions *) (relation)->rd_options)->check_option == \
VIEW_OPTION_CHECK_OPTION_LOCAL)

Definition at line 440 of file rel.h.

◆ RelationHasReferenceCountZero

#define RelationHasReferenceCountZero (   relation)     ((bool)((relation)->rd_refcnt == 0))

Definition at line 472 of file rel.h.

◆ RelationHasSecurityInvoker

#define RelationHasSecurityInvoker (   relation)
Value:
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
(relation)->rd_options ? \
((ViewOptions *) (relation)->rd_options)->security_invoker : false)

Definition at line 419 of file rel.h.

◆ RelationIsAccessibleInLogicalDecoding

#define RelationIsAccessibleInLogicalDecoding (   relation)
Value:
RelationNeedsWAL(relation) && \
bool IsCatalogRelation(Relation relation)
Definition: catalog.c:105
#define RelationIsUsedAsCatalogTable(relation)
Definition: rel.h:369
#define XLogLogicalInfoActive()
Definition: xlog.h:121

Definition at line 668 of file rel.h.

◆ RelationIsLogicallyLogged

#define RelationIsLogicallyLogged (   relation)
Value:
RelationNeedsWAL(relation) && \
(relation)->rd_rel->relkind != RELKIND_FOREIGN_TABLE && \
!IsCatalogRelation(relation))

Definition at line 685 of file rel.h.

◆ RelationIsMapped

#define RelationIsMapped (   relation)
Value:
(RELKIND_HAS_STORAGE((relation)->rd_rel->relkind) && \
((relation)->rd_rel->relfilenode == InvalidOid))
#define InvalidOid
Definition: postgres_ext.h:36

Definition at line 537 of file rel.h.

◆ RelationIsPermanent

#define RelationIsPermanent (   relation)     ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)

Definition at line 601 of file rel.h.

◆ RelationIsPopulated

#define RelationIsPopulated (   relation)    ((relation)->rd_rel->relispopulated)

Definition at line 661 of file rel.h.

◆ RelationIsScannable

#define RelationIsScannable (   relation)    ((relation)->rd_rel->relispopulated)

Definition at line 653 of file rel.h.

◆ RelationIsSecurityView

#define RelationIsSecurityView (   relation)
Value:
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
(relation)->rd_options ? \
((ViewOptions *) (relation)->rd_options)->security_barrier : false)

Definition at line 409 of file rel.h.

◆ RelationIsUsedAsCatalogTable

#define RelationIsUsedAsCatalogTable (   relation)
Value:
((relation)->rd_options && \
((relation)->rd_rel->relkind == RELKIND_RELATION || \
(relation)->rd_rel->relkind == RELKIND_MATVIEW) ? \
((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)

Definition at line 369 of file rel.h.

◆ RelationIsValid

#define RelationIsValid (   relation)    PointerIsValid(relation)

Definition at line 461 of file rel.h.

◆ RelationNeedsWAL

#define RelationNeedsWAL (   relation)
Value:
(RelationIsPermanent(relation) && (XLogIsNeeded() || \
(relation->rd_createSubid == InvalidSubTransactionId && \
relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
#define RelationIsPermanent(relation)
Definition: rel.h:601
#define XLogIsNeeded()
Definition: xlog.h:104

Definition at line 612 of file rel.h.

◆ RelationSetTargetBlock

#define RelationSetTargetBlock (   relation,
  targblock 
)
Value:
do { \
RelationGetSmgr(relation)->smgr_targblock = (targblock); \
} while (0)

Definition at line 592 of file rel.h.

◆ RelationUsesLocalBuffers

#define RelationUsesLocalBuffers (   relation)     ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP)

Definition at line 621 of file rel.h.

Typedef Documentation

◆ AutoVacOpts

typedef struct AutoVacOpts AutoVacOpts

◆ ForeignKeyCacheInfo

◆ LockInfo

Definition at line 48 of file rel.h.

◆ LockInfoData

typedef struct LockInfoData LockInfoData

◆ LockRelId

typedef struct LockRelId LockRelId

◆ RelationData

typedef struct RelationData RelationData

◆ StdRdOptIndexCleanup

◆ StdRdOptions

typedef struct StdRdOptions StdRdOptions

◆ ViewOptCheckOption

◆ ViewOptions

typedef struct ViewOptions ViewOptions

Enumeration Type Documentation

◆ StdRdOptIndexCleanup

Enumerator
STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO 
STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF 
STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON 

Definition at line 312 of file rel.h.

313 {
StdRdOptIndexCleanup
Definition: rel.h:313
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO
Definition: rel.h:314
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF
Definition: rel.h:315
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON
Definition: rel.h:316

◆ ViewOptCheckOption

Enumerator
VIEW_OPTION_CHECK_OPTION_NOT_SET 
VIEW_OPTION_CHECK_OPTION_LOCAL 
VIEW_OPTION_CHECK_OPTION_CASCADED 

Definition at line 385 of file rel.h.

386 {
ViewOptCheckOption
Definition: rel.h:386
@ VIEW_OPTION_CHECK_OPTION_NOT_SET
Definition: rel.h:387
@ VIEW_OPTION_CHECK_OPTION_LOCAL
Definition: rel.h:388
@ VIEW_OPTION_CHECK_OPTION_CASCADED
Definition: rel.h:389

Function Documentation

◆ RelationDecrementReferenceCount()

void RelationDecrementReferenceCount ( Relation  rel)

Definition at line 2139 of file relcache.c.

2140 {
2141  Assert(rel->rd_refcnt > 0);
2142  rel->rd_refcnt -= 1;
2145 }
Assert(fmt[strlen(fmt) - 1] !='\n')
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:406
ResourceOwner CurrentResourceOwner
Definition: resowner.c:146
void ResourceOwnerForgetRelationRef(ResourceOwner owner, Relation rel)
Definition: resowner.c:1124
int rd_refcnt
Definition: rel.h:58

References Assert(), CurrentResourceOwner, IsBootstrapProcessingMode, RelationData::rd_refcnt, and ResourceOwnerForgetRelationRef().

Referenced by DestroyPartitionDirectory(), heap_endscan(), index_endscan(), RelationCacheInitializePhase3(), RelationClose(), and RelationFlushRelation().

◆ RelationGetSmgr()

static SMgrRelation RelationGetSmgr ( Relation  rel)
inlinestatic

Definition at line 555 of file rel.h.

556 {
557  if (unlikely(rel->rd_smgr == NULL))
558  smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_node, rel->rd_backend));
559  return rel->rd_smgr;
560 }
#define unlikely(x)
Definition: c.h:284
void smgrsetowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:198
SMgrRelation smgropen(RelFileNode rnode, BackendId backend)
Definition: smgr.c:146
RelFileNode rd_node
Definition: rel.h:56
BackendId rd_backend
Definition: rel.h:59
SMgrRelation rd_smgr
Definition: rel.h:57

References RelationData::rd_backend, RelationData::rd_node, RelationData::rd_smgr, smgropen(), smgrsetowner(), and unlikely.

Referenced by _bt_blwritepage(), _bt_load(), _hash_alloc_buckets(), autoprewarm_database_main(), blbuildempty(), bt_index_check_internal(), btbuildempty(), CreateAndCopyRelationData(), end_heap_rewrite(), FlushRelationBuffers(), FreeSpaceMapPrepareTruncateRel(), fsm_extend(), fsm_readbuf(), gist_indexsortbuild(), gist_indexsortbuild_flush_ready_pages(), gistBuildCallback(), heapam_relation_copy_data(), index_build(), index_copy_data(), pg_prewarm(), pg_truncate_visibility_map(), PrefetchBuffer(), raw_heap_insert(), ReadBufferExtended(), RelationCopyStorageUsingBuffer(), RelationGetNumberOfBlocksInFork(), RelationPreTruncate(), RelationTruncate(), ScanSourceDatabasePgClass(), spgbuildempty(), table_block_relation_size(), visibilitymap_prepare_truncate(), vm_extend(), and vm_readbuf().

◆ RelationIncrementReferenceCount()