* ExecFindInitialMatchingSubPlans * Identify the set of subplans that cannot be eliminated by initial * pruning, disregarding any pruning constraints involving PARAM_EXEC * Params. * * If additional pruning passes will be required (because of PARAM_EXEC * Params), we must also update the translation data that allows conversion * of partition indexes into subplan indexes to account for th
| 2054 | * 'nsubplans' must be passed as the total number of unpruned subplans. |
| 2055 | */ |
| 2056 | Bitmapset * |
| 2057 | ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate, int nsubplans) |
| 2058 | { |
| 2059 | Bitmapset *result = NULL; |
| 2060 | MemoryContext oldcontext; |
| 2061 | int i; |
| 2062 | |
| 2063 | /* Caller error if we get here without do_initial_prune */ |
| 2064 | Assert(prunestate->do_initial_prune); |
| 2065 | |
| 2066 | /* |
| 2067 | * Switch to a temp context to avoid leaking memory in the executor's |
| 2068 | * query-lifespan memory context. |
| 2069 | */ |
| 2070 | oldcontext = MemoryContextSwitchTo(prunestate->prune_context); |
| 2071 | |
| 2072 | /* |
| 2073 | * For each hierarchy, do the pruning tests, and add nondeletable |
| 2074 | * subplans' indexes to "result". |
| 2075 | */ |
| 2076 | for (i = 0; i < prunestate->num_partprunedata; i++) |
| 2077 | { |
| 2078 | PartitionPruningData *prunedata; |
| 2079 | PartitionedRelPruningData *pprune; |
| 2080 | |
| 2081 | prunedata = prunestate->partprunedata[i]; |
| 2082 | pprune = &prunedata->partrelprunedata[0]; |
| 2083 | |
| 2084 | /* Perform pruning without using PARAM_EXEC Params */ |
| 2085 | find_matching_subplans_recurse(prunedata, pprune, true, &result); |
| 2086 | |
| 2087 | /* Expression eval may have used space in node's ps_ExprContext too */ |
| 2088 | if (pprune->initial_pruning_steps) |
| 2089 | ResetExprContext(pprune->initial_context.planstate->ps_ExprContext); |
| 2090 | } |
| 2091 | |
| 2092 | /* Add in any subplans that partition pruning didn't account for */ |
| 2093 | result = bms_add_members(result, prunestate->other_subplans); |
| 2094 | |
| 2095 | MemoryContextSwitchTo(oldcontext); |
| 2096 | |
| 2097 | /* Copy result out of the temp context before we reset it */ |
| 2098 | result = bms_copy(result); |
| 2099 | |
| 2100 | MemoryContextReset(prunestate->prune_context); |
| 2101 | |
| 2102 | /* |
| 2103 | * If exec-time pruning is required and we pruned subplans above, then we |
| 2104 | * must re-sequence the subplan indexes so that ExecFindMatchingSubPlans |
| 2105 | * properly returns the indexes from the subplans which will remain after |
| 2106 | * execution of this function. |
| 2107 | * |
| 2108 | * We can safely skip this when !do_exec_prune, even though that leaves |
| 2109 | * invalid data in prunestate, because that data won't be consulted again |
| 2110 | * (cf initial Assert in ExecFindMatchingSubPlans). |
| 2111 | */ |
| 2112 | if (prunestate->do_exec_prune && bms_num_members(result) < nsubplans) |
| 2113 | { |
no test coverage detected