PostgreSQL Source Code git master
Loading...
Searching...
No Matches
rel.h File Reference
#include "access/tupdesc.h"
#include "access/xlog.h"
#include "catalog/catalog.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/relfilelocator.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)   ((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 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)
 
static void RelationCloseSmgr (Relation relation)
 
void RelationIncrementReferenceCount (Relation rel)
 
void RelationDecrementReferenceCount (Relation rel)
 

Macro Definition Documentation

◆ HEAP_DEFAULT_FILLFACTOR

#define HEAP_DEFAULT_FILLFACTOR   100

Definition at line 360 of file rel.h.

◆ HEAP_MIN_FILLFACTOR

#define HEAP_MIN_FILLFACTOR   10

Definition at line 359 of file rel.h.

◆ IndexRelationGetNumberOfAttributes

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

Definition at line 526 of file rel.h.

576{
577 if (unlikely(rel->rd_smgr == NULL))
578 {
579 rel->rd_smgr = smgropen(rel->rd_locator, rel->rd_backend);
580 smgrpin(rel->rd_smgr);
581 }
582 return rel->rd_smgr;
583}
584
585/*
586 * RelationCloseSmgr
587 * Close the relation at the smgr level, if not already done.
588 */
589static inline void
591{
592 if (relation->rd_smgr != NULL)
593 {
594 smgrunpin(relation->rd_smgr);
595 smgrclose(relation->rd_smgr);
596 relation->rd_smgr = NULL;
597 }
598}
599#endif /* !FRONTEND */
600
601/*
602 * RelationGetTargetBlock
603 * Fetch relation's current insertion target block.
604 *
605 * Returns InvalidBlockNumber if there is no current target block. Note
606 * that the target block status is discarded on any smgr-level invalidation,
607 * so there's no need to re-open the smgr handle if it's not currently open.
608 */
609#define RelationGetTargetBlock(relation) \
610 ( (relation)->rd_smgr != NULL ? (relation)->rd_smgr->smgr_targblock : InvalidBlockNumber )
611
612/*
613 * RelationSetTargetBlock
614 * Set relation's current insertion target block.
615 */
616#define RelationSetTargetBlock(relation, targblock) \
617 do { \
618 RelationGetSmgr(relation)->smgr_targblock = (targblock); \
619 } while (0)
620
621/*
622 * RelationIsPermanent
623 * True if relation is permanent.
624 */
625#define RelationIsPermanent(relation) \
626 ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
627
628/*
629 * RelationNeedsWAL
630 * True if relation needs WAL.
631 *
632 * Returns false if wal_level = minimal and this relation is created or
633 * truncated in the current transaction. See "Skipping WAL for New
634 * RelFileLocator" in src/backend/access/transam/README.
635 */
636#define RelationNeedsWAL(relation) \
637 (RelationIsPermanent(relation) && (XLogIsNeeded() || \
638 (relation->rd_createSubid == InvalidSubTransactionId && \
639 relation->rd_firstRelfilelocatorSubid == InvalidSubTransactionId)))
640
641/*
642 * RelationUsesLocalBuffers
643 * True if relation's pages are stored in local buffers.
644 */
645#define RelationUsesLocalBuffers(relation) \
646 ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
647
648/*
649 * RELATION_IS_LOCAL
650 * If a rel is either temp or newly created in the current transaction,
651 * it can be assumed to be accessible only to the current backend.
652 * This is typically used to decide that we can skip acquiring locks.
653 *
654 * Beware of multiple eval of argument
655 */
656#define RELATION_IS_LOCAL(relation) \
657 ((relation)->rd_islocaltemp || \
658 (relation)->rd_createSubid != InvalidSubTransactionId)
659
660/*
661 * RELATION_IS_OTHER_TEMP
662 * Test for a temporary relation that belongs to some other session.
663 *
664 * Beware of multiple eval of argument
665 */
666#define RELATION_IS_OTHER_TEMP(relation) \
667 ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \
668 !(relation)->rd_islocaltemp)
669
670
671/*
672 * RelationIsScannable
673 * Currently can only be false for a materialized view which has not been
674 * populated by its query. This is likely to get more complicated later,
675 * so use a macro which looks like a function.
676 */
677#define RelationIsScannable(relation) ((relation)->rd_rel->relispopulated)
678
679/*
680 * RelationIsPopulated
681 * Currently, we don't physically distinguish the "populated" and
682 * "scannable" properties of matviews, but that may change later.
683 * Hence, use the appropriate one of these macros in code tests.
684 */
685#define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated)
686
687/*
688 * RelationIsAccessibleInLogicalDecoding
689 * True if we need to log enough information to have access via
690 * decoding snapshot.
691 */
692#define RelationIsAccessibleInLogicalDecoding(relation) \
693 (XLogLogicalInfoActive() && \
694 RelationNeedsWAL(relation) && \
695 (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation)))
696
697/*
698 * RelationIsLogicallyLogged
699 * True if we need to log enough information to extract the data from the
700 * WAL stream.
701 *
702 * We don't log information for unlogged tables (since they don't WAL log
703 * anyway), for foreign tables (since they don't WAL log, either),
704 * and for system tables (their content is hard to make sense of, and
705 * it would complicate decoding slightly for little gain). Note that we *do*
706 * log information for user defined catalog tables since they presumably are
707 * interesting to the user...
708 */
709#define RelationIsLogicallyLogged(relation) \
710 (XLogLogicalInfoActive() && \
711 RelationNeedsWAL(relation) && \
712 (relation)->rd_rel->relkind != RELKIND_FOREIGN_TABLE && \
713 !IsCatalogRelation(relation))
714
715/* routines in utils/cache/relcache.c */
718
719#endif /* REL_H */
#define unlikely(x)
Definition c.h:412
static int fb(int x)
void RelationDecrementReferenceCount(Relation rel)
Definition relcache.c:2195
void RelationIncrementReferenceCount(Relation rel)
Definition relcache.c:2182
static void RelationCloseSmgr(Relation relation)
Definition rel.h:591
SMgrRelation smgropen(RelFileLocator rlocator, ProcNumber backend)
Definition smgr.c:240
void smgrpin(SMgrRelation reln)
Definition smgr.c:296
void smgrunpin(SMgrRelation reln)
Definition smgr.c:311
void smgrclose(SMgrRelation reln)
Definition smgr.c:374
SMgrRelation rd_smgr
Definition rel.h:58

