1 /*-------------------------------------------------------------------------
5 * Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * src/include/partitioning/partdesc.h
9 *-------------------------------------------------------------------------
15 #include "partitioning/partdefs.h"
16 #include "utils/relcache.h"
19 * Information about partitions of a partitioned table.
21 * For partitioned tables where detached partitions exist, we only cache
22 * descriptors that include all partitions, including detached; when we're
23 * requested a descriptor without the detached partitions, we create one
24 * afresh each time. (The reason for this is that the set of detached
25 * partitions that are visible to each caller depends on the snapshot it has,
26 * so it's pretty much impossible to evict a descriptor from cache at the
29 typedef struct PartitionDescData
31 int nparts
; /* Number of partitions */
32 bool detached_exist
; /* Are there any detached partitions? */
33 Oid
*oids
; /* Array of 'nparts' elements containing
34 * partition OIDs in order of their bounds */
35 bool *is_leaf
; /* Array of 'nparts' elements storing whether
36 * the corresponding 'oids' element belongs to
37 * a leaf partition or not */
38 PartitionBoundInfo boundinfo
; /* collection of partition bounds */
40 /* Caching fields to cache lookups in get_partition_for_tuple() */
43 * Index into the PartitionBoundInfo's datum array for the last found
44 * partition or -1 if none.
46 int last_found_datum_index
;
49 * Partition index of the last found partition or -1 if none has been
52 int last_found_part_index
;
55 * For LIST partitioning, this is the number of times in a row that the
56 * datum we're looking for a partition for matches the datum in the
57 * last_found_datum_index index of the boundinfo->datums array. For RANGE
58 * partitioning, this is the number of times in a row we've found that the
59 * datum we're looking for a partition for falls into the range of the
60 * partition corresponding to the last_found_datum_index index of the
61 * boundinfo->datums array.
67 extern PartitionDesc
RelationGetPartitionDesc(Relation rel
, bool omit_detached
);
69 extern PartitionDirectory
CreatePartitionDirectory(MemoryContext mcxt
, bool omit_detached
);
70 extern PartitionDesc
PartitionDirectoryLookup(PartitionDirectory
, Relation
);
71 extern void DestroyPartitionDirectory(PartitionDirectory pdir
);
73 extern Oid
get_default_oid_from_partdesc(PartitionDesc partdesc
);
75 #endif /* PARTCACHE_H */