Re: update == delete + insert?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Craig A(dot) James" <cjames(at)modgraph-usa(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: update == delete + insert?
Date: 2006-03-20 23:22:45
Message-ID: 8909.1142896965@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Craig A. James" <cjames(at)modgraph-usa(dot)com> writes:
> I've seen it said here several times that "update == delete + insert". On the other hand, I've noticed that "alter table [add|drop] column ..." is remarkably fast, even for very large tables, which leads me to wonder whether each column's contents are in a file specifically for that column.

No. The reason "drop column" is fast is that we make no attempt to
remove the data from existing rows; we only mark the column's entry in
the system catalogs as deleted. "add column" is only fast if you are
adding a column with no default (a/k/a default NULL). In that case
likewise we don't have to modify existing rows; the desired behavior
falls out from the fact that the tuple access routines return NULL if
asked to fetch a column beyond those existing in a particular tuple.

You can read about the storage layout in
http://developer.postgresql.org/docs/postgres/storage.html

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message PFC 2006-03-20 23:27:04 Re: Best OS & Configuration for Dual Xeon w/4GB & Adaptec
Previous Message Miguel 2006-03-20 23:15:01 Re: Best OS & Configuration for Dual Xeon w/4GB & Adaptec