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

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

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

285 {
286  MemoryContext oldcontext = MemoryContextSwitchTo(mcxt);
287  PartitionDirectory pdir;
288  HASHCTL ctl;
290  MemSet(&ctl, 0, sizeof(HASHCTL));
291  ctl.keysize = sizeof(Oid);
292  ctl.entrysize = sizeof(PartitionDirectoryEntry);
293  ctl.hcxt = mcxt;
295  pdir = palloc(sizeof(PartitionDirectoryData));
296  pdir->pdir_mcxt = mcxt;
297  pdir->pdir_hash = hash_create("partition directory", 256, &ctl,
300  MemoryContextSwitchTo(oldcontext);
301  return pdir;
302 }
Definition: hsearch.h:91
#define HASH_ELEM
Definition: hsearch.h:85
MemoryContext hcxt
Definition: hsearch.h:77
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Size entrysize
Definition: hsearch.h:72
#define MemSet(start, val, len)
Definition: c.h:950
unsigned int Oid
Definition: postgres_ext.h:31
MemoryContext pdir_mcxt
Definition: partdesc.c:39
struct PartitionDirectoryEntry PartitionDirectoryEntry
#define HASH_BLOBS
Definition: hsearch.h:86
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:326
Size keysize
Definition: hsearch.h:71
void * palloc(Size size)
Definition: mcxt.c:950

◆ DestroyPartitionDirectory()

void DestroyPartitionDirectory ( PartitionDirectory  pdir)

Definition at line 344 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().

345 {
349  hash_seq_init(&status, pdir->pdir_hash);
350  while ((pde = hash_seq_search(&status)) != NULL)
352 }
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2090
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1401
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1391
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 361 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().

362 {
363  if (partdesc && partdesc->boundinfo &&
365  return partdesc->oids[partdesc->boundinfo->default_index];
367  return InvalidOid;
368 }
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 316 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().

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

◆ RelationGetPartitionDesc()

PartitionDesc RelationGetPartitionDesc ( Relation  rel)

Definition at line 65 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().

66 {
67  if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
68  return NULL;
70  if (unlikely(rel->rd_partdesc == NULL))
73  return rel->rd_partdesc;
74 }
Form_pg_class rd_rel
Definition: rel.h:109
PartitionDesc rd_partdesc
Definition: rel.h:128
static void RelationBuildPartitionDesc(Relation rel)
Definition: partdesc.c:92
#define unlikely(x)
Definition: c.h:207