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 381 of file partdesc.c.

382 {
383  MemoryContext oldcontext = MemoryContextSwitchTo(mcxt);
384  PartitionDirectory pdir;
385  HASHCTL ctl;
386 
387  pdir = palloc(sizeof(PartitionDirectoryData));
388  pdir->pdir_mcxt = mcxt;
389 
390  ctl.keysize = sizeof(Oid);
391  ctl.entrysize = sizeof(PartitionDirectoryEntry);
392  ctl.hcxt = mcxt;
393 
394  pdir->pdir_hash = hash_create("partition directory", 256, &ctl,
396  pdir->omit_detached = omit_detached;
397 
398  MemoryContextSwitchTo(oldcontext);
399  return pdir;
400 }
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:1304
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
struct PartitionDirectoryEntry PartitionDirectoryEntry
unsigned int Oid
Definition: postgres_ext.h:31
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
MemoryContext hcxt
Definition: hsearch.h:86
MemoryContext pdir_mcxt
Definition: partdesc.c:36

References HASHCTL::entrysize, HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASHCTL::hcxt, HASHCTL::keysize, 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 442 of file partdesc.c.

443 {
444  HASH_SEQ_STATUS status;
446 
447  hash_seq_init(&status, pdir->pdir_hash);
448  while ((pde = hash_seq_search(&status)) != NULL)
450 }
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1395
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1385
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2166

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 459 of file partdesc.c.

460 {
461  if (partdesc && partdesc->boundinfo &&
463  return partdesc->oids[partdesc->boundinfo->default_index];
464 
465  return InvalidOid;
466 }
#define partition_bound_has_default(bi)
Definition: partbounds.h:99
#define InvalidOid
Definition: postgres_ext.h:36
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 414 of file partdesc.c.

415 {
417  Oid relid = RelationGetRelid(rel);
418  bool found;
419 
420  pde = hash_search(pdir->pdir_hash, &relid, HASH_ENTER, &found);
421  if (!found)
422  {
423  /*
424  * We must keep a reference count on the relation so that the
425  * PartitionDesc to which we are pointing can't get destroyed.
426  */
428  pde->rel = rel;
429  pde->pd = RelationGetPartitionDesc(rel, pdir->omit_detached);
430  Assert(pde->pd != NULL);
431  }
432  return pde->pd;
433 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:955
@ HASH_ENTER
Definition: hsearch.h:114
Assert(fmt[strlen(fmt) - 1] !='\n')
PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached)
Definition: partdesc.c:70
#define RelationGetRelid(relation)
Definition: rel.h:505
void RelationIncrementReferenceCount(Relation rel)
Definition: relcache.c:2153
PartitionDesc pd
Definition: partdesc.c:45

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 70 of file partdesc.c.

71 {
72  Assert(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
73 
74  /*
75  * If relcache has a partition descriptor, use that. However, we can only
76  * do so when we are asked to include all partitions including detached;
77  * and also when we know that there are no detached partitions.
78  *
79  * If there is no active snapshot, detached partitions aren't omitted
80  * either, so we can use the cached descriptor too in that case.
81  */
82  if (likely(rel->rd_partdesc &&
83  (!rel->rd_partdesc->detached_exist || !omit_detached ||
84  !ActiveSnapshotSet())))
85  return rel->rd_partdesc;
86 
87  /*
88  * If we're asked to omit detached partitions, we may be able to use a
89  * cached descriptor too. We determine that based on the pg_inherits.xmin
90  * that was saved alongside that descriptor: if the xmin that was not in
91  * progress for that active snapshot is also not in progress for the
92  * current active snapshot, then we can use it. Otherwise build one from
93  * scratch.
94  */
95  if (omit_detached &&
98  {
99  Snapshot activesnap;
100 
102  activesnap = GetActiveSnapshot();
103 
104  if (!XidInMVCCSnapshot(rel->rd_partdesc_nodetached_xmin, activesnap))
105  return rel->rd_partdesc_nodetached;
106  }
107 
108  return RelationBuildPartitionDesc(rel, omit_detached);
109 }
#define likely(x)
Definition: c.h:297
static PartitionDesc RelationBuildPartitionDesc(Relation rel, bool omit_detached)
Definition: partdesc.c:133
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition: snapmgr.c:1856
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:782
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:770
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(), ATExecDropNotNull(), check_new_partition_bound(), CreateTriggerFiringOn(), DefineIndex(), DefineRelation(), EnableDisableTrigger(), get_qual_for_list(), get_qual_for_range(), PartitionDirectoryLookup(), QueuePartitionConstraintValidation(), renametrig(), renametrig_partition(), StorePartitionBound(), and validatePartitionedIndex().