|
9 | 9 | */
|
10 | 10 |
|
11 | 11 | #include "postgres.h"
|
| 12 | +#include "miscadmin.h" |
12 | 13 |
|
13 | 14 | #include "access/heapam.h"
|
14 | 15 | #include "access/htup_details.h"
|
|
24 | 25 |
|
25 | 26 |
|
26 | 27 | ExchangeSharedState *ExchShmem = NULL;
|
| 28 | + |
| 29 | +static bool |
| 30 | +plan_walk_members(List *plans, bool (*walker) (), void *context) |
| 31 | +{ |
| 32 | + ListCell *lc; |
| 33 | + |
| 34 | + foreach (lc, plans) |
| 35 | + { |
| 36 | + Plan *plan = lfirst(lc); |
| 37 | + if (walker(plan, context)) |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + return false; |
| 42 | +} |
| 43 | + |
| 44 | +bool |
| 45 | +plan_tree_walker(Plan *plan, bool (*walker) (), void *context) |
| 46 | +{ |
| 47 | + ListCell *lc; |
| 48 | + |
| 49 | + /* Guard against stack overflow due to overly complex plan trees */ |
| 50 | + check_stack_depth(); |
| 51 | + |
| 52 | + /* initPlan-s */ |
| 53 | + if (plan_walk_members(plan->initPlan, walker, context)) |
| 54 | + return true; |
| 55 | + |
| 56 | + /* lefttree */ |
| 57 | + if (outerPlan(plan)) |
| 58 | + { |
| 59 | + if (walker(outerPlan(plan), context)) |
| 60 | + return true; |
| 61 | + } |
| 62 | + |
| 63 | + /* righttree */ |
| 64 | + if (innerPlan(plan)) |
| 65 | + { |
| 66 | + if (walker(innerPlan(plan), context)) |
| 67 | + return true; |
| 68 | + } |
| 69 | + |
| 70 | + /* special child plans */ |
| 71 | + switch (nodeTag(plan)) |
| 72 | + { |
| 73 | + case T_ModifyTable: |
| 74 | + if (plan_walk_members(((ModifyTable *) plan)->plans, |
| 75 | + walker, context)) |
| 76 | + return true; |
| 77 | + break; |
| 78 | + case T_Append: |
| 79 | + if (plan_walk_members(((Append *) plan)->appendplans, |
| 80 | + walker, context)) |
| 81 | + return true; |
| 82 | + break; |
| 83 | + case T_MergeAppend: |
| 84 | + if (plan_walk_members(((MergeAppend *) plan)->mergeplans, |
| 85 | + walker, context)) |
| 86 | + return true; |
| 87 | + break; |
| 88 | + case T_BitmapAnd: |
| 89 | + if (plan_walk_members(((BitmapAnd *) plan)->bitmapplans, |
| 90 | + walker, context)) |
| 91 | + return true; |
| 92 | + break; |
| 93 | + case T_BitmapOr: |
| 94 | + if (plan_walk_members(((BitmapOr *) plan)->bitmapplans, |
| 95 | + walker, context)) |
| 96 | + return true; |
| 97 | + break; |
| 98 | + case T_SubqueryScan: |
| 99 | + if (walker(((SubqueryScan *) plan)->subplan, context)) |
| 100 | + return true; |
| 101 | + break; |
| 102 | + case T_CustomScan: |
| 103 | + foreach(lc, ((CustomScan *) plan)->custom_plans) |
| 104 | + { |
| 105 | + if (walker((Plan *) lfirst(lc), context)) |
| 106 | + return true; |
| 107 | + } |
| 108 | + break; |
| 109 | + default: |
| 110 | + break; |
| 111 | + } |
| 112 | + |
| 113 | + return false; |
| 114 | +} |
0 commit comments