forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit511e902
committed
Make TRUNCATE ... RESTART IDENTITY restart sequences transactionally.
In the previous coding, we simply issued ALTER SEQUENCE RESTART commands,which do not roll back on error. This meant that an error betweentruncating and committing left the sequences out of sync with the tablecontents, with potentially bad consequences as were noted in a Warning onthe TRUNCATE man page.To fix, create a new storage file (relfilenode) for a sequence that is tobe reset due to RESTART IDENTITY. If the transaction aborts, we'llautomatically revert to the old storage file. This acts just like arewriting ALTER TABLE operation. A penalty is that we have to takeexclusive lock on the sequence, but since we've already got exclusive lockon its owning table, that seems unlikely to be much of a problem.The interaction of this with usual nontransactional behaviors of sequenceoperations is a bit weird, but it's hard to see what would be completelyconsistent. Our choice is to discard cached-but-unissued sequence valuesboth when the RESTART is executed, and at rollback if any; but to not touchthe currval() state either time.In passing, move the sequence reset operations to happen before not afterany AFTER TRUNCATE triggers are fired. The previous ordering was notlogically sensible, but was forced by the need to minimize inconsistencyif the triggers caused an error. Transactional rollback is a much bettersolution to that.Patch by Steve Singer, rather heavily adjusted by me.1 parentcfad144 commit511e902
File tree
7 files changed
+203
-102
lines changed- doc/src/sgml/ref
- src
- backend
- commands
- utils/cache
- include/commands
- test/regress
- expected
- sql
7 files changed
+203
-102
lines changedLines changed: 28 additions & 35 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
108 | 108 |
| |
109 | 109 |
| |
110 | 110 |
| |
111 |
| - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
112 | 114 |
| |
113 | 115 |
| |
114 | 116 |
| |
| |||
130 | 132 |
| |
131 | 133 |
| |
132 | 134 |
| |
133 |
| - | |
| 135 | + | |
| 136 | + | |
134 | 137 |
| |
135 | 138 |
| |
136 | 139 |
| |
| |||
159 | 162 |
| |
160 | 163 |
| |
161 | 164 |
| |
162 |
| - | |
163 |
| - | |
164 |
| - | |
165 |
| - | |
166 |
| - | |
167 |
| - | |
168 |
| - | |
169 |
| - | |
170 |
| - | |
171 |
| - | |
172 |
| - | |
173 |
| - | |
174 |
| - | |
175 |
| - | |
176 |
| - | |
177 |
| - | |
178 |
| - | |
179 |
| - | |
180 |
| - | |
181 |
| - | |
182 |
| - | |
183 |
| - | |
184 |
| - | |
185 |
| - | |
186 |
| - | |
187 |
| - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
188 | 180 |
| |
189 | 181 |
| |
190 | 182 |
| |
| |||
222 | 214 |
| |
223 | 215 |
| |
224 | 216 |
| |
225 |
| - | |
226 |
| - | |
227 |
| - | |
228 |
| - | |
229 |
| - | |
230 |
| - | |
231 |
| - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
232 | 225 |
| |
233 | 226 |
| |
234 | 227 |
|
Lines changed: 117 additions & 35 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
68 | 68 |
| |
69 | 69 |
| |
70 | 70 |
| |
| 71 | + | |
71 | 72 |
| |
72 | 73 |
| |
73 | 74 |
| |
| |||
87 | 88 |
| |
88 | 89 |
| |
89 | 90 |
| |
| 91 | + | |
90 | 92 |
| |
91 | 93 |
| |
92 | 94 |
| |
| |||
109 | 111 |
| |
110 | 112 |
| |
111 | 113 |
| |
112 |
| - | |
113 |
| - | |
114 |
| - | |
115 | 114 |
| |
116 | 115 |
| |
117 | 116 |
| |
| |||
211 | 210 |
| |
212 | 211 |
| |
213 | 212 |
| |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
214 | 307 |
| |
215 | 308 |
| |
216 | 309 |
| |
| |||
225 | 318 |
| |
226 | 319 |
| |
227 | 320 |
| |
228 |
| - | |
229 |
| - | |
| 321 | + | |
230 | 322 |
| |
231 | 323 |
| |
232 | 324 |
| |
| |||
306 | 398 |
| |
307 | 399 |
| |
308 | 400 |
| |
309 |
| - | |
310 |
| - | |
311 |
| - | |
312 |
| - | |
313 |
| - | |
314 |
| - | |
315 | 401 |
| |
316 | 402 |
| |
317 | 403 |
| |
| |||
323 | 409 |
| |
324 | 410 |
| |
325 | 411 |
| |
326 |
| - | |
327 |
| - | |
328 |
| - | |
329 |
| - | |
330 |
| - | |
331 |
| - | |
332 |
| - | |
333 |
| - | |
334 |
| - | |
335 |
| - | |
336 |
| - | |
337 |
| - | |
338 |
| - | |
339 |
| - | |
340 |
| - | |
341 |
| - | |
342 |
| - | |
343 |
| - | |
344 |
| - | |
345 |
| - | |
346 |
| - | |
347 |
| - | |
348 |
| - | |
349 | 412 |
| |
350 | 413 |
| |
351 | 414 |
| |
| |||
355 | 418 |
| |
356 | 419 |
| |
357 | 420 |
| |
| 421 | + | |
358 | 422 |
| |
359 | 423 |
| |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
360 | 429 |
| |
361 | 430 |
| |
362 | 431 |
| |
| |||
365 | 434 |
| |
366 | 435 |
| |
367 | 436 |
| |
368 |
| - | |
| 437 | + | |
369 | 438 |
| |
370 | 439 |
| |
371 | 440 |
| |
| |||
937 | 1006 |
| |
938 | 1007 |
| |
939 | 1008 |
| |
| 1009 | + | |
940 | 1010 |
| |
941 | 1011 |
| |
942 | 1012 |
| |
| |||
955 | 1025 |
| |
956 | 1026 |
| |
957 | 1027 |
| |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
958 | 1040 |
| |
959 | 1041 |
| |
960 | 1042 |
| |
|
Lines changed: 14 additions & 24 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
916 | 916 |
| |
917 | 917 |
| |
918 | 918 |
| |
919 |
| - | |
920 |
| - | |
921 |
| - | |
922 |
| - | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
923 | 922 |
| |
924 | 923 |
| |
925 | 924 |
| |
| |||
934 | 933 |
| |
935 | 934 |
| |
936 | 935 |
| |
937 |
| - | |
| 936 | + | |
938 | 937 |
| |
939 | 938 |
| |
940 | 939 |
| |
| |||
1043 | 1042 |
| |
1044 | 1043 |
| |
1045 | 1044 |
| |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
1046 | 1055 |
| |
1047 | 1056 |
| |
1048 | 1057 |
| |
| |||
1067 | 1076 |
| |
1068 | 1077 |
| |
1069 | 1078 |
| |
1070 |
| - | |
1071 |
| - | |
1072 |
| - | |
1073 |
| - | |
1074 |
| - | |
1075 |
| - | |
1076 |
| - | |
1077 |
| - | |
1078 |
| - | |
1079 |
| - | |
1080 |
| - | |
1081 |
| - | |
1082 |
| - | |
1083 |
| - | |
1084 |
| - | |
1085 |
| - | |
1086 |
| - | |
1087 |
| - | |
1088 |
| - | |
1089 | 1079 |
| |
1090 | 1080 |
| |
1091 | 1081 |
| |
|
0 commit comments
Comments
(0)