X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4A8214761BB for ; Sat, 1 Feb 2003 07:39:13 -0500 (EST) Received: from jobs1.unisoftbg.com (unknown [194.12.229.208]) by postgresql.org (Postfix) with SMTP id 41CBE475EBB for ; Sat, 1 Feb 2003 07:38:32 -0500 (EST) Received: (qmail 18682 invoked from network); 1 Feb 2003 14:15:13 -0000 Received: from unisoft.unisoftbg.com (HELO t1.unisoftbg.com) (194.12.229.193) by 0 with SMTP; 1 Feb 2003 14:15:13 -0000 Message-ID: <3E3BB210.5C51478C@t1.unisoftbg.com> Date: Sat, 01 Feb 2003 12:40:00 +0100 From: pginfo X-Mailer: Mozilla 4.03 [en] (Win95; I) MIME-Version: 1.0 To: "pgsql-sql@postgresql.org" Subject: update and IN vs. EXISTS Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/5 X-Sequence-Number: 11403 Hi, I have 2 tables Table1 and Table2. The PK for Table1 is declared as name. Table 2 have only 1 field and it is also name ( it is indexed). I will to update all Table1.filedForUpdate for all rows that exists in Table2. In Table1 I have ~ 120 000 rows and in Table2 I have ~ 100 000. If I execute: update Table1 set fieldForUpdate = 1; it takes ~ 28 sec. I test it only to know how much time will I need for all rows. If I try to execute: update Table1 set fieldForUpdate = 1 where ID IN (select T2.ID from Table2); it is running very slow. I do not nkow how many time, but I waited ~ 30 min without to get result. I tested anoder query: update Table1 set fieldForUpdate = 1 where ID IN ( select T1.ID from Table1 T1 where exists (select * select T2.ID from Table2 where T1.IDS=T2.IDS )); and it was running > 30 min ( I do not know how many). And the last query: update Table1 set fieldForUpdate = 1 from Tablet T1 where EXISTS (select * select T2.ID from Table2 where T1.IDS=T2.IDS ); and it was also > 30 min. How can I speed up this update? I have executed vacuum and vacuum full analyze. redards, ivan.