1 /*------------------------------------------------------------------------- 2 * 3 * partprune.h 4 * prototypes for partprune.c 5 * 6 * 7 * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group 8 * Portions Copyright (c) 1994, Regents of the University of California 9 * 10 * src/include/partitioning/partprune.h 11 * 12 *------------------------------------------------------------------------- 13 */ 14 #ifndef PARTPRUNE_H 15 #define PARTPRUNE_H 16 17 #include "nodes/execnodes.h" 18 #include "nodes/relation.h" 19 20 21 /* 22 * PartitionPruneContext 23 * Stores information needed at runtime for pruning computations 24 * related to a single partitioned table. 25 * 26 * partrel Relcache pointer for the partitioned table, 27 * if we have it open (else NULL). 28 * strategy Partition strategy, e.g. LIST, RANGE, HASH. 29 * partnatts Number of columns in the partition key. 30 * nparts Number of partitions in this partitioned table. 31 * boundinfo Partition boundary info for the partitioned table. 32 * partcollation Array of partnatts elements, storing the collations of the 33 * partition key columns. 34 * partsupfunc Array of FmgrInfos for the comparison or hashing functions 35 * associated with the partition keys (partnatts elements). 36 * (This points into the partrel's partition key, typically.) 37 * stepcmpfuncs Array of FmgrInfos for the comparison or hashing function 38 * for each pruning step and partition key. 39 * ppccontext Memory context holding this PartitionPruneContext's 40 * subsidiary data, such as the FmgrInfos. 41 * planstate Points to the parent plan node's PlanState when called 42 * during execution; NULL when called from the planner. 43 * exprstates Array of ExprStates, indexed as per PruneCtxStateIdx; one 44 * for each partition key in each pruning step. Allocated if 45 * planstate is non-NULL, otherwise NULL. 46 */ 47 typedef struct PartitionPruneContext 48 { 49 Relation partrel; 50 char strategy; 51 int partnatts; 52 int nparts; 53 PartitionBoundInfo boundinfo; 54 Oid *partcollation; 55 FmgrInfo *partsupfunc; 56 FmgrInfo *stepcmpfuncs; 57 MemoryContext ppccontext; 58 PlanState *planstate; 59 ExprState **exprstates; 60 } PartitionPruneContext; 61 62 /* 63 * PruneCxtStateIdx() computes the correct index into the stepcmpfuncs[], 64 * exprstates[] and exprhasexecparam[] arrays for step step_id and 65 * partition key column keyno. (Note: there is code that assumes the 66 * entries for a given step are sequential, so this is not chosen freely.) 67 */ 68 #define PruneCxtStateIdx(partnatts, step_id, keyno) \ 69 ((partnatts) * (step_id) + (keyno)) 70 71 extern PartitionPruneInfo *make_partition_pruneinfo(PlannerInfo *root, 72 RelOptInfo *parentrel, 73 List *subpaths, 74 List *partitioned_rels, 75 List *prunequal); 76 extern Relids prune_append_rel_partitions(RelOptInfo *rel); 77 extern Bitmapset *get_matching_partitions(PartitionPruneContext *context, 78 List *pruning_steps); 79 80 #endif /* PARTPRUNE_H */ 81