近期同事在讨论如何在PostgreSQL中一张大表,添加一个带有not null属性的,且具有缺省值的字段,并且要求在秒级完成。...因为此,有了以下的实验记录:
首先我们是在PostgreSQL 10下做的实验:
postgres=# select version();...建表,并查询表信息,插入数据:
postgres=# create table add_c_d_in_ms(id int, a1 text, a2 text, a3 text, a4 text, a5...: 36803.610 ms (00:36.804)
明显看到时间花费相当长,其实PostgreSQL在这里将数据完全重写了,主要原因就是就是添加的字段带有not null属性。..., null, null, null, wangshuo, null).