Re: postgresql vs mysql - Mailing list pgsql-general

From Scott Marlowe
Subject Re: postgresql vs mysql
Date
Msg-id 1172075183.25338.126.camel@state.g2switchworks.com
Whole thread Raw
In response to Re: postgresql vs mysql  (Jack Orenstein <jorenstein@archivas.com>)
Responses Re: postgresql vs mysql  (Jim Nasby <decibel@decibel.org>)
How to force planner to use GiST index?  (araza@esri.com)
List pgsql-general
On Wed, 2007-02-21 at 10:12, Jack Orenstein wrote:
> Scott Marlowe wrote:
> > You can't change a table in any way without rewriting the whole thing,
> > resulting in a very long wait and a complete table lock on any alter
> > table action on big tables.  Don't forget that if you've got a really
> > big table, you need that much space free on the drive to alter the table
> > for the rewrite that's going to take place.
>
> Forgive a dumb question: What does postgresql do with ALTER TABLE?
> What sort of modifications do not require time proportional to the
> number of rows in the table?

It's an interesting subject, and it's not a dumb question.  In
PostgreSQL, indexes live in another file than the table.  In MySQL they
are part of the main table file with myisam tables.  I don't know what
innodb does in this regard.

The only thing I can think of that rewrites a whole postgresql table
would be reindexing it, or an update without a where clause (or a where
clause that includes every row).  Normal operations, like create index,
add column, drop column, etc do not need to rewrite the table and happen
almost instantly.

For instance, on a table with about 30 columns and 100,000 rows, I can
add a column this fast:

alter table brs add column a int;
ALTER TABLE
Time: 57.052 ms

alter table brs rename column b to c;
ALTER TABLE
Time: 33.281 ms

alter table brs drop column c;
ALTER TABLE
Time: 31.065 ms

Of course, mvcc (which both postgresql and innodb use) have other
issues, like doubling the table size if you update every row until the
dead tuples can be reclaimed.

pgsql-general by date:

Previous
From: Jack Orenstein
Date:
Subject: Re: postgresql vs mysql
Next
From: Lincoln Yeoh
Date:
Subject: Re: postgresql vs mysql