1/*-------------------------------------------------------------------------
2 *
3 * partprune.h
4 * prototypes for partprune.c
5 *
6 *
7 * Portions Copyright (c) 1996-2019, 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 "partitioning/partdefs.h"
19
20struct PlannerInfo; /* avoid including pathnodes.h here */
21struct RelOptInfo;
22
23
24/*
25 * PartitionPruneContext
26 * Stores information needed at runtime for pruning computations
27 * related to a single partitioned table.
28 *
29 * strategy Partition strategy, e.g. LIST, RANGE, HASH.
30 * partnatts Number of columns in the partition key.
31 * nparts Number of partitions in this partitioned table.
32 * boundinfo Partition boundary info for the partitioned table.
33 * partcollation Array of partnatts elements, storing the collations of the
34 * partition key columns.
35 * partsupfunc Array of FmgrInfos for the comparison or hashing functions
36 * associated with the partition keys (partnatts elements).
37 * (This points into the partrel's partition key, typically.)
38 * stepcmpfuncs Array of FmgrInfos for the comparison or hashing function
39 * for each pruning step and partition key.
40 * ppccontext Memory context holding this PartitionPruneContext's
41 * subsidiary data, such as the FmgrInfos.
42 * planstate Points to the parent plan node's PlanState when called
43 * during execution; NULL when called from the planner.
44 * exprstates Array of ExprStates, indexed as per PruneCxtStateIdx; one
45 * for each partition key in each pruning step. Allocated if
46 * planstate is non-NULL, otherwise NULL.
47 */
48typedef struct PartitionPruneContext
49{
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
71extern PartitionPruneInfo *make_partition_pruneinfo(struct PlannerInfo *root,
72 struct RelOptInfo *parentrel,
73 List *subpaths,
74 List *partitioned_rels,
75 List *prunequal);
76extern Bitmapset *prune_append_rel_partitions(struct RelOptInfo *rel);
77extern Bitmapset *get_matching_partitions(PartitionPruneContext *context,
78 List *pruning_steps);
79
80#endif /* PARTPRUNE_H */
81