2
0

execPartition.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*--------------------------------------------------------------------
  2. * execPartition.h
  3. * POSTGRES partitioning executor interface
  4. *
  5. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  6. * Portions Copyright (c) 1994, Regents of the University of California
  7. *
  8. * IDENTIFICATION
  9. * src/include/executor/execPartition.h
  10. *--------------------------------------------------------------------
  11. */
  12. #ifndef EXECPARTITION_H
  13. #define EXECPARTITION_H
  14. #include "nodes/execnodes.h"
  15. #include "nodes/parsenodes.h"
  16. #include "nodes/plannodes.h"
  17. #include "partitioning/partprune.h"
  18. /* See execPartition.c for the definitions. */
  19. typedef struct PartitionDispatchData *PartitionDispatch;
  20. typedef struct PartitionTupleRouting PartitionTupleRouting;
  21. extern PartitionTupleRouting *ExecSetupPartitionTupleRouting(EState *estate,
  22. Relation rel);
  23. extern ResultRelInfo *ExecFindPartition(ModifyTableState *mtstate,
  24. ResultRelInfo *rootResultRelInfo,
  25. PartitionTupleRouting *proute,
  26. TupleTableSlot *slot,
  27. EState *estate);
  28. extern void ExecCleanupTupleRouting(ModifyTableState *mtstate,
  29. PartitionTupleRouting *proute);
  30. /*
  31. * PartitionedRelPruningData - Per-partitioned-table data for run-time pruning
  32. * of partitions. For a multilevel partitioned table, we have one of these
  33. * for the topmost partition plus one for each non-leaf child partition.
  34. *
  35. * subplan_map[] and subpart_map[] have the same definitions as in
  36. * PartitionedRelPruneInfo (see plannodes.h); though note that here,
  37. * subpart_map contains indexes into PartitionPruningData.partrelprunedata[].
  38. *
  39. * nparts Length of subplan_map[] and subpart_map[].
  40. * subplan_map Subplan index by partition index, or -1.
  41. * subpart_map Subpart index by partition index, or -1.
  42. * present_parts A Bitmapset of the partition indexes that we
  43. * have subplans or subparts for.
  44. * initial_pruning_steps List of PartitionPruneSteps used to
  45. * perform executor startup pruning.
  46. * exec_pruning_steps List of PartitionPruneSteps used to
  47. * perform per-scan pruning.
  48. * initial_context If initial_pruning_steps isn't NIL, contains
  49. * the details needed to execute those steps.
  50. * exec_context If exec_pruning_steps isn't NIL, contains
  51. * the details needed to execute those steps.
  52. */
  53. typedef struct PartitionedRelPruningData
  54. {
  55. int nparts;
  56. int *subplan_map;
  57. int *subpart_map;
  58. Bitmapset *present_parts;
  59. List *initial_pruning_steps;
  60. List *exec_pruning_steps;
  61. PartitionPruneContext initial_context;
  62. PartitionPruneContext exec_context;
  63. } PartitionedRelPruningData;
  64. /*
  65. * PartitionPruningData - Holds all the run-time pruning information for
  66. * a single partitioning hierarchy containing one or more partitions.
  67. * partrelprunedata[] is an array ordered such that parents appear before
  68. * their children; in particular, the first entry is the topmost partition,
  69. * which was actually named in the SQL query.
  70. */
  71. typedef struct PartitionPruningData
  72. {
  73. int num_partrelprunedata; /* number of array entries */
  74. PartitionedRelPruningData partrelprunedata[FLEXIBLE_ARRAY_MEMBER];
  75. } PartitionPruningData;
  76. /*
  77. * PartitionPruneState - State object required for plan nodes to perform
  78. * run-time partition pruning.
  79. *
  80. * This struct can be attached to plan types which support arbitrary Lists of
  81. * subplans containing partitions, to allow subplans to be eliminated due to
  82. * the clauses being unable to match to any tuple that the subplan could
  83. * possibly produce.
  84. *
  85. * execparamids Contains paramids of PARAM_EXEC Params found within
  86. * any of the partprunedata structs. Pruning must be
  87. * done again each time the value of one of these
  88. * parameters changes.
  89. * other_subplans Contains indexes of subplans that don't belong to any
  90. * "partprunedata", e.g UNION ALL children that are not
  91. * partitioned tables, or a partitioned table that the
  92. * planner deemed run-time pruning to be useless for.
  93. * These must not be pruned.
  94. * prune_context A short-lived memory context in which to execute the
  95. * partition pruning functions.
  96. * do_initial_prune true if pruning should be performed during executor
  97. * startup (at any hierarchy level).
  98. * do_exec_prune true if pruning should be performed during
  99. * executor run (at any hierarchy level).
  100. * num_partprunedata Number of items in "partprunedata" array.
  101. * partprunedata Array of PartitionPruningData pointers for the plan's
  102. * partitioned relation(s), one for each partitioning
  103. * hierarchy that requires run-time pruning.
  104. */
  105. typedef struct PartitionPruneState
  106. {
  107. Bitmapset *execparamids;
  108. Bitmapset *other_subplans;
  109. MemoryContext prune_context;
  110. bool do_initial_prune;
  111. bool do_exec_prune;
  112. int num_partprunedata;
  113. PartitionPruningData *partprunedata[FLEXIBLE_ARRAY_MEMBER];
  114. } PartitionPruneState;
  115. extern PartitionPruneState *ExecInitPartitionPruning(PlanState *planstate,
  116. int n_total_subplans,
  117. PartitionPruneInfo *pruneinfo,
  118. Bitmapset **initially_valid_subplans);
  119. extern Bitmapset *ExecFindMatchingSubPlans(PartitionPruneState *prunestate,
  120. bool initial_prune);
  121. #endif /* EXECPARTITION_H */