Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 9B54F9FA3B1 for ; Wed, 13 Dec 2006 11:20:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 52639-01 for ; Wed, 13 Dec 2006 11:19:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from serveurmail01.codata.be (125.123.146.82.ipv4.evonet.be [82.146.123.125]) by postgresql.org (Postfix) with ESMTP id 8E9D79FA182 for ; Wed, 13 Dec 2006 11:19:59 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by serveurmail01.codata.be (Postfix) with ESMTP id 02F2A183877B; Wed, 13 Dec 2006 16:19:58 +0100 (CET) X-DSPAM-Result: Innocent X-DSPAM-Processed: Wed Dec 13 16:19:56 2006 X-DSPAM-Confidence: 0.6768 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 45801a1c37236642377823 X-DSPAM-Factors: 27, X-Virus-Scanned: amavisd-new at Received: from serveurmail01.codata.be ([127.0.0.1]) by localhost (serveurmail01.codata.be [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KuI182dW7Uql; Wed, 13 Dec 2006 16:19:56 +0100 (CET) Received: from [127.0.0.1] (38-179-112-217.fix.adsl.belcenter.be [217.112.179.38]) by serveurmail01.codata.be (Postfix) with ESMTP id 565501838777; Wed, 13 Dec 2006 16:19:56 +0100 (CET) Message-ID: <45801A1B.6070200@freesurf.fr> Date: Wed, 13 Dec 2006 16:19:55 +0100 From: Arnaud Lesauvage User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: Ragnar CC: Jens Schipkowski , pgsql-performance@postgresql.org Subject: Re: Slow update with simple query References: <457FDB1E.6040801@freesurf.fr> <457FF0CD.4050606@freesurf.fr> <4580025D.2040903@freesurf.fr> <1166021340.6369.103.camel@localhost.localdomain> In-Reply-To: <1166021340.6369.103.camel@localhost.localdomain> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 0657-2, 12/12/2006), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/321 X-Sequence-Number: 22377 Ragnar a écrit : > On mið, 2006-12-13 at 14:38 +0100, Arnaud Lesauvage wrote: >> Jens Schipkowski a écrit : >> > On Wed, 13 Dec 2006 13:23:41 +0100, Arnaud Lesauvage >> >> Why is this query better than the other one ? Because it runs the >> >> "(field IN ('some','other') AND field2 = 'Y')" once and then executes >> >> the join with the resulting set ? >> > True. The Subselect in FROM clause will be executed once and will be >> > joined using the condition at where clause. So your condition at t2 is not >> > executed for each row in t1(2mio records) but for each row in t2(1k >> > records). And the boolean value is already set during update. >> >> OK Jens, thanks for clarifying this. >> I thought the planner could guess what to do in such cases. > > don't worry, it will. > this is not your problem Indeed, the new query does not perform that well : "Hash Join (cost=112.75..307504.97 rows=2024869 width=355) (actual time=53.995..246443.811 rows=2020061 loops=1)" " Hash Cond: ("outer".uid = "inner".uid)" " -> Seq Scan on t1 (cost=0.00..261792.01 rows=2033001 width=338) (actual time=19.342..234304.499 rows=2033001 loops=1)" " -> Hash (cost=110.20..110.20 rows=1020 width=53) (actual time=4.853..4.853 rows=1020 loops=1)" " -> Seq Scan on t2 (cost=0.00..110.20 rows=1020 width=53) (actual time=0.017..2.586 rows=1020 loops=1)" "Total runtime: 2777844.892 ms" I removed all unnecessary indexes on t1 before running the query (I left the index on uid and the multicolumn index containind the updated field). I believe the multicolumn-functional-index computation is taking some time here, isn't it ? Regards -- Arnaud