File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,34 @@ whether a rewrite will be triggered.
279
279
PS. Remember to drop the test event trigger
280
280
` drop event trigger log_rewrite_table ` .
281
281
282
+ ### Alter table "table_name" alter column "column_name" set/drop non null
283
+
284
+ Making a column nullable or non nullable needs ` AccessExclusiveLock ` . Changing
285
+ a column to nullable is simple. But changing a column to non nullable needs a
286
+ column scan. If one tuple is null at this column, then the change fails with a
287
+ message
288
+ [ column xxx of relation xxx contains null values] ( https://github.com/postgres/postgres/blob/3f9b9621766796983c37e192f73c5f8751872c18/src/backend/commands/tablecmds.c#L6326 ) .
289
+ The call stack is
290
+
291
+ ```
292
+ ATController
293
+ -> ATRewriteTables
294
+ -> ATRewriteTable
295
+
296
+ while (table_scan_getnextslot(scan, ForwardScanDirection, oldslot)) {
297
+ ...
298
+ if (slot_attisnull(insertslot, attn + 1))
299
+ }
300
+
301
+
302
+ ```
303
+
304
+ Note, the function is named ` ATRewriteTable ` , but it actually can either be
305
+ rewriting the table or scanning the table. Also, the code path does not trigger
306
+ ` table_rewrite ` event as the code path is
307
+ [ here] ( https://github.com/postgres/postgres/blob/3f9b9621766796983c37e192f73c5f8751872c18/src/backend/commands/tablecmds.c#L5931 ) .
308
+ It is not the branch and triggers the ` table_rewrite ` event.
309
+
282
310
## Index
283
311
284
312
### Processes and Memory
You can’t perform that action at this time.
0 commit comments