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

410 {
411  MemoryContext oldcontext = MemoryContextSwitchTo(mcxt);
412  PartitionDirectory pdir;
413  HASHCTL ctl;
414 
415  pdir = palloc(sizeof(PartitionDirectoryData));
416  pdir->pdir_mcxt = mcxt;
417 
418  ctl.keysize = sizeof(Oid);
419  ctl.entrysize = sizeof(PartitionDirectoryEntry);
420  ctl.hcxt = mcxt;
421 
422  pdir->pdir_hash = hash_create("partition directory", 256, &ctl,
424  pdir->omit_detached = omit_detached;
425 
426  MemoryContextSwitchTo(oldcontext);
427  return pdir;
428 }
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
struct PartitionDirectoryEntry PartitionDirectoryEntry
unsigned int Oid
Definition: postgres_ext.h:31
MemoryContextSwitchTo(old_ctx)
tree ctl
Definition: radixtree.h:1853
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 470 of file partdesc.c.

471 {
472  HASH_SEQ_STATUS status;
474 
475  hash_seq_init(&status, pdir->pdir_hash);
476  while ((pde = hash_seq_search(&status)) != NULL)
478 }
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:2172

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)

◆ PartitionDirectoryLookup()

PartitionDesc PartitionDirectoryLookup ( PartitionDirectory  pdir,
Relation  rel 
)

Definition at line 442 of file partdesc.c.

443 {
445  Oid relid = RelationGetRelid(rel);
446  bool found;
447 
448  pde = hash_search(pdir->pdir_hash, &relid, HASH_ENTER, &found);
449  if (!found)
450  {
451  /*
452  * We must keep a reference count on the relation so that the
453  * PartitionDesc to which we are pointing can't get destroyed.
454  */
456  pde->rel = rel;
457  pde->pd = RelationGetPartitionDesc(rel, pdir->omit_detached);
458  Assert(pde->pd != NULL);
459  }
460  return pde->pd;
461 }
#define Assert(condition)
Definition: c.h:858
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:2159
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 ||
85  !ActiveSnapshotSet())))
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:310
static PartitionDesc RelationBuildPartitionDesc(Relation rel, bool omit_detached)
Definition: partdesc.c:134
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(), ATExecMergePartitions(), ATExecSplitPartition(), ATPrepDropNotNull(), check_new_partition_bound(), check_parent_values_in_new_partitions(), check_partition_bounds_for_split_list(), check_partitions_for_split(), CreateTriggerFiringOn(), DefineIndex(), DefineRelation(), EnableDisableTrigger(), get_qual_for_list(), get_qual_for_range(), PartitionDirectoryLookup(), QueuePartitionConstraintValidation(), renametrig(), renametrig_partition(), StorePartitionBound(), transformPartitionCmdForMerge(), and validatePartitionedIndex().