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 * hierarchy 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, 78 PartitionBoundSpec *spec); 79 extern Oid get_partition_parent(Oid relid); 80 extern List *get_qual_from_partbound(Relation rel, Relation parent, 81 PartitionBoundSpec *spec); 82 extern List *map_partition_varattnos(List *expr, int target_varno, 83 Relation partrel, Relation parent, 84 bool *found_whole_row); 85 extern List *RelationGetPartitionQual(Relation rel); 86 extern Expr *get_partition_qual_relid(Oid relid); 87 88 /* For tuple routing */ 89 extern PartitionDispatch *RelationGetPartitionDispatchInfo(Relation rel, 90 int *num_parted, List **leaf_part_oids); 91 extern void FormPartitionKeyDatum(PartitionDispatch pd, 92 TupleTableSlot *slot, 93 EState *estate, 94 Datum *values, 95 bool *isnull); 96 extern int get_partition_for_tuple(PartitionDispatch *pd, 97 TupleTableSlot *slot, 98 EState *estate, 99 PartitionDispatchData **failed_at, 100 TupleTableSlot **failed_slot); 101 #endif /* PARTITION_H */ 102