◆ IndexRelationGetNumberOfKeyAttributes

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

Definition at line 533 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:672

Definition at line 657 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 667 of file rel.h.

◆ RelationGetDescr

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

Definition at line 540 of file rel.h.

◆ RelationGetFillFactor

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

Definition at line 374 of file rel.h.

376 : (defaultff))

◆ RelationGetForm

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

Definition at line 508 of file rel.h.

◆ RelationGetNamespace

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

Definition at line 555 of file rel.h.

◆ RelationGetNumberOfAttributes

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

Definition at line 520 of file rel.h.

◆ RelationGetParallelWorkers

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

Definition at line 408 of file rel.h.

410 : (defaultpw))

◆ RelationGetRelationName

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

Definition at line 548 of file rel.h.

◆ RelationGetRelid

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

Definition at line 514 of file rel.h.

◆ RelationGetTargetBlock

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

Definition at line 610 of file rel.h.

#define InvalidBlockNumber
Definition block.h:33

◆ RelationGetTargetPageFreeSpace

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

Definition at line 389 of file rel.h.

◆ RelationGetTargetPageUsage

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

Definition at line 382 of file rel.h.

◆ RelationGetToastTupleTarget

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

Definition at line 366 of file rel.h.

368 : (defaulttarg))

◆ RelationHasCascadedCheckOption

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

Definition at line 479 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 rel.h:415

Definition at line 457 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 rel.h:416

Definition at line 468 of file rel.h.

◆ RelationHasReferenceCountZero

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

Definition at line 498 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 447 of file rel.h.

450 : false)

◆ RelationIsAccessibleInLogicalDecoding

