Skip to content

Commit 8491aa4

Browse files
committed
Add Parallel execution of Index Scan
1 parent 7448baa commit 8491aa4

File tree

15 files changed

+625
-111
lines changed

15 files changed

+625
-111
lines changed

contrib/pg_exchange/common.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include "postgres.h"
12+
#include "miscadmin.h"
1213

1314
#include "access/heapam.h"
1415
#include "access/htup_details.h"
@@ -24,3 +25,90 @@
2425

2526

2627
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+
}

contrib/pg_exchange/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define COMMON_H_
1717

1818
#include "nodes/pg_list.h"
19+
#include "nodes/plannodes.h"
1920
#include "storage/lock.h"
2021
#include "dmq.h"
2122

@@ -43,4 +44,6 @@ typedef struct
4344

4445
extern ExchangeSharedState *ExchShmem;
4546

47+
bool plan_tree_walker(Plan *plan, bool (*walker) (), void *context);
48+
4649
#endif /* COMMON_H_ */

0 commit comments

Comments
 (0)