forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit16828d5
committed
Fast ALTER TABLE ADD COLUMN with a non-NULL default
Currently adding a column to a table with a non-NULL default results ina rewrite of the table. For large tables this can be both expensive anddisruptive. This patch removes the need for the rewrite as long as thedefault value is not volatile. The default expression is evaluated atthe time of the ALTER TABLE and the result stored in a new column(attmissingval) in pg_attribute, and a new column (atthasmissing) is setto true. Any existing row when fetched will be supplied with theattmissingval. New rows will have the supplied value or the default andso will never need the attmissingval.Any time the table is rewritten all the atthasmissing and attmissingvalsettings for the attributes are cleared, as they are no longer needed.The most visible code change from this is in heap_attisnull, whichacquires a third TupleDesc argument, allowing it to detect a missingvalue if there is one. In many cases where it is known that there willnot be any (e.g. catalog relations) NULL can be passed for thisargument.Andrew Dunstan, heavily modified from an original patch from SergeRielau.Reviewed by Tom Lane, Andres Freund, Tomas Vondra and David Rowley.Discussion:https://postgr.es/m/31e2e921-7002-4c27-59f5-51f08404c858@2ndQuadrant.com1 parentef1978d commit16828d5
File tree
36 files changed
+1898
-244
lines changed- doc/src/sgml
- ref
- src
- backend
- access/common
- catalog
- commands
- executor
- optimizer/util
- rewrite
- statistics
- utils
- adt
- cache
- fmgr
- include
- access
- catalog
- test/regress
- expected
- sql
36 files changed
+1898
-244
lines changedLines changed: 27 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1149 | 1149 |
| |
1150 | 1150 |
| |
1151 | 1151 |
| |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
1152 | 1165 |
| |
1153 | 1166 |
| |
1154 | 1167 |
| |
| |||
1229 | 1242 |
| |
1230 | 1243 |
| |
1231 | 1244 |
| |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
1232 | 1259 |
| |
1233 | 1260 |
| |
1234 | 1261 |
| |
|
Lines changed: 17 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1184 | 1184 |
| |
1185 | 1185 |
| |
1186 | 1186 |
| |
1187 |
| - | |
1188 |
| - | |
1189 |
| - | |
1190 |
| - | |
1191 |
| - | |
1192 |
| - | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
1193 | 1193 |
| |
1194 | 1194 |
| |
1195 | 1195 |
| |
1196 |
| - | |
1197 |
| - | |
1198 |
| - | |
1199 |
| - | |
1200 |
| - | |
1201 |
| - | |
1202 |
| - | |
1203 |
| - | |
1204 |
| - | |
1205 |
| - | |
1206 |
| - | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
1207 | 1207 |
| |
1208 | 1208 |
| |
1209 | 1209 |
| |
|
0 commit comments
Comments
(0)