Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 020EE6352CA for ; Fri, 20 Mar 2009 06:21:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 00544-03 for ; Fri, 20 Mar 2009 06:21:23 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from relay.ptn-ipout01.plus.net (relay.ptn-ipout01.plus.net [212.159.7.35]) by mail.postgresql.org (Postfix) with ESMTP id D268C63516C for ; Fri, 20 Mar 2009 06:21:22 -0300 (ADT) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEANz8wknUnw4R/2dsb2JhbADTdYN9BmE Received: from pih-relay04.plus.net ([212.159.14.17]) by relay.ptn-ipout01.plus.net with ESMTP; 20 Mar 2009 09:21:19 +0000 Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay04.plus.net with esmtp (Exim) id 1Lkauk-0003sT-Qq; Fri, 20 Mar 2009 09:21:19 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 74BA2274050; Fri, 20 Mar 2009 09:21:18 +0000 (GMT) Message-ID: <49C3600E.20504@archonet.com> Date: Fri, 20 Mar 2009 09:21:18 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: Anne Rosset CC: pgsql-performance@postgresql.org Subject: Re: Need help with one query References: <49C2AC75.5060601@collab.net> In-Reply-To: <49C2AC75.5060601@collab.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 015e023af55fa75e9fc098ea868a238c X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200903/285 X-Sequence-Number: 33207 Anne Rosset wrote: > EXPLAIN ANALYZE > SELECT > audit_change.id AS id, > audit_change.audit_entry_id AS auditEntryId, > audit_entry.object_id AS objectId, > audit_change.property_name AS propertyName, > audit_change.property_type AS propertyType, > audit_change.old_value AS oldValue, > audit_change.new_value AS newValue, > audit_change.flexfield AS flexField > FROM > audit_entry audit_entry, audit_change audit_change > WHERE > audit_change.audit_entry_id = audit_entry.id > AND audit_entry.object_id = 'artf414029'; [query reformatted to make it more readable] Not quite clear why you are aliasing the tables to their own names... > --------------------------------------------------------------------------------------------------------------------------------------------- > > Hash Join (cost=8.79..253664.55 rows=4 width=136) (actual > time=4612.674..6683.158 rows=4 loops=1) > Hash Cond: ((audit_change.audit_entry_id)::text = (audit_entry.id)::text) > -> Seq Scan on audit_change (cost=0.00..225212.52 rows=7584852 > width=123) (actual time=0.009..2838.216 rows=7584852 loops=1) > -> Hash (cost=8.75..8.75 rows=3 width=45) (actual time=0.049..0.049 > rows=4 loops=1) > -> Index Scan using audit_entry_object on audit_entry > (cost=0.00..8.75 rows=3 width=45) (actual time=0.033..0.042 rows=4 loops=1) > Index Cond: ((object_id)::text = 'artf414029'::text) > Total runtime: 6683.220 ms Very odd. It knows the table is large and that the seq-scan is going to be expensive. Try issuing "set enable_seqscan = off" and run the explain analyse again. That should show the cost of using the indexes. -- Richard Huxton Archonet Ltd