Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id E1E819FB5EC for ; Mon, 9 Apr 2007 23:13:10 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 31945-07 for ; Mon, 9 Apr 2007 23:13:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 1DDEC9FB57C for ; Mon, 9 Apr 2007 23:13:08 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l3A2D5SG016375; Mon, 9 Apr 2007 22:13:05 -0400 (EDT) To: Drew Wilson cc: pgsql-performance@postgresql.org Subject: Re: how to efficiently update tuple in many-to-many relationship? In-reply-to: <22512E5C-A60F-43E7-A370-257F7AF956FD@gmail.com> References: <233A9987-ABA5-4491-A304-FDA1F8FCD962@gmail.com> <14019.1176155022@sss.pgh.pa.us> <22512E5C-A60F-43E7-A370-257F7AF956FD@gmail.com> Comments: In-reply-to Drew Wilson message dated "Mon, 09 Apr 2007 18:29:41 -0700" Date: Mon, 09 Apr 2007 22:13:05 -0400 Message-ID: <16374.1176171185@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/222 X-Sequence-Number: 24099 Drew Wilson writes: > Here's the query plan for a SELECT statement that returns 1,207,161 > rows in 6 seconds. > ... > And here's the query plan for the UPDATE query that seems to never > complete. (Execution time > 30 minutes.) Well, the subplan is certainly the same as before, so it seems there are two possibilities: * there's something unreasonably inefficient about the hash join being used to perform the IN (work_mem too small? inefficient-to-compare datatype? bad data distribution?) * the time is actually going into the UPDATE operation proper, or perhaps some triggers it fires (have you got any foreign keys involving this table? what's checkpoint_segments set to?) You could narrow it down by checking the runtime for select count(*) from translation_pair_data where translation_pair_id in (select translation_pair_id from translation_pair_data ... If that's slow it's the topmost hash join's fault, else we have to look at the UPDATE's side effects. regards, tom lane