-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit 27af8b9
committed
Use SnapshotDirty when checking for conflicting index names.
While choosing an autogenerated name for an index, look for
pre-existing relations using a SnapshotDirty snapshot, instead of the
previous behavior that considered only committed-good pg_class rows.
This allows us to detect and avoid conflicts against indexes that are
still being built.
It's still possible to fail due to a race condition, but the window
is now just the amount of time that it takes DefineIndex to validate
all its parameters, call smgrcreate(), and enter the index's pg_class
row. Formerly the race window covered the entire time needed to
create and fill an index, which could be very long if the table is
large. Worse, if the conflicting index creation is part of a larger
transaction, it wouldn't be visible till COMMIT.
So this isn't a complete solution, but it should greatly ameliorate
the problem, and the patch is simple enough to be back-patchable.
It might at some point be useful to do the same for pg_constraint
entries (cf. ChooseConstraintName, ConstraintNameExists, and related
functions). However, in the absence of field complaints, I'll leave
that alone for now. The relation-name test should be good enough for
index-based constraints, while foreign-key constraints seem to be okay
since they require exclusive locks to create.
Bug: #18959
Reported-by: Maximilian Chrzan <maximilian.chrzan@here.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Discussion: https://postgr.es/m/18959-f63b53b864bb1417@postgresql.org
Backpatch-through: 131 parent 983b363 commit 27af8b9Copy full SHA for 27af8b9
File tree
Expand file treeCollapse file tree
1 file changed
+36
-2
lines changedFilter options
- src/backend/commands
Expand file treeCollapse file tree
1 file changed
+36
-2
lines changedsrc/backend/commands/indexcmds.c
Copy file name to clipboardExpand all lines: src/backend/commands/indexcmds.c+36-2Lines changed: 36 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2411 | 2411 |
| |
2412 | 2412 |
| |
2413 | 2413 |
| |
2414 |
| - | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
2415 | 2417 |
| |
2416 | 2418 |
| |
2417 | 2419 |
| |
| |||
2427 | 2429 |
| |
2428 | 2430 |
| |
2429 | 2431 |
| |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
2430 | 2438 |
| |
2431 | 2439 |
| |
2432 | 2440 |
| |
2433 | 2441 |
| |
2434 | 2442 |
| |
2435 | 2443 |
| |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
2436 | 2448 |
| |
2437 | 2449 |
| |
2438 |
| - | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
2439 | 2471 |
| |
2440 | 2472 |
| |
2441 | 2473 |
| |
| |||
2447 | 2479 |
| |
2448 | 2480 |
| |
2449 | 2481 |
| |
| 2482 | + | |
| 2483 | + | |
2450 | 2484 |
| |
2451 | 2485 |
| |
2452 | 2486 |
| |
|
0 commit comments