PostgreSQL Source Code git master
partdesc.h File Reference
Include dependency graph for partdesc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PartitionDescData
 

Typedefs

typedef struct PartitionDescData PartitionDescData
 

Functions

PartitionDesc RelationGetPartitionDesc (Relation rel, bool omit_detached)
 
PartitionDirectory CreatePartitionDirectory (MemoryContext mcxt, bool omit_detached)
 
PartitionDesc PartitionDirectoryLookup (PartitionDirectory, Relation)
 
void DestroyPartitionDirectory (PartitionDirectory pdir)
 
Oid get_default_oid_from_partdesc (PartitionDesc partdesc)
 

Typedef Documentation

◆ PartitionDescData

Function Documentation

◆ CreatePartitionDirectory()

PartitionDirectory CreatePartitionDirectory ( MemoryContext  mcxt,
bool  omit_detached 
)

Definition at line 423 of file partdesc.c.

424{
425 MemoryContext oldcontext = MemoryContextSwitchTo(mcxt);
427 HASHCTL ctl;
428
429 pdir = palloc(sizeof(PartitionDirectoryData));
430 pdir->pdir_mcxt = mcxt;
431
432 ctl.keysize = sizeof(Oid);
433 ctl.entrysize = sizeof(PartitionDirectoryEntry);
434 ctl.hcxt = mcxt;
435
436 pdir->pdir_hash = hash_create("partition directory", 256, &ctl,
438 pdir->omit_detached = omit_detached;
439
440 MemoryContextSwitchTo(oldcontext);
441 return pdir;
442}
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:352
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
void * palloc(Size size)
Definition: mcxt.c:1317
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
struct PartitionDirectoryEntry PartitionDirectoryEntry
unsigned int Oid
Definition: postgres_ext.h:32
tree ctl
Definition: radixtree.h:1838
MemoryContext pdir_mcxt
Definition: partdesc.c:37

References ctl, HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, MemoryContextSwitchTo(), PartitionDirectoryData::omit_detached, palloc(), PartitionDirectoryData::pdir_hash, and PartitionDirectoryData::pdir_mcxt.

Referenced by CreatePartitionPruneState(), ExecInitPartitionDispatchInfo(), and set_relation_partition_info().

◆ DestroyPartitionDirectory()

void DestroyPartitionDirectory ( PartitionDirectory  pdir)

Definition at line 484 of file partdesc.c.

485{
486 HASH_SEQ_STATUS status;
488
489 hash_seq_init(&status, pdir->pdir_hash);
490 while ((pde = hash_seq_search(&status)) != NULL)
492}
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1420
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1385
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2151

References hash_seq_init(), hash_seq_search(), PartitionDirectoryData::pdir_hash, PartitionDirectoryEntry::rel, and RelationDecrementReferenceCount().

Referenced by FreeExecutorState(), and standard_planner().

◆ get_default_oid_from_partdesc()

Oid get_default_oid_from_partdesc ( PartitionDesc  partdesc)

Definition at line 501 of file partdesc.c.

502{
503 if (partdesc && partdesc->boundinfo &&
505 return partdesc->oids[partdesc->boundinfo->default_index];
506
507 return InvalidOid;
508}
#define partition_bound_has_default(bi)
Definition: partbounds.h:99
#define InvalidOid
Definition: postgres_ext.h:37
PartitionBoundInfo boundinfo
Definition: partdesc.h:38

References PartitionDescData::boundinfo, PartitionBoundInfoData::default_index, InvalidOid, PartitionDescData::oids, and partition_bound_has_default.

Referenced by ATExecAttachPartition(), ATExecDetachPartition(), DefineRelation(), and StorePartitionBound().

◆ PartitionDirectoryLookup()

PartitionDesc PartitionDirectoryLookup ( PartitionDirectory  pdir,
Relation  rel 
)

Definition at line 456 of file partdesc.c.

457{
459 Oid relid = RelationGetRelid(rel);
460 bool found;
461
462 pde = hash_search(pdir->pdir_hash, &relid, HASH_ENTER, &found);
463 if (!found)
464 {
465 /*
466 * We must keep a reference count on the relation so that the
467 * PartitionDesc to which we are pointing can't get destroyed.
468 */
470 pde->rel = rel;
471 pde->pd = RelationGetPartitionDesc(rel, pdir->omit_detached);
472 Assert(pde->pd != NULL);
473 }
474 return pde->pd;
475}
#define Assert(condition)
Definition: c.h:815
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:955
@ HASH_ENTER
Definition: hsearch.h:114
PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached)
Definition: partdesc.c:71
#define RelationGetRelid(relation)
Definition: rel.h:505
void RelationIncrementReferenceCount(Relation rel)
Definition: relcache.c:2138
PartitionDesc pd
Definition: partdesc.c:46

References Assert, HASH_ENTER, hash_search(), PartitionDirectoryData::omit_detached, PartitionDirectoryEntry::pd, PartitionDirectoryData::pdir_hash, PartitionDirectoryEntry::rel, RelationGetPartitionDesc(), RelationGetRelid, and RelationIncrementReferenceCount().

Referenced by CreatePartitionPruneState(), ExecInitPartitionDispatchInfo(), expand_partitioned_rtentry(), and set_relation_partition_info().

◆ RelationGetPartitionDesc()

PartitionDesc RelationGetPartitionDesc ( Relation  rel,
bool  omit_detached 
)

Definition at line 71 of file partdesc.c.

72{
73 Assert(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
74
75 /*
76 * If relcache has a partition descriptor, use that. However, we can only
77 * do so when we are asked to include all partitions including detached;
78 * and also when we know that there are no detached partitions.
79 *
80 * If there is no active snapshot, detached partitions aren't omitted
81 * either, so we can use the cached descriptor too in that case.
82 */
83 if (likely(rel->rd_partdesc &&
84 (!rel->rd_partdesc->detached_exist || !omit_detached ||
86 return rel->rd_partdesc;
87
88 /*
89 * If we're asked to omit detached partitions, we may be able to use a
90 * cached descriptor too. We determine that based on the pg_inherits.xmin
91 * that was saved alongside that descriptor: if the xmin that was not in
92 * progress for that active snapshot is also not in progress for the
93 * current active snapshot, then we can use it. Otherwise build one from
94 * scratch.
95 */
96 if (omit_detached &&
99 {
100 Snapshot activesnap;
101
103 activesnap = GetActiveSnapshot();
104
105 if (!XidInMVCCSnapshot(rel->rd_partdesc_nodetached_xmin, activesnap))
106 return rel->rd_partdesc_nodetached;
107 }
108
109 return RelationBuildPartitionDesc(rel, omit_detached);
110}
#define likely(x)
Definition: c.h:332
static PartitionDesc RelationBuildPartitionDesc(Relation rel, bool omit_detached)
Definition: partdesc.c:134
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition: snapmgr.c:1800
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:740
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:728
bool detached_exist
Definition: partdesc.h:32
TransactionId rd_partdesc_nodetached_xmin
Definition: rel.h:144
PartitionDesc rd_partdesc
Definition: rel.h:130
PartitionDesc rd_partdesc_nodetached
Definition: rel.h:134
Form_pg_class rd_rel
Definition: rel.h:111
#define TransactionIdIsValid(xid)
Definition: transam.h:41

References ActiveSnapshotSet(), Assert, PartitionDescData::detached_exist, GetActiveSnapshot(), likely, RelationData::rd_partdesc, RelationData::rd_partdesc_nodetached, RelationData::rd_partdesc_nodetached_xmin, RelationData::rd_rel, RelationBuildPartitionDesc(), TransactionIdIsValid, and XidInMVCCSnapshot().

Referenced by addFkRecurseReferenced(), addFkRecurseReferencing(), ATExecAttachPartition(), ATExecAttachPartitionIdx(), ATExecDetachPartition(), check_new_partition_bound(), CreateTriggerFiringOn(), DefineIndex(), DefineRelation(), EnableDisableTrigger(), get_qual_for_list(), get_qual_for_range(), PartitionDirectoryLookup(), QueuePartitionConstraintValidation(), renametrig(), renametrig_partition(), StorePartitionBound(), and validatePartitionedIndex().