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

384 {
385  MemoryContext oldcontext = MemoryContextSwitchTo(mcxt);
386  PartitionDirectory pdir;
387  HASHCTL ctl;
388 
389  pdir = palloc(sizeof(PartitionDirectoryData));
390  pdir->pdir_mcxt = mcxt;
391 
392  ctl.keysize = sizeof(Oid);
393  ctl.entrysize = sizeof(PartitionDirectoryEntry);
394  ctl.hcxt = mcxt;
395 
396  pdir->pdir_hash = hash_create("partition directory", 256, &ctl,
398  pdir->omit_detached = omit_detached;
399 
400  MemoryContextSwitchTo(oldcontext);
401  return pdir;
402 }
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:350
#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:1210
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
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:38

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

445 {
448 
449  hash_seq_init(&status, pdir->pdir_hash);
450  while ((pde = hash_seq_search(&status)) != NULL)
452 }
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1431
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1421
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2140

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

Referenced by FreeExecutorState(), and standard_planner().

◆ get_default_oid_from_partdesc()

Oid get_default_oid_from_partdesc ( PartitionDesc  partdesc)

Definition at line 461 of file partdesc.c.

462 {
463  if (partdesc && partdesc->boundinfo &&
465  return partdesc->oids[partdesc->boundinfo->default_index];
466 
467  return InvalidOid;
468 }
#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 416 of file partdesc.c.

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

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

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