forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitfb9f955
Refactor ExecScan() to allow inlining of its core logic
This commit refactors ExecScan() by moving its tuple-fetching,filtering, and projection logic into an inline-able function,ExecScanExtended(), defined in src/include/executor/execScan.h.ExecScanExtended() accepts parameters for EvalPlanQual state,qualifiers (ExprState), and projection (ProjectionInfo).Specialized variants of the execution function of a given Scan node(for example, ExecSeqScan() for SeqScan) can then pass const-NULL forunused parameters. This allows the compiler to inline the logic andeliminate unnecessary branches or checks. Each variant function thuscontains only the necessary code, optimizing execution for scanswhere these features are not needed.The variant function to be used is determined in the ExecInit*()function of the node and assigned to the ExecProcNode function pointerin the node's PlanState, effectively turning runtime checks andconditional branches on the NULLness of epqstate, qual, and projInfointo static ones, provided the compiler successfully eliminatesunnecessary checks from the inlined code of ExecScanExtended().Currently, only ExecSeqScan() is modified to take advantage of thisinline-ability. Other Scan nodes might benefit from such specializedvariant functions but that is left as future work.Benchmarks performed by Junwang Zhao, David Rowley and myself show upto a 5% reduction in execution time for queries that rely heavily onSeq Scans. The most significant improvements were observed inscenarios where EvalPlanQual, qualifiers, and projection were notrequired, but other cases also benefit from reduced runtime overheaddue to the inlining and removal of unnecessary code paths.The idea for this patch first came from Andres Freund in an off-listdiscussion. The refactoring approach implemented here is based on aproposal by David Rowley, significantly improving upon the patch I(amitlan) initially proposed.Suggested-by: Andres Freund <andres@anarazel.de>Co-authored-by: David Rowley <dgrowleyml@gmail.com>Reviewed-by: David Rowley <dgrowleyml@gmail.com>Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>Tested-by: Junwang Zhao <zhjwpku@gmail.com>Tested-by: David Rowley <dgrowleyml@gmail.com>Discussion:https://postgr.es/m/CA+HiwqGaH-otvqW_ce-paL=96JvU4j+Xbuk+14esJNDwefdkOg@mail.gmail.com1 parent4feba03 commitfb9f955
File tree
3 files changed
+365
-203
lines changed- src
- backend/executor
- include/executor
3 files changed
+365
-203
lines changedLines changed: 9 additions & 198 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
| 22 | + | |
22 | 23 |
| |
23 | 24 |
| |
24 |
| - | |
25 |
| - | |
26 |
| - | |
27 |
| - | |
28 |
| - | |
29 |
| - | |
30 |
| - | |
31 |
| - | |
32 |
| - | |
33 |
| - | |
34 |
| - | |
35 |
| - | |
36 |
| - | |
37 |
| - | |
38 |
| - | |
39 |
| - | |
40 |
| - | |
41 |
| - | |
42 |
| - | |
43 |
| - | |
44 |
| - | |
45 |
| - | |
46 |
| - | |
47 |
| - | |
48 |
| - | |
49 |
| - | |
50 |
| - | |
51 |
| - | |
52 |
| - | |
53 |
| - | |
54 |
| - | |
55 |
| - | |
56 |
| - | |
57 |
| - | |
58 |
| - | |
59 |
| - | |
60 |
| - | |
61 |
| - | |
62 |
| - | |
63 |
| - | |
64 |
| - | |
65 |
| - | |
66 |
| - | |
67 |
| - | |
68 |
| - | |
69 |
| - | |
70 |
| - | |
71 |
| - | |
72 |
| - | |
73 |
| - | |
74 |
| - | |
75 |
| - | |
76 |
| - | |
77 |
| - | |
78 |
| - | |
79 |
| - | |
80 |
| - | |
81 |
| - | |
82 |
| - | |
83 |
| - | |
84 |
| - | |
85 |
| - | |
86 |
| - | |
87 |
| - | |
88 |
| - | |
89 |
| - | |
90 |
| - | |
91 |
| - | |
92 |
| - | |
93 |
| - | |
94 |
| - | |
95 |
| - | |
96 |
| - | |
97 |
| - | |
98 |
| - | |
99 |
| - | |
100 |
| - | |
101 |
| - | |
102 |
| - | |
103 |
| - | |
104 |
| - | |
105 |
| - | |
106 |
| - | |
107 |
| - | |
108 |
| - | |
109 |
| - | |
110 |
| - | |
111 |
| - | |
112 |
| - | |
113 |
| - | |
114 |
| - | |
115 |
| - | |
116 |
| - | |
117 |
| - | |
118 |
| - | |
119 |
| - | |
120 |
| - | |
121 |
| - | |
122 |
| - | |
123 |
| - | |
124 |
| - | |
125 |
| - | |
126 |
| - | |
127 |
| - | |
128 |
| - | |
129 |
| - | |
130 |
| - | |
131 |
| - | |
132 |
| - | |
133 |
| - | |
134 | 25 |
| |
135 | 26 |
| |
136 | 27 |
| |
| |||
157 | 48 |
| |
158 | 49 |
| |
159 | 50 |
| |
160 |
| - | |
| 51 | + | |
161 | 52 |
| |
162 | 53 |
| |
163 | 54 |
| |
164 |
| - | |
165 |
| - | |
166 |
| - | |
| 55 | + | |
167 | 56 |
| |
168 | 57 |
| |
169 |
| - | |
170 |
| - | |
171 |
| - | |
172 |
| - | |
173 |
| - | |
174 |
| - | |
175 |
| - | |
176 |
| - | |
177 |
| - | |
178 |
| - | |
179 |
| - | |
180 |
| - | |
181 |
| - | |
182 |
| - | |
183 |
| - | |
184 |
| - | |
185 |
| - | |
186 |
| - | |
187 |
| - | |
188 |
| - | |
189 |
| - | |
190 |
| - | |
191 |
| - | |
192 |
| - | |
193 |
| - | |
194 |
| - | |
195 |
| - | |
196 | 58 |
| |
197 |
| - | |
198 |
| - | |
199 |
| - | |
200 |
| - | |
201 |
| - | |
202 |
| - | |
203 |
| - | |
204 |
| - | |
205 |
| - | |
206 |
| - | |
207 |
| - | |
208 |
| - | |
209 |
| - | |
210 |
| - | |
211 |
| - | |
212 |
| - | |
213 |
| - | |
214 |
| - | |
215 |
| - | |
216 |
| - | |
217 |
| - | |
218 |
| - | |
219 |
| - | |
220 |
| - | |
221 |
| - | |
222 |
| - | |
223 |
| - | |
224 |
| - | |
225 |
| - | |
226 |
| - | |
227 |
| - | |
228 |
| - | |
229 |
| - | |
230 |
| - | |
231 |
| - | |
232 |
| - | |
233 |
| - | |
234 |
| - | |
235 |
| - | |
236 |
| - | |
237 |
| - | |
238 |
| - | |
239 |
| - | |
240 |
| - | |
241 |
| - | |
242 |
| - | |
243 |
| - | |
244 |
| - | |
245 |
| - | |
246 |
| - | |
247 |
| - | |
248 |
| - | |
249 |
| - | |
250 |
| - | |
251 |
| - | |
252 |
| - | |
253 |
| - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
254 | 65 |
| |
255 | 66 |
| |
256 | 67 |
| |
|
Lines changed: 110 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
29 | 29 |
| |
30 | 30 |
| |
31 | 31 |
| |
| 32 | + | |
32 | 33 |
| |
33 | 34 |
| |
34 | 35 |
| |
| |||
99 | 100 |
| |
100 | 101 |
| |
101 | 102 |
| |
102 |
| - | |
103 |
| - | |
104 |
| - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
105 | 107 |
| |
106 | 108 |
| |
107 | 109 |
| |
108 | 110 |
| |
109 | 111 |
| |
110 | 112 |
| |
111 | 113 |
| |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
112 | 197 |
| |
113 | 198 |
| |
114 | 199 |
| |
115 | 200 |
| |
116 | 201 |
| |
117 |
| - | |
118 | 202 |
| |
119 | 203 |
| |
120 | 204 |
| |
| |||
137 | 221 |
| |
138 | 222 |
| |
139 | 223 |
| |
140 |
| - | |
141 | 224 |
| |
142 | 225 |
| |
143 | 226 |
| |
| |||
171 | 254 |
| |
172 | 255 |
| |
173 | 256 |
| |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
174 | 279 |
| |
175 | 280 |
| |
176 | 281 |
| |
|
0 commit comments
Comments
(0)