forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitb4c6d31
committed
Fix serious performance problems in json(b) to_tsvector().
In an off-list followup to bug #14745, Bob Jones complained thatto_tsvector() on a 2MB jsonb value took an unreasonable amount oftime and space --- enough to draw the wrath of the OOM killer onhis machine. On my machine, his example proved to require upwardsof 18 seconds and 4GB, which seemed pretty bogus considering thatto_tsvector() on the same data treated as text took just a couplehundred msec and 10 or so MB.On investigation, the problem is that the implementation scans eachstring element of the json(b) and converts it to tsvector separately,then applies tsvector_concat() to join those separate tsvectors.The unreasonable memory usage came from leaking every single one ofthe transient tsvectors --- but even without that mistake, this is anO(N^2) or worse algorithm, because tsvector_concat() has to repeatedlyprocess the words coming from earlier elements.We can fix it by accumulating all the lexeme data and applyingmake_tsvector() just once. As a side benefit, that also makes thedesired adjustment of lexeme positions far cheaper, because we canjust tweak the running "pos" counter between JSON elements.In passing, try to make the explanation of that tweak more intelligible.(I didn't think that a barely-readable comment far removed from theactual code was helpful.) And do some minor other code beautification.1 parentfb9bd4b commitb4c6d31
2 files changed
+58
-71
lines changedLines changed: 58 additions & 62 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
28 | 28 |
| |
29 | 29 |
| |
30 | 30 |
| |
31 |
| - | |
32 | 31 |
| |
33 | 32 |
| |
34 | 33 |
| |
35 |
| - | |
| 34 | + | |
| 35 | + | |
36 | 36 |
| |
37 | 37 |
| |
38 | 38 |
| |
| |||
270 | 270 |
| |
271 | 271 |
| |
272 | 272 |
| |
| 273 | + | |
273 | 274 |
| |
274 |
| - | |
| 275 | + | |
275 | 276 |
| |
276 |
| - | |
277 |
| - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
278 | 280 |
| |
279 |
| - | |
280 | 281 |
| |
281 |
| - | |
| 282 | + | |
282 | 283 |
| |
283 |
| - | |
284 |
| - | |
285 |
| - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
286 | 287 |
| |
287 | 288 |
| |
288 |
| - | |
289 |
| - | |
| 289 | + | |
| 290 | + | |
290 | 291 |
| |
291 |
| - | |
292 |
| - | |
293 |
| - | |
294 |
| - | |
295 |
| - | |
296 |
| - | |
297 |
| - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
298 | 295 |
| |
299 | 296 |
| |
300 |
| - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
301 | 300 |
| |
302 | 301 |
| |
303 | 302 |
| |
| |||
317 | 316 |
| |
318 | 317 |
| |
319 | 318 |
| |
| 319 | + | |
320 | 320 |
| |
321 |
| - | |
| 321 | + | |
322 | 322 |
| |
323 |
| - | |
324 |
| - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
325 | 326 |
| |
326 |
| - | |
327 | 327 |
| |
328 |
| - | |
| 328 | + | |
329 | 329 |
| |
330 |
| - | |
331 |
| - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
332 | 333 |
| |
333 | 334 |
| |
334 |
| - | |
| 335 | + | |
335 | 336 |
| |
336 | 337 |
| |
337 |
| - | |
338 |
| - | |
339 |
| - | |
340 |
| - | |
341 |
| - | |
342 |
| - | |
343 |
| - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
344 | 341 |
| |
345 | 342 |
| |
346 |
| - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
347 | 346 |
| |
348 | 347 |
| |
349 | 348 |
| |
| |||
359 | 358 |
| |
360 | 359 |
| |
361 | 360 |
| |
362 |
| - | |
363 |
| - | |
| 361 | + | |
364 | 362 |
| |
365 | 363 |
| |
366 | 364 |
| |
367 | 365 |
| |
368 | 366 |
| |
369 | 367 |
| |
370 |
| - | |
371 |
| - | |
| 368 | + | |
372 | 369 |
| |
373 |
| - | |
374 |
| - | |
375 |
| - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
376 | 381 |
| |
377 |
| - | |
378 |
| - | |
379 |
| - | |
| 382 | + | |
380 | 383 |
| |
381 | 384 |
| |
382 | 385 |
| |
383 |
| - | |
384 |
| - | |
385 |
| - | |
386 |
| - | |
387 |
| - | |
388 |
| - | |
389 |
| - | |
390 |
| - | |
391 |
| - | |
392 |
| - | |
393 |
| - | |
394 |
| - | |
395 |
| - | |
396 |
| - | |
397 |
| - | |
398 |
| - | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
399 | 394 |
| |
400 | 395 |
| |
| 396 | + | |
401 | 397 |
| |
402 | 398 |
| |
403 | 399 |
| |
|
Lines changed: 0 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
86 | 86 |
| |
87 | 87 |
| |
88 | 88 |
| |
89 |
| - | |
90 |
| - | |
91 |
| - | |
92 |
| - | |
93 |
| - | |
94 |
| - | |
95 |
| - | |
96 |
| - | |
97 |
| - | |
98 | 89 |
| |
99 | 90 |
| |
100 | 91 |
| |
|
0 commit comments
Comments
(0)