Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 20AA59FA248 for ; Wed, 13 Dec 2006 08:24:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 50858-03 for ; Wed, 13 Dec 2006 08:23:49 -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 5551D9FA0FB for ; Wed, 13 Dec 2006 08:23:49 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by serveurmail01.codata.be (Postfix) with ESMTP id 049F0183877C; Wed, 13 Dec 2006 13:23:48 +0100 (CET) X-DSPAM-Result: Innocent X-DSPAM-Processed: Wed Dec 13 13:23:45 2006 X-DSPAM-Confidence: 0.6181 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 457ff0d110271748359437 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 TpYgaT-a3jyX; Wed, 13 Dec 2006 13:23:45 +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 D9B731838778; Wed, 13 Dec 2006 13:23:44 +0100 (CET) Message-ID: <457FF0CD.4050606@freesurf.fr> Date: Wed, 13 Dec 2006 13:23:41 +0100 From: Arnaud Lesauvage User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: Jens Schipkowski CC: pgsql-performance@postgresql.org Subject: Re: Slow update with simple query References: <457FDB1E.6040801@freesurf.fr> In-Reply-To: Content-Type: text/plain; charset=UTF-8; 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/317 X-Sequence-Number: 22373 Jens Schipkowski a écrit : > the problem is a combination of bad formed SQL and maybe missing indexes. > try this: > UPDATE t1 > SET booleanfield = foo.bar > FROM (SELECT uid,(field IN ('some','other') AND field2 = 'Y') AS bar FROM > t2) AS foo > WHERE t1.uid=foo.uid; Hi Jens, 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 ? > and index t1.uid, t2.uid, t2.field, t2.field2 t1.field can only take 3 or 4 values (don't remember exactly), and field2 only 2 ('Y' or 'N'). So this fields have a very low cardinality. Won't the planner chose to do a table scan in such a case ? Thanks for your advices ! -- Arnaud