forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3c84046
committed
Fix assorted bugs in CREATE/DROP INDEX CONCURRENTLY.
Commit8cb5365, which introduced DROPINDEX CONCURRENTLY, managed to break CREATE INDEX CONCURRENTLY via a poorchoice of catalog state representation. The pg_index state for an indexthat's reached the final pre-drop stage was the same as the state for anindex just created by CREATE INDEX CONCURRENTLY. This meant that the(necessary) change to make RelationGetIndexList ignore about-to-die indexesalso made it ignore freshly-created indexes; which is catastrophic becausethe latter do need to be considered in HOT-safety decisions. Failure todo so leads to incorrect index entries and subsequently wrong results fromqueries depending on the concurrently-created index.To fix, add an additional boolean column "indislive" to pg_index, so thatthe freshly-created and about-to-die states can be distinguished. (Thischange obviously is only possible in HEAD. This patch will need to beback-patched, but in 9.2 we'll use a kluge consisting of overloading theformerly-impossible state of indisvalid = true and indisready = false.)In addition, change CREATE/DROP INDEX CONCURRENTLY so that the pg_indexflag changes they make without exclusive lock on the index are made viaheap_inplace_update() rather than a normal transactional update. Thelatter is not very safe because moving the pg_index tuple could result inconcurrent SnapshotNow scans finding it twice or not at all, thus possiblyresulting in index corruption. This is a pre-existing bug in CREATE INDEXCONCURRENTLY, which was copied into the DROP code.In addition, fix various places in the code that ought to check to makesure that the indexes they are manipulating are valid and/or ready asappropriate. These represent bugs that have existed since 8.2, sincea failed CREATE INDEX CONCURRENTLY could leave a corrupt or invalidindex behind, and we ought not try to do anything that might fail withsuch an index.Also fix RelationReloadIndexInfo to ensure it copies all the pg_indexcolumns that are allowed to change after initial creation. Previously wecould have been left with stale values of some fields in an index relcacheentry. It's not clear whether this actually had any user-visibleconsequences, but it's at least a bug waiting to happen.In addition, do some code and docs review for DROP INDEX CONCURRENTLY;some cosmetic code cleanup but mostly addition and revision of comments.This will need to be back-patched, but in a noticeably different form,so I'm committing it to HEAD before working on the back-patch.Problem reported by Amit Kapila, diagnosis by Pavan Deolassee,fix by Tom Lane and Andres Freund.1 parent1577b46 commit3c84046
File tree
17 files changed
+464
-265
lines changed- contrib/tcn
- doc/src/sgml
- ref
- src
- backend
- access/heap
- catalog
- commands
- executor
- optimizer/util
- parser
- utils/cache
- include/catalog
17 files changed
+464
-265
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
141 | 141 |
| |
142 | 142 |
| |
143 | 143 |
| |
144 |
| - | |
145 |
| - | |
| 144 | + | |
| 145 | + | |
146 | 146 |
| |
147 | 147 |
| |
148 | 148 |
| |
|
Lines changed: 11 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3480 | 3480 |
| |
3481 | 3481 |
| |
3482 | 3482 |
| |
3483 |
| - | |
| 3483 | + | |
3484 | 3484 |
| |
3485 | 3485 |
| |
3486 | 3486 |
| |
| |||
3507 | 3507 |
| |
3508 | 3508 |
| |
3509 | 3509 |
| |
| 3510 | + | |
| 3511 | + | |
| 3512 | + | |
| 3513 | + | |
| 3514 | + | |
| 3515 | + | |
| 3516 | + | |
| 3517 | + | |
| 3518 | + | |
| 3519 | + | |
3510 | 3520 |
| |
3511 | 3521 |
| |
3512 | 3522 |
| |
|
Lines changed: 18 additions & 19 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
40 | 40 |
| |
41 | 41 |
| |
42 | 42 |
| |
43 |
| - | |
| 43 | + | |
44 | 44 |
| |
45 | 45 |
| |
46 |
| - | |
47 |
| - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
48 | 60 |
| |
49 | 61 |
| |
50 | 62 |
| |
51 | 63 |
| |
52 | 64 |
| |
53 |
| - | |
| 65 | + | |
54 | 66 |
| |
55 | 67 |
| |
56 |
| - | |
57 |
| - | |
58 |
| - | |
59 |
| - | |
60 |
| - | |
61 |
| - | |
62 |
| - | |
63 |
| - | |
64 |
| - | |
65 |
| - | |
66 |
| - | |
67 |
| - | |
68 |
| - | |
69 |
| - | |
70 |
| - | |
| 68 | + | |
| 69 | + | |
71 | 70 |
| |
72 | 71 |
| |
73 | 72 |
| |
|
Lines changed: 28 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
386 | 386 |
| |
387 | 387 |
| |
388 | 388 |
| |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
389 | 417 |
| |
390 | 418 |
| |
391 | 419 |
| |
|
Lines changed: 20 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
995 | 995 |
| |
996 | 996 |
| |
997 | 997 |
| |
998 |
| - | |
999 | 998 |
| |
1000 | 999 |
| |
1001 | 1000 |
| |
| |||
1008 | 1007 |
| |
1009 | 1008 |
| |
1010 | 1009 |
| |
1011 |
| - | |
1012 |
| - | |
1013 |
| - | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
1014 | 1013 |
| |
1015 | 1014 |
| |
1016 | 1015 |
| |
1017 | 1016 |
| |
1018 | 1017 |
| |
1019 | 1018 |
| |
1020 | 1019 |
| |
1021 |
| - | |
1022 |
| - | |
1023 |
| - | |
1024 |
| - | |
1025 |
| - | |
1026 |
| - | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
1027 | 1025 |
| |
1028 | 1026 |
| |
1029 | 1027 |
| |
1030 | 1028 |
| |
1031 |
| - | |
| 1029 | + | |
1032 | 1030 |
| |
1033 | 1031 |
| |
1034 |
| - | |
| 1032 | + | |
1035 | 1033 |
| |
1036 | 1034 |
| |
1037 |
| - | |
1038 |
| - | |
| 1035 | + | |
| 1036 | + | |
1039 | 1037 |
| |
1040 | 1038 |
| |
1041 | 1039 |
| |
| |||
1258 | 1256 |
| |
1259 | 1257 |
| |
1260 | 1258 |
| |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
1261 | 1265 |
| |
1262 | 1266 |
| |
1263 | 1267 |
| |
1264 | 1268 |
| |
1265 | 1269 |
| |
1266 | 1270 |
| |
| 1271 | + | |
1267 | 1272 |
| |
1268 | 1273 |
| |
1269 | 1274 |
| |
| 1275 | + | |
1270 | 1276 |
| |
1271 | 1277 |
| |
1272 | 1278 |
| |
|
0 commit comments
Comments
(0)