X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2408B9DC808 for ; Fri, 23 Dec 2005 11:30:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90164-02 for ; Fri, 23 Dec 2005 11:30:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5875A9DC805 for ; Fri, 23 Dec 2005 11:30:14 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jBNFU1JQ019922; Fri, 23 Dec 2005 10:30:01 -0500 (EST) To: Anton Maksimenkov cc: pgsql-performance@postgresql.org Subject: Re: DELETE, INSERT vs SELECT, UPDATE || INSERT In-reply-to: <287988431.20051223140205@hlebprom.ru> References: <287988431.20051223140205@hlebprom.ru> Comments: In-reply-to Anton Maksimenkov message dated "Fri, 23 Dec 2005 14:02:05 +0500" Date: Fri, 23 Dec 2005 10:30:00 -0500 Message-ID: <19921.1135351800@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.039 required=5 tests=[AWL=0.039] X-Spam-Score: 0.039 X-Spam-Level: X-Archive-Number: 200512/588 X-Sequence-Number: 16409 Anton Maksimenkov writes: > Second idea was to try to SELECT (user, cookie) pair and then UPDATE > it if it exists or INSERT if not. I has thought that if UPDATE will > rewrite same place in file with new count it may lead to more compact > table (file not grow and information about actual rows in file will > not changed). You're wasting your time, because Postgres doesn't work that way. UPDATE is really indistinguishable from DELETE+INSERT, and there will always be a dead row afterwards, because under MVCC rules both versions of the row have to be left in the table for some time after your transaction commits. See http://www.postgresql.org/docs/8.1/static/mvcc.html regards, tom lane