]> granicus.if.org Git - postgresql/blob - src/include/catalog/partition.h
537f0aad67545a907440401833b3bf0812995c21
[postgresql] / src / include / catalog / partition.h
1 /*-------------------------------------------------------------------------
2  *
3  * partition.h
4  *              Header file for structures and utility functions related to
5  *              partitioning
6  *
7  * Copyright (c) 2007-2017, PostgreSQL Global Development Group
8  *
9  * src/include/catalog/partition.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef PARTITION_H
14 #define PARTITION_H
15
16 #include "fmgr.h"
17 #include "executor/tuptable.h"
18 #include "nodes/execnodes.h"
19 #include "parser/parse_node.h"
20 #include "utils/rel.h"
21
22 /*
23  * PartitionBoundInfo encapsulates a set of partition bounds.  It is usually
24  * associated with partitioned tables as part of its partition descriptor.
25  *
26  * The internal structure is opaque outside partition.c.
27  */
28 typedef struct PartitionBoundInfoData *PartitionBoundInfo;
29
30 /*
31  * Information about partitions of a partitioned table.
32  */
33 typedef struct PartitionDescData
34 {
35         int                                     nparts;         /* Number of partitions */
36         Oid                                *oids;               /* OIDs of partitions */
37         PartitionBoundInfo      boundinfo;      /* collection of partition bounds */
38 } PartitionDescData;
39
40 typedef struct PartitionDescData *PartitionDesc;
41
42 /*-----------------------
43  * PartitionDispatch - information about one partitioned table in a partition
44  * hiearchy required to route a tuple to one of its partitions
45  *
46  *      reldesc         Relation descriptor of the table
47  *      key                     Partition key information of the table
48  *      keystate        Execution state required for expressions in the partition key
49  *      partdesc        Partition descriptor of the table
50  *      tupslot         A standalone TupleTableSlot initialized with this table's tuple
51  *                              descriptor
52  *      tupmap          TupleConversionMap to convert from the parent's rowtype to
53  *                              this table's rowtype (when extracting the partition key of a
54  *                              tuple just before routing it through this table)
55  *      indexes         Array with partdesc->nparts members (for details on what
56  *                              individual members represent, see how they are set in
57  *                              RelationGetPartitionDispatchInfo())
58  *-----------------------
59  */
60 typedef struct PartitionDispatchData
61 {
62         Relation                                reldesc;
63         PartitionKey                    key;
64         List                               *keystate;   /* list of ExprState */
65         PartitionDesc                   partdesc;
66         TupleTableSlot             *tupslot;
67         TupleConversionMap         *tupmap;
68         int                                        *indexes;
69 } PartitionDispatchData;
70
71 typedef struct PartitionDispatchData *PartitionDispatch;
72
73 extern void RelationBuildPartitionDesc(Relation relation);
74 extern bool partition_bounds_equal(PartitionKey key,
75                                            PartitionBoundInfo p1, PartitionBoundInfo p2);
76
77 extern void check_new_partition_bound(char *relname, Relation parent, Node *bound);
78 extern Oid get_partition_parent(Oid relid);
79 extern List *get_qual_from_partbound(Relation rel, Relation parent, Node *bound);
80 extern List *map_partition_varattnos(List *expr, Relation partrel, Relation parent);
81 extern List *RelationGetPartitionQual(Relation rel);
82
83 /* For tuple routing */
84 extern PartitionDispatch *RelationGetPartitionDispatchInfo(Relation rel,
85                                                                  int lockmode, int *num_parted,
86                                                                  List **leaf_part_oids);
87 extern int get_partition_for_tuple(PartitionDispatch *pd,
88                                         TupleTableSlot *slot,
89                                         EState *estate,
90                                         Oid *failed_at);
91 #endif   /* PARTITION_H */