Received: from mx99.openu.ac.il (arbel.openu.ac.il [147.233.32.4]) by hub.org (8.9.3/8.9.3) with ESMTP id FAA34726 for ; Wed, 21 Jul 1999 05:52:05 -0400 (EDT) (envelope-from herouth@oumail.openu.ac.il) Received: from talmon.openu.ac.il (talmon.openu.ac.il [147.233.32.11]) by mx99.openu.ac.il (Postfix) with ESMTP for id 3CBA14B5A1; Wed, 21 Jul 1999 12:52:04 +0300 (IDT) Received: from [147.233.159.109] (mac-herouth.pc.openu.ac.il) by talmon.openu.ac.il (Netscape Messaging Server 3.54) with ESMTP id AAA87D; Wed, 21 Jul 1999 12:55:18 +0300 X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: <199907210228.TAA04635@uno.tksoft.com> References: <000001bed304$78193380$65dea8c0@gunni.gi.hf.is> from "Gunnar Ingvi Thorisson" at Jul 21, 99 00:06:15 am Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Wed, 21 Jul 1999 12:52:31 +0300 To: gunni@if.is From: Herouth Maoz Subject: Re: [SQL] Bad update performance? Cc: pgsql-sql@postgreSQL.org At 05:28 +0300 on 21/07/1999, tjk@tksoft.com wrote: > The table is stored in one chunk of a file, and when > postgres modifies it, it takes a long time because > it has to do a heck of a lot of seeking and modifying > in the file. This ends up being very time consuming. > > When you use a separate table for the field you are > isolating the field to its own file, which means > that when it's modified only a much smaller file > needs to be worked on. This will give a penalty in the selects, however. When you split a table into two, you have to have a relation between the field you separated and the original table, and from then on, you can see them together only using a join. A join takes more time than a search on one table. I think that update is slow, because it has to read each record, and write it in its new form in the end of the file. It does sequential scanning plus jump to the end of the file and writing. That's essentially what you said, too. In addition, it has to re-index each new entry. But in my opinion, the chance to make this faster is to select the new values into a new table, drop the old table, rename the new table, and add indices after that. If your table is called A: CREATE TABLE B ...; -- Same schema and constraints as A INSERT INTO B SELECT f1, f2, 'unknown', f4... FROM A; -- Note new value DROP TABLE A; ALTER TABLE B RENAME TO A; CREATE INDEX .....; -- Recreate the indices When defining the table, don't use SERIAL and PRIMARY KEY, as these create sequences and indices. You would do better to control these yourself, so as not to break the sequences used, and not to create an index before all values are inserted. One last comment: indices always accelerate retrieval, at the expense of slowing inserts and updates. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma