X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8931E9DC98A for ; Wed, 11 Jan 2006 11:45:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00885-10 for ; Wed, 11 Jan 2006 11:45:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id AE5AB9DC9D6 for ; Wed, 11 Jan 2006 11:45:43 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0BFjlSC013029; Wed, 11 Jan 2006 10:45:47 -0500 (EST) To: Bendik Rognlien Johansen cc: pgsql-performance@postgresql.org Subject: Re: Slow query with joins In-reply-to: References: Comments: In-reply-to Bendik Rognlien Johansen message dated "Wed, 11 Jan 2006 11:59:39 +0100" Date: Wed, 11 Jan 2006 10:45:47 -0500 Message-ID: <13028.1136994347@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.083 required=5 tests=[AWL=0.083] X-Spam-Score: 0.083 X-Spam-Level: X-Archive-Number: 200601/114 X-Sequence-Number: 16592 Bendik Rognlien Johansen writes: > Has anyone got any tips for speeding up this query? It currently > takes hours to start. Are the rowcount estimates close to reality? The plan doesn't look unreasonable to me if they are. It might help to increase work_mem to ensure that the hash tables don't spill to disk. Indexes: "people_original_is_null" btree (original) WHERE original IS NULL This index seems poorly designed: the actual index entries are dead weight since all of them are necessarily NULL. You might as well make the index carry something that you frequently test in conjunction with "original IS NULL". For instance, if this particular query is a common case, you could replace this index with CREATE INDEX people_deleted_original_is_null ON people(deleted) WHERE original IS NULL; This index is still perfectly usable for queries that only say "original IS NULL", but it can also filter out rows with the wrong value of deleted. Now, if there are hardly any rows with deleted = true, maybe this won't help much for your problem. But in any case you ought to consider whether you can make the index entries do something useful. regards, tom lane