Commit 9aab83f
committed
Redesign get_attstatsslot()/free_attstatsslot() for more safety and speed.
The mess cleaned up in commit da07596 is clear evidence that it's a
bug hazard to expect the caller of get_attstatsslot()/free_attstatsslot()
to provide the correct type OID for the array elements in the slot.
Moreover, we weren't even getting any performance benefit from that,
since get_attstatsslot() was extracting the real type OID from the array
anyway. So we ought to get rid of that requirement; indeed, it would
make more sense for get_attstatsslot() to pass back the type OID it found,
in case the caller isn't sure what to expect, which is likely in binary-
compatible-operator cases.
Another problem with the current implementation is that if the stats array
element type is pass-by-reference, we incur a palloc/memcpy/pfree cycle
for each element. That seemed acceptable when the code was written because
we were targeting O(10) array sizes --- but these days, stats arrays are
almost always bigger than that, sometimes much bigger. We can save a
significant number of cycles by doing one palloc/memcpy/pfree of the whole
array. Indeed, in the now-probably-common case where the array is toasted,
that happens anyway so this method is basically free. (Note: although the
catcache code will inline any out-of-line toasted values, it doesn't
decompress them. At the other end of the size range, it doesn't expand
short-header datums either. In either case, DatumGetArrayTypeP would have
to make a copy. We do end up using an extra array copy step if the element
type is pass-by-value and the array length is neither small enough for a
short header nor large enough to have suffered compression. But that
seems like a very acceptable price for winning in pass-by-ref cases.)
Hence, redesign to take these insights into account. While at it,
convert to an API in which we fill a struct rather than passing a bunch
of pointers to individual output arguments. That will make it less
painful if we ever want further expansion of what get_attstatsslot can
pass back.
It's certainly arguable that this is new development and not something to
push post-feature-freeze. However, I view it as primarily bug-proofing
and therefore something that's better to have sooner not later. Since
we aren't quite at beta phase yet, let's put it in.
Discussion: https://postgr.es/m/16364.1494520862@sss.pgh.pa.us1 parent 1848b73 commit 9aab83f
File tree
10 files changed
+436
-601
lines changed- contrib/intarray
- src
- backend
- executor
- tsearch
- utils
- adt
- cache
- include/utils
10 files changed
+436
-601
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 139 | + | |
144 | 140 | | |
145 | 141 | | |
146 | 142 | | |
| |||
193 | 189 | | |
194 | 190 | | |
195 | 191 | | |
| 192 | + | |
| 193 | + | |
196 | 194 | | |
197 | 195 | | |
198 | 196 | | |
199 | 197 | | |
200 | 198 | | |
201 | 199 | | |
202 | 200 | | |
203 | | - | |
204 | | - | |
| 201 | + | |
205 | 202 | | |
206 | | - | |
207 | | - | |
208 | | - | |
| 203 | + | |
209 | 204 | | |
| 205 | + | |
| 206 | + | |
210 | 207 | | |
211 | 208 | | |
212 | 209 | | |
213 | 210 | | |
214 | 211 | | |
215 | | - | |
| 212 | + | |
216 | 213 | | |
217 | 214 | | |
218 | | - | |
| 215 | + | |
219 | 216 | | |
220 | | - | |
221 | | - | |
222 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
223 | 220 | | |
224 | 221 | | |
225 | 222 | | |
| 223 | + | |
| 224 | + | |
226 | 225 | | |
227 | 226 | | |
228 | 227 | | |
| |||
231 | 230 | | |
232 | 231 | | |
233 | 232 | | |
234 | | - | |
| 233 | + | |
235 | 234 | | |
236 | 235 | | |
237 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1283 | 1283 | | |
1284 | 1284 | | |
1285 | 1285 | | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
| 1286 | + | |
1290 | 1287 | | |
1291 | 1288 | | |
1292 | 1289 | | |
| |||
1305 | 1302 | | |
1306 | 1303 | | |
1307 | 1304 | | |
1308 | | - | |
| 1305 | + | |
1309 | 1306 | | |
1310 | | - | |
1311 | | - | |
1312 | | - | |
| 1307 | + | |
1313 | 1308 | | |
1314 | 1309 | | |
1315 | 1310 | | |
1316 | 1311 | | |
1317 | 1312 | | |
1318 | 1313 | | |
1319 | | - | |
1320 | | - | |
| 1314 | + | |
| 1315 | + | |
1321 | 1316 | | |
1322 | 1317 | | |
1323 | 1318 | | |
| |||
1326 | 1321 | | |
1327 | 1322 | | |
1328 | 1323 | | |
1329 | | - | |
| 1324 | + | |
1330 | 1325 | | |
1331 | 1326 | | |
1332 | | - | |
1333 | | - | |
| 1327 | + | |
1334 | 1328 | | |
1335 | 1329 | | |
1336 | 1330 | | |
| |||
1392 | 1386 | | |
1393 | 1387 | | |
1394 | 1388 | | |
1395 | | - | |
| 1389 | + | |
1396 | 1390 | | |
1397 | 1391 | | |
1398 | 1392 | | |
| |||
1426 | 1420 | | |
1427 | 1421 | | |
1428 | 1422 | | |
1429 | | - | |
1430 | | - | |
| 1423 | + | |
1431 | 1424 | | |
1432 | 1425 | | |
1433 | 1426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 166 | + | |
170 | 167 | | |
171 | 168 | | |
172 | 169 | | |
173 | 170 | | |
174 | | - | |
175 | | - | |
| 171 | + | |
176 | 172 | | |
177 | | - | |
178 | | - | |
179 | | - | |
| 173 | + | |
180 | 174 | | |
181 | 175 | | |
182 | 176 | | |
183 | 177 | | |
184 | 178 | | |
185 | | - | |
186 | | - | |
187 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
188 | 182 | | |
189 | 183 | | |
190 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 140 | + | |
| 141 | + | |
146 | 142 | | |
147 | 143 | | |
148 | 144 | | |
149 | 145 | | |
150 | | - | |
151 | | - | |
| 146 | + | |
152 | 147 | | |
153 | | - | |
154 | | - | |
155 | | - | |
| 148 | + | |
156 | 149 | | |
157 | 150 | | |
158 | 151 | | |
159 | | - | |
160 | | - | |
| 152 | + | |
161 | 153 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
| 154 | + | |
| 155 | + | |
169 | 156 | | |
170 | 157 | | |
171 | 158 | | |
172 | 159 | | |
173 | 160 | | |
174 | 161 | | |
175 | 162 | | |
176 | | - | |
177 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
178 | 167 | | |
179 | 168 | | |
180 | 169 | | |
181 | 170 | | |
182 | | - | |
183 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
184 | 175 | | |
185 | | - | |
| 176 | + | |
| 177 | + | |
186 | 178 | | |
187 | 179 | | |
188 | 180 | | |
189 | | - | |
190 | | - | |
191 | | - | |
| 181 | + | |
| 182 | + | |
192 | 183 | | |
193 | 184 | | |
194 | 185 | | |
| |||
369 | 360 | | |
370 | 361 | | |
371 | 362 | | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
| 363 | + | |
| 364 | + | |
378 | 365 | | |
379 | 366 | | |
380 | 367 | | |
381 | 368 | | |
382 | | - | |
383 | | - | |
| 369 | + | |
384 | 370 | | |
385 | | - | |
386 | | - | |
387 | | - | |
| 371 | + | |
388 | 372 | | |
389 | 373 | | |
390 | 374 | | |
391 | 375 | | |
392 | 376 | | |
393 | 377 | | |
394 | | - | |
395 | | - | |
| 378 | + | |
396 | 379 | | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
| 380 | + | |
| 381 | + | |
404 | 382 | | |
405 | 383 | | |
406 | 384 | | |
407 | | - | |
408 | | - | |
409 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
410 | 388 | | |
411 | 389 | | |
412 | | - | |
413 | | - | |
414 | | - | |
| 390 | + | |
| 391 | + | |
415 | 392 | | |
416 | 393 | | |
417 | 394 | | |
| |||
0 commit comments