partprune.h 2.9 KB

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