X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 5993ED1B4FC for ; Sat, 11 Oct 2003 22:35:31 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 40412-09 for ; Sat, 11 Oct 2003 19:34:55 -0300 (ADT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 7B703D1B4F2 for ; Sat, 11 Oct 2003 19:34:44 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id DF3FB351EF; Sat, 11 Oct 2003 15:34:52 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id DD85C34D58; Sat, 11 Oct 2003 15:34:52 -0700 (PDT) Date: Sat, 11 Oct 2003 15:34:52 -0700 (PDT) From: Stephan Szabo To: David Griffiths Cc: pgsql-performance@postgresql.org Subject: Re: Another weird one with an UPDATE In-Reply-To: <05a401c3903f$a8524850$6501a8c0@griffiths2> Message-ID: <20031011153251.F57866@megazone.bigpanda.com> References: <052001c39030$1ccc8020$6501a8c0@griffiths2> <05a401c3903f$a8524850$6501a8c0@griffiths2> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/396 X-Sequence-Number: 4144 On Sat, 11 Oct 2003, David Griffiths wrote: > Sorry - just found the FAQ ( > http://jamesthornton.com/postgres/FAQ/faq-english.html#4.22 > ) on how > IN is very slow. > > So I rewrote the query: > > \o ./data/temp.txt > SELECT current_timestamp; > UPDATE user_account SET last_name = 'abc' > WHERE EXISTS (SELECT ua.user_account_id FROM user_account ua, > commercial_entity ce, commercial_service cs > WHERE ua.user_account_id = ce.user_account_id AND > ce.commercial_entity_id = cs.commercial_entity_id); > SELECT current_timestamp; I don't think that's the query you want. You're not binding the subselect to the outer values of user_account. I think you want something like: UPDATE user_account SET last_name = 'abc' WHERE EXISTS (SELECT 1 FROM commercial_entity ce, commercial_service cs WHERE user_account.user_account_id = ce.user_account_id AND ce.commercial_entity_id = cs.commercial_entity_id);