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


typedef struct PartitionDescData PartitionDescData


PartitionDesc RelationGetPartitionDesc (Relation rel)
PartitionDirectory CreatePartitionDirectory (MemoryContext mcxt)
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)

Definition at line 283 of file partdesc.c.

References HASHCTL::entrysize, HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASHCTL::hcxt, HASHCTL::keysize, MemoryContextSwitchTo(), palloc(), PartitionDirectoryData::pdir_hash, and PartitionDirectoryData::pdir_mcxt.

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

284 {
285  MemoryContext oldcontext = MemoryContextSwitchTo(mcxt);
286  PartitionDirectory pdir;
287  HASHCTL ctl;
289  pdir = palloc(sizeof(PartitionDirectoryData));
290  pdir->pdir_mcxt = mcxt;
292  ctl.keysize = sizeof(Oid);
293  ctl.entrysize = sizeof(PartitionDirectoryEntry);
294  ctl.hcxt = mcxt;
296  pdir->pdir_hash = hash_create("partition directory", 256, &ctl,
299  MemoryContextSwitchTo(oldcontext);
300  return pdir;
301 }
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
MemoryContext hcxt
Definition: hsearch.h:86
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Size entrysize
Definition: hsearch.h:76
unsigned int Oid
Definition: postgres_ext.h:31
MemoryContext pdir_mcxt
Definition: partdesc.c:38
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
struct PartitionDirectoryEntry PartitionDirectoryEntry
#define HASH_BLOBS
Definition: hsearch.h:97
Size keysize
Definition: hsearch.h:75
void * palloc(Size size)
Definition: mcxt.c:950

◆ DestroyPartitionDirectory()

void DestroyPartitionDirectory ( PartitionDirectory  pdir)

Definition at line 343 of file partdesc.c.

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

Referenced by FreeExecutorState(), and standard_planner().

344 {
348  hash_seq_init(&status, pdir->pdir_hash);
349  while ((pde = hash_seq_search(&status)) != NULL)
351 }
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2103
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1436
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1426
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:227

◆ get_default_oid_from_partdesc()

Oid get_default_oid_from_partdesc ( PartitionDesc  partdesc)

Definition at line 360 of file partdesc.c.

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

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

361 {
362  if (partdesc && partdesc->boundinfo &&
364  return partdesc->oids[partdesc->boundinfo->default_index];
366  return InvalidOid;
367 }
PartitionBoundInfo boundinfo
Definition: partdesc.h:29
#define partition_bound_has_default(bi)
Definition: partbounds.h:75
#define InvalidOid
Definition: postgres_ext.h:36

◆ PartitionDirectoryLookup()

PartitionDesc PartitionDirectoryLookup ( PartitionDirectory  ,

Definition at line 315 of file partdesc.c.

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

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

316 {
318  Oid relid = RelationGetRelid(rel);
319  bool found;
321  pde = hash_search(pdir->pdir_hash, &relid, HASH_ENTER, &found);
322  if (!found)
323  {
324  /*
325  * We must keep a reference count on the relation so that the
326  * PartitionDesc to which we are pointing can't get destroyed.
327  */
329  pde->rel = rel;
330  pde->pd = RelationGetPartitionDesc(rel);
331  Assert(pde->pd != NULL);
332  }
333  return pde->pd;
334 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
unsigned int Oid
Definition: postgres_ext.h:31
PartitionDesc pd
Definition: partdesc.c:46
PartitionDesc RelationGetPartitionDesc(Relation rel)
Definition: partdesc.c:64
void RelationIncrementReferenceCount(Relation rel)
Definition: relcache.c:2090
#define Assert(condition)
Definition: c.h:792
#define RelationGetRelid(relation)
Definition: rel.h:457

◆ RelationGetPartitionDesc()

PartitionDesc RelationGetPartitionDesc ( Relation  rel)

Definition at line 64 of file partdesc.c.

References RelationData::rd_partdesc, RelationData::rd_rel, RelationBuildPartitionDesc(), and unlikely.

Referenced by addFkRecurseReferenced(), addFkRecurseReferencing(), ATExecAttachPartition(), ATExecAttachPartitionIdx(), ATExecDetachPartition(), ATPrepDropNotNull(), check_new_partition_bound(), CreateTrigger(), DefineIndex(), DefineRelation(), get_qual_for_list(), get_qual_for_range(), PartitionDirectoryLookup(), QueuePartitionConstraintValidation(), StorePartitionBound(), and validatePartitionedIndex().

65 {
66  if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
67  return NULL;
69  if (unlikely(rel->rd_partdesc == NULL))
72  return rel->rd_partdesc;
73 }
Form_pg_class rd_rel
Definition: rel.h:110
PartitionDesc rd_partdesc
Definition: rel.h:129
static void RelationBuildPartitionDesc(Relation rel)
Definition: partdesc.c:91
#define unlikely(x)
Definition: c.h:261