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 include_detached)
 
PartitionDirectory CreatePartitionDirectory (MemoryContext mcxt, bool include_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  include_detached 
)

Definition at line 287 of file partdesc.c.

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

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

288 {
289  MemoryContext oldcontext = MemoryContextSwitchTo(mcxt);
290  PartitionDirectory pdir;
291  HASHCTL ctl;
292 
293  pdir = palloc(sizeof(PartitionDirectoryData));
294  pdir->pdir_mcxt = mcxt;
295 
296  ctl.keysize = sizeof(Oid);
297  ctl.entrysize = sizeof(PartitionDirectoryEntry);
298  ctl.hcxt = mcxt;
299 
300  pdir->pdir_hash = hash_create("partition directory", 256, &ctl,
302  pdir->include_detached = include_detached;
303 
304  MemoryContextSwitchTo(oldcontext);
305  return pdir;
306 }
#define HASH_CONTEXT
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:1062

◆ DestroyPartitionDirectory()

void DestroyPartitionDirectory ( PartitionDirectory  pdir)

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

349 {
352 
353  hash_seq_init(&status, pdir->pdir_hash);
354  while ((pde = hash_seq_search(&status)) != NULL)
356 }
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2076
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 365 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().

366 {
367  if (partdesc && partdesc->boundinfo &&
369  return partdesc->oids[partdesc->boundinfo->default_index];
370 
371  return InvalidOid;
372 }
PartitionBoundInfo boundinfo
Definition: partdesc.h:30
#define partition_bound_has_default(bi)
Definition: partbounds.h:82
#define InvalidOid
Definition: postgres_ext.h:36

◆ PartitionDirectoryLookup()

PartitionDesc PartitionDirectoryLookup ( PartitionDirectory  ,
Relation   
)

Definition at line 320 of file partdesc.c.

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

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

321 {
323  Oid relid = RelationGetRelid(rel);
324  bool found;
325 
326  pde = hash_search(pdir->pdir_hash, &relid, HASH_ENTER, &found);
327  if (!found)
328  {
329  /*
330  * We must keep a reference count on the relation so that the
331  * PartitionDesc to which we are pointing can't get destroyed.
332  */
334  pde->rel = rel;
335  pde->pd = RelationGetPartitionDesc(rel, pdir->include_detached);
336  Assert(pde->pd != NULL);
337  }
338  return pde->pd;
339 }
PartitionDesc RelationGetPartitionDesc(Relation rel, bool include_detached)
Definition: partdesc.c:65
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:47
void RelationIncrementReferenceCount(Relation rel)
Definition: relcache.c:2063
#define Assert(condition)
Definition: c.h:804
#define RelationGetRelid(relation)
Definition: rel.h:457

◆ RelationGetPartitionDesc()

PartitionDesc RelationGetPartitionDesc ( Relation  rel,
bool  include_detached 
)

Definition at line 65 of file partdesc.c.

References PartitionDescData::includes_detached, 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;
69 
70  if (unlikely(rel->rd_partdesc == NULL ||
71  rel->rd_partdesc->includes_detached != include_detached))
72  RelationBuildPartitionDesc(rel, include_detached);
73 
74  return rel->rd_partdesc;
75 }
bool includes_detached
Definition: partdesc.h:24
Form_pg_class rd_rel
Definition: rel.h:110
static void RelationBuildPartitionDesc(Relation rel, bool include_detached)
Definition: partdesc.c:93
PartitionDesc rd_partdesc
Definition: rel.h:129
#define unlikely(x)
Definition: c.h:273