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)
 
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;
289 
290  MemSet(&ctl, 0, sizeof(HASHCTL));
291  ctl.keysize = sizeof(Oid);
292  ctl.entrysize = sizeof(PartitionDirectoryEntry);
293  ctl.hcxt = mcxt;
294 
295  pdir = palloc(sizeof(PartitionDirectoryData));
296  pdir->pdir_mcxt = mcxt;
297  pdir->pdir_hash = hash_create("partition directory", 256, &ctl,
299 
300  MemoryContextSwitchTo(oldcontext);
301  return pdir;
302 }
#define HASH_CONTEXT
Definition: hsearch.h:93
#define HASH_ELEM
Definition: hsearch.h:87
MemoryContext hcxt
Definition: hsearch.h:78
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:949
unsigned int Oid
Definition: postgres_ext.h:31
MemoryContext pdir_mcxt
Definition: partdesc.c:39
struct PartitionDirectoryEntry PartitionDirectoryEntry
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:328
Size keysize
Definition: hsearch.h:72
void * palloc(Size size)
Definition: mcxt.c:949

◆ 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 {
348 
349  hash_seq_init(&status, pdir->pdir_hash);
350  while ((pde = hash_seq_search(&status)) != NULL)
352 }
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2083
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1410
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1400
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225

◆ 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];
366 
367  return InvalidOid;
368 }
PartitionBoundInfo boundinfo
Definition: partdesc.h:29
#define partition_bound_has_default(bi)
Definition: partbounds.h:76
#define InvalidOid
Definition: postgres_ext.h:36

◆ PartitionDirectoryLookup()

PartitionDesc PartitionDirectoryLookup ( PartitionDirectory  ,
Relation   
)

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;
321 
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:927
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:2070
#define Assert(condition)
Definition: c.h:745
#define RelationGetRelid(relation)
Definition: rel.h:456

◆ RelationGetPartitionDesc()

PartitionDesc RelationGetPartitionDesc ( Relation  rel)