forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit94c014b
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, make the final state be indisvalid = true and indisready = false,which is otherwise nonsensical. This is pretty ugly but we can't addanother column without forcing initdb, and it's too late for that in 9.2.(There's a cleaner fix in HEAD.)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.Portions of this need to be back-patched even further, but I'll workon that separately.Problem reported by Amit Kapila, diagnosis by Pavan Deolasee,fix by Tom Lane and Andres Freund.1 parentffc3172 commit94c014b
File tree
16 files changed
+443
-258
lines changed- contrib/tcn
- doc/src/sgml
- ref
- src
- backend
- access/heap
- catalog
- commands
- executor
- optimizer/util
- parser
- utils/cache
- include/catalog
16 files changed
+443
-258
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
140 | 140 |
| |
141 | 141 |
| |
142 | 142 |
| |
143 |
| - | |
144 |
| - | |
| 143 | + | |
| 144 | + | |
145 | 145 |
| |
146 | 146 |
| |
147 | 147 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3389 | 3389 |
| |
3390 | 3390 |
| |
3391 | 3391 |
| |
3392 |
| - | |
| 3392 | + | |
| 3393 | + | |
3393 | 3394 |
| |
3394 | 3395 |
| |
3395 | 3396 |
| |
3396 |
| - | |
| 3397 | + | |
3397 | 3398 |
| |
3398 | 3399 |
| |
3399 | 3400 |
| |
|
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: 31 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 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
389 | 420 |
| |
390 | 421 |
| |
391 | 422 |
| |
|
Lines changed: 20 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
991 | 991 |
| |
992 | 992 |
| |
993 | 993 |
| |
994 |
| - | |
995 | 994 |
| |
996 | 995 |
| |
997 | 996 |
| |
| |||
1004 | 1003 |
| |
1005 | 1004 |
| |
1006 | 1005 |
| |
1007 |
| - | |
1008 |
| - | |
1009 |
| - | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
1010 | 1009 |
| |
1011 | 1010 |
| |
1012 | 1011 |
| |
1013 | 1012 |
| |
1014 | 1013 |
| |
1015 | 1014 |
| |
1016 | 1015 |
| |
1017 |
| - | |
1018 |
| - | |
1019 |
| - | |
1020 |
| - | |
1021 |
| - | |
1022 |
| - | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
1023 | 1021 |
| |
1024 | 1022 |
| |
1025 | 1023 |
| |
1026 | 1024 |
| |
1027 |
| - | |
| 1025 | + | |
1028 | 1026 |
| |
1029 | 1027 |
| |
1030 |
| - | |
| 1028 | + | |
1031 | 1029 |
| |
1032 | 1030 |
| |
1033 |
| - | |
1034 |
| - | |
| 1031 | + | |
| 1032 | + | |
1035 | 1033 |
| |
1036 | 1034 |
| |
1037 | 1035 |
| |
| |||
1250 | 1248 |
| |
1251 | 1249 |
| |
1252 | 1250 |
| |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
1253 | 1257 |
| |
1254 | 1258 |
| |
1255 | 1259 |
| |
1256 | 1260 |
| |
1257 | 1261 |
| |
1258 | 1262 |
| |
| 1263 | + | |
1259 | 1264 |
| |
1260 | 1265 |
| |
1261 | 1266 |
| |
| 1267 | + | |
1262 | 1268 |
| |
1263 | 1269 |
| |
1264 | 1270 |
| |
|
0 commit comments
Comments
(0)