#define RelationIsAccessibleInLogicalDecoding (   relation)
Value:
RelationNeedsWAL(relation) && \
bool IsCatalogRelation(Relation relation)
Definition catalog.c:104
#define RelationIsUsedAsCatalogTable(relation)
Definition rel.h:397
#define XLogLogicalInfoActive()
Definition xlog.h:136

Definition at line 693 of file rel.h.

◆ RelationIsLogicallyLogged

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

Definition at line 710 of file rel.h.

◆ RelationIsMapped

#define RelationIsMapped (   relation)
Value:
(RELKIND_HAS_STORAGE((relation)->rd_rel->relkind) && \
((relation)->rd_rel->relfilenode == InvalidRelFileNumber))
#define InvalidRelFileNumber
Definition relpath.h:26

Definition at line 563 of file rel.h.

◆ RelationIsPermanent

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

Definition at line 626 of file rel.h.

◆ RelationIsPopulated

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

Definition at line 686 of file rel.h.

◆ RelationIsScannable

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

Definition at line 678 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 437 of file rel.h.

440 : false)

◆ 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)
#define false

Definition at line 397 of file rel.h.

401 : false)

◆ RelationIsValid

#define RelationIsValid (   relation)    ((relation) != NULL)

Definition at line 489 of file rel.h.

◆ RelationNeedsWAL

#define RelationNeedsWAL (   relation)
Value:
(RelationIsPermanent(relation) && (XLogIsNeeded() || \
(relation->rd_createSubid == InvalidSubTransactionId && \
relation->rd_firstRelfilelocatorSubid == InvalidSubTransactionId)))
#define RelationIsPermanent(relation)
Definition rel.h:626
#define XLogIsNeeded()
Definition xlog.h:111

Definition at line 637 of file rel.h.

◆ RelationSetTargetBlock

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

Definition at line 617 of file rel.h.

618 { \
619 RelationGetSmgr(relation)->smgr_targblock = (targblock); \
620 } while (0)

◆ RelationUsesLocalBuffers

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

Definition at line 646 of file rel.h.

Typedef Documentation

◆ AutoVacOpts

◆ ForeignKeyCacheInfo

◆ LockInfo

Definition at line 49 of file rel.h.

◆ LockInfoData

◆ LockRelId

◆ RelationData

◆ StdRdOptIndexCleanup

◆ StdRdOptions

◆ ViewOptCheckOption

◆ 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 334 of file rel.h.

335{
StdRdOptIndexCleanup
Definition rel.h:335
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO
Definition rel.h:336
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_OFF
Definition rel.h:337
@ STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON
Definition rel.h:338

◆ ViewOptCheckOption

Enumerator
VIEW_OPTION_CHECK_OPTION_NOT_SET 
VIEW_OPTION_CHECK_OPTION_LOCAL 
VIEW_OPTION_CHECK_OPTION_CASCADED 

Definition at line 413 of file rel.h.

Function Documentation

◆ RelationCloseSmgr()

static void RelationCloseSmgr ( Relation  relation)
inlinestatic

Definition at line 591 of file rel.h.

592{
593 if (relation->rd_smgr != NULL)
594 {
595 smgrunpin(relation->rd_smgr);
596 smgrclose(relation->rd_smgr);
597 relation->rd_smgr = NULL;
598 }
599}

References fb(), RelationData::rd_smgr, smgrclose(), and smgrunpin().

Referenced by RelationCacheInvalidate(), RelationDestroyRelation(), RelationDropStorage(), and RelationInvalidateRelation().

◆ RelationDecrementReferenceCount()

void RelationDecrementReferenceCount ( Relation  rel)
extern

Definition at line 2195 of file relcache.c.

2196{
2197 Assert(rel->rd_refcnt > 0);
2198 rel->rd_refcnt -= 1;
2201}
#define Assert(condition)
Definition c.h:873
#define IsBootstrapProcessingMode()
Definition miscadmin.h:477
static void ResourceOwnerForgetRelationRef(ResourceOwner owner, Relation rel)
Definition relcache.c:2168
ResourceOwner CurrentResourceOwner
Definition resowner.c:173
int rd_refcnt
Definition rel.h:59

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

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

◆ RelationGetSmgr()

◆ RelationIncrementReferenceCount()