PostgreSQL Source Code  git master
partbounds.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * partbounds.h
4  *
5  * Copyright (c) 2007-2020, PostgreSQL Global Development Group
6  *
7  * src/include/partitioning/partbounds.h
8  *
9  *-------------------------------------------------------------------------
10  */
11 #ifndef PARTBOUNDS_H
12 #define PARTBOUNDS_H
13 
14 #include "fmgr.h"
15 #include "nodes/parsenodes.h"
16 #include "nodes/pg_list.h"
17 #include "partitioning/partdefs.h"
18 #include "utils/relcache.h"
19 struct RelOptInfo; /* avoid including pathnodes.h here */
20 
21 
22 /*
23  * PartitionBoundInfoData encapsulates a set of partition bounds. It is
24  * usually associated with partitioned tables as part of its partition
25  * descriptor, but may also be used to represent a virtual partitioned
26  * table such as a partitioned joinrel within the planner.
27  *
28  * A list partition datum that is known to be NULL is never put into the
29  * datums array. Instead, it is tracked using the null_index field.
30  *
31  * In the case of range partitioning, ndatums will typically be far less than
32  * 2 * nparts, because a partition's upper bound and the next partition's lower
33  * bound are the same in most common cases, and we only store one of them (the
34  * upper bound). In case of hash partitioning, ndatums will be same as the
35  * number of partitions.
36  *
37  * For range and list partitioned tables, datums is an array of datum-tuples
38  * with key->partnatts datums each. For hash partitioned tables, it is an array
39  * of datum-tuples with 2 datums, modulus and remainder, corresponding to a
40  * given partition.
41  *
42  * The datums in datums array are arranged in increasing order as defined by
43  * functions qsort_partition_rbound_cmp(), qsort_partition_list_value_cmp() and
44  * qsort_partition_hbound_cmp() for range, list and hash partitioned tables
45  * respectively. For range and list partitions this simply means that the
46  * datums in the datums array are arranged in increasing order as defined by
47  * the partition key's operator classes and collations.
48  *
49  * In the case of list partitioning, the indexes array stores one entry for
50  * every datum, which is the index of the partition that accepts a given datum.
51  * In case of range partitioning, it stores one entry per distinct range
52  * datum, which is the index of the partition for which a given datum
53  * is an upper bound. In the case of hash partitioning, the number of the
54  * entries in the indexes array is same as the greatest modulus amongst all
55  * partitions. For a given partition key datum-tuple, the index of the
56  * partition which would accept that datum-tuple would be given by the entry
57  * pointed by remainder produced when hash value of the datum-tuple is divided
58  * by the greatest modulus.
59  */
60 typedef struct PartitionBoundInfoData
61 {
62  char strategy; /* hash, list or range? */
63  int ndatums; /* Length of the datums following array */
65  PartitionRangeDatumKind **kind; /* The kind of each range bound datum;
66  * NULL for hash and list partitioned
67  * tables */
68  int *indexes; /* Partition indexes */
69  int null_index; /* Index of the null-accepting partition; -1
70  * if there isn't one */
71  int default_index; /* Index of the default partition; -1 if there
72  * isn't one */
74 
75 #define partition_bound_accepts_nulls(bi) ((bi)->null_index != -1)
76 #define partition_bound_has_default(bi) ((bi)->default_index != -1)
77 
79 extern uint64 compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc,
80  Oid *partcollation,
81  Datum *values, bool *isnull);
82 extern List *get_qual_from_partbound(Relation rel, Relation parent,
83  PartitionBoundSpec *spec);
85  int nparts, PartitionKey key, int **mapping);
86 extern bool partition_bounds_equal(int partnatts, int16 *parttyplen,
87  bool *parttypbyval, PartitionBoundInfo b1,
91 extern PartitionBoundInfo partition_bounds_merge(int partnatts,
92  FmgrInfo *partsupfunc,
93  Oid *partcollation,
94  struct RelOptInfo *outer_rel,
95  struct RelOptInfo *inner_rel,
96  JoinType jointype,
97  List **outer_parts,
98  List **inner_parts);
99 extern bool partitions_are_ordered(PartitionBoundInfo boundinfo, int nparts);
100 extern void check_new_partition_bound(char *relname, Relation parent,
101  PartitionBoundSpec *spec);
102 extern void check_default_partition_contents(Relation parent,
103  Relation defaultRel,
104  PartitionBoundSpec *new_spec);
105 
106 extern int32 partition_rbound_datum_cmp(FmgrInfo *partsupfunc,
107  Oid *partcollation,
108  Datum *rb_datums, PartitionRangeDatumKind *rb_kind,
109  Datum *tuple_datums, int n_tuple_datums);
110 extern int partition_list_bsearch(FmgrInfo *partsupfunc,
111  Oid *partcollation,
112  PartitionBoundInfo boundinfo,
113  Datum value, bool *is_equal);
114 extern int partition_range_datum_bsearch(FmgrInfo *partsupfunc,
115  Oid *partcollation,
116  PartitionBoundInfo boundinfo,
117  int nvalues, Datum *values, bool *is_equal);
118 extern int partition_hash_bsearch(PartitionBoundInfo boundinfo,
119  int modulus, int remainder);
120 
121 #endif /* PARTBOUNDS_H */
signed short int16
Definition: c.h:354
Definition: fmgr.h:56
PartitionRangeDatumKind ** kind
Definition: partbounds.h:65
int partition_list_bsearch(FmgrInfo *partsupfunc, Oid *partcollation, PartitionBoundInfo boundinfo, Datum value, bool *is_equal)
Definition: partbounds.c:3452
bool partitions_are_ordered(PartitionBoundInfo boundinfo, int nparts)
Definition: partbounds.c:2750
PartitionRangeDatumKind
Definition: parsenodes.h:836
PartitionBoundInfo partition_bounds_create(PartitionBoundSpec **boundspecs, int nparts, PartitionKey key, int **mapping)
Definition: partbounds.c:305
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
int partition_hash_bsearch(PartitionBoundInfo boundinfo, int modulus, int remainder)
Definition: partbounds.c:3584
signed int int32
Definition: c.h:355
JoinType
Definition: nodes.h:696
void check_default_partition_contents(Relation parent, Relation defaultRel, PartitionBoundSpec *new_spec)
Definition: partbounds.c:3101
bool partition_bounds_equal(int partnatts, int16 *parttyplen, bool *parttypbyval, PartitionBoundInfo b1, PartitionBoundInfo b2)
Definition: partbounds.c:799
void check_new_partition_bound(char *relname, Relation parent, PartitionBoundSpec *spec)
Definition: partbounds.c:2809
struct PartitionBoundInfoData PartitionBoundInfoData
uintptr_t Datum
Definition: postgres.h:367
static struct @143 value
int32 partition_rbound_datum_cmp(FmgrInfo *partsupfunc, Oid *partcollation, Datum *rb_datums, PartitionRangeDatumKind *rb_kind, Datum *tuple_datums, int n_tuple_datums)
Definition: partbounds.c:3401
int get_hash_partition_greatest_modulus(PartitionBoundInfo b)
Definition: partbounds.c:3264
List * get_qual_from_partbound(Relation rel, Relation parent, PartitionBoundSpec *spec)
Definition: partbounds.c:250
static Datum values[MAXATTR]
Definition: bootstrap.c:167
PartitionBoundInfo partition_bounds_copy(PartitionBoundInfo src, PartitionKey key)
Definition: partbounds.c:917
uint64 compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc, Oid *partcollation, Datum *values, bool *isnull)
Definition: partbounds.c:4615
Definition: pg_list.h:50
int partition_range_datum_bsearch(FmgrInfo *partsupfunc, Oid *partcollation, PartitionBoundInfo boundinfo, int nvalues, Datum *values, bool *is_equal)
Definition: partbounds.c:3541
PartitionBoundInfo partition_bounds_merge(int partnatts, FmgrInfo *partsupfunc, Oid *partcollation, struct RelOptInfo *outer_rel, struct RelOptInfo *inner_rel, JoinType jointype, List **outer_parts, List **inner_parts)
Definition: partbounds.c:1017