forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9b10926
committed
Prevent O(N^2) unique index insertion edge case.
Commitdd299df made nbtree treat heap TID as a tiebreaker column,establishing the principle that there is only one correct location (pageand page offset number) for every index tuple, no matter what.Insertions of tuples into non-unique indexes proceed as if heap TID(scan key's scantid) is just another user-attribute value, butinsertions into unique indexes are more delicate. The TID value inscantid must initially be omitted to ensure that the unique indexinsertion visits every leaf page that duplicates could be on. Thescantid is set once again after unique checking finishes successfully,which can force _bt_findinsertloc() to step right one or more times, tolocate the leaf page that the new tuple must be inserted on.Stepping right within _bt_findinsertloc() was assumed to occur no morefrequently than stepping right within _bt_check_unique(), but there wasone important case where that assumption was incorrect: inserting a"duplicate" with NULL values. Since _bt_check_unique() didn't do anyreal work in this case, it wasn't appropriate for _bt_findinsertloc() tobehave as if it was finishing off a conventional unique insertion, whereany existing physical duplicate must be dead or recently dead._bt_findinsertloc() might have to grovel through a substantial portionof all of the leaf pages in the index to insert a single tuple, evenwhen there were no dead tuples.To fix, treat insertions of tuples with NULLs into a unique index as ifthey were insertions into a non-unique index: never unset scantid beforecalling _bt_search() to descend the tree, and bypass _bt_check_unique()entirely. _bt_check_unique() is no longer responsible for incomingtuples with NULL values.Discussion:https://postgr.es/m/CAH2-Wzm08nr+JPx4jMOa9CGqxWYDQ-_D4wtPBiKghXAUiUy-nQ@mail.gmail.com1 parentf4a3fdf commit9b10926
File tree
4 files changed
+56
-76
lines changed- src
- backend/access/nbtree
- include/access
4 files changed
+56
-76
lines changedLines changed: 41 additions & 76 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
55 | 55 |
| |
56 | 56 |
| |
57 | 57 |
| |
58 |
| - | |
59 |
| - | |
60 | 58 |
| |
61 | 59 |
| |
62 | 60 |
| |
| |||
91 | 89 |
| |
92 | 90 |
| |
93 | 91 |
| |
94 |
| - | |
95 |
| - | |
96 |
| - | |
| 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 | + | |
97 | 117 |
| |
98 | 118 |
| |
99 | 119 |
| |
| |||
209 | 229 |
| |
210 | 230 |
| |
211 | 231 |
| |
212 |
| - | |
| 232 | + | |
213 | 233 |
| |
214 | 234 |
| |
215 | 235 |
| |
| |||
266 | 286 |
| |
267 | 287 |
| |
268 | 288 |
| |
269 |
| - | |
270 |
| - | |
271 |
| - | |
272 |
| - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
273 | 292 |
| |
274 | 293 |
| |
275 | 294 |
| |
| |||
315 | 334 |
| |
316 | 335 |
| |
317 | 336 |
| |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
318 | 341 |
| |
319 | 342 |
| |
320 | 343 |
| |
321 | 344 |
| |
322 | 345 |
| |
323 | 346 |
| |
324 |
| - | |
325 | 347 |
| |
326 | 348 |
| |
327 | 349 |
| |
| |||
354 | 376 |
| |
355 | 377 |
| |
356 | 378 |
| |
| 379 | + | |
357 | 380 |
| |
358 | 381 |
| |
359 | 382 |
| |
| |||
375 | 398 |
| |
376 | 399 |
| |
377 | 400 |
| |
378 |
| - | |
379 |
| - | |
380 |
| - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
381 | 404 |
| |
382 | 405 |
| |
383 | 406 |
| |
384 | 407 |
| |
385 | 408 |
| |
386 | 409 |
| |
387 |
| - | |
| 410 | + | |
388 | 411 |
| |
389 | 412 |
| |
390 | 413 |
| |
| |||
394 | 417 |
| |
395 | 418 |
| |
396 | 419 |
| |
397 |
| - | |
| 420 | + | |
398 | 421 |
| |
399 |
| - | |
| 422 | + | |
400 | 423 |
| |
401 | 424 |
| |
402 | 425 |
| |
| |||
407 | 430 |
| |
408 | 431 |
| |
409 | 432 |
| |
410 |
| - | |
411 |
| - | |
412 |
| - | |
413 |
| - | |
414 |
| - | |
415 |
| - | |
416 |
| - | |
| 433 | + | |
417 | 434 |
| |
418 | 435 |
| |
419 | 436 |
| |
| |||
2184 | 2201 |
| |
2185 | 2202 |
| |
2186 | 2203 |
| |
2187 |
| - | |
2188 |
| - | |
2189 |
| - | |
2190 |
| - | |
2191 |
| - | |
2192 |
| - | |
2193 |
| - | |
2194 |
| - | |
2195 |
| - | |
2196 |
| - | |
2197 |
| - | |
2198 |
| - | |
2199 |
| - | |
2200 |
| - | |
2201 |
| - | |
2202 |
| - | |
2203 |
| - | |
2204 |
| - | |
2205 |
| - | |
2206 |
| - | |
2207 |
| - | |
2208 |
| - | |
2209 |
| - | |
2210 |
| - | |
2211 |
| - | |
2212 |
| - | |
2213 |
| - | |
2214 |
| - | |
2215 |
| - | |
2216 |
| - | |
2217 |
| - | |
2218 |
| - | |
2219 |
| - | |
2220 |
| - | |
2221 |
| - | |
2222 |
| - | |
2223 |
| - | |
2224 |
| - | |
2225 |
| - | |
2226 |
| - | |
2227 |
| - | |
2228 |
| - | |
2229 |
| - | |
2230 |
| - | |
2231 |
| - | |
2232 |
| - | |
2233 |
| - | |
2234 |
| - | |
2235 |
| - | |
2236 |
| - | |
2237 |
| - | |
2238 |
| - | |
2239 | 2204 |
| |
2240 | 2205 |
| |
2241 | 2206 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1235 | 1235 |
| |
1236 | 1236 |
| |
1237 | 1237 |
| |
| 1238 | + | |
1238 | 1239 |
| |
1239 | 1240 |
| |
1240 | 1241 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
107 | 107 |
| |
108 | 108 |
| |
109 | 109 |
| |
| 110 | + | |
110 | 111 |
| |
111 | 112 |
| |
112 | 113 |
| |
| |||
147 | 148 |
| |
148 | 149 |
| |
149 | 150 |
| |
| 151 | + | |
| 152 | + | |
| 153 | + | |
150 | 154 |
| |
151 | 155 |
| |
152 | 156 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
435 | 435 |
| |
436 | 436 |
| |
437 | 437 |
| |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
438 | 447 |
| |
439 | 448 |
| |
440 | 449 |
| |
| |||
461 | 470 |
| |
462 | 471 |
| |
463 | 472 |
| |
| 473 | + | |
464 | 474 |
| |
465 | 475 |
| |
466 | 476 |
| |
|
0 commit comments
Comments
(0)