X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4F999D98DB for ; Tue, 27 Sep 2005 09:45:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32169-02 for ; Tue, 27 Sep 2005 12:45:23 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 194A0D9916 for ; Tue, 27 Sep 2005 08:10:32 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 0614440DD67; Tue, 27 Sep 2005 12:10:28 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 19B7015F1D; Tue, 27 Sep 2005 12:08:37 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 12659-02; Tue, 27 Sep 2005 12:08:32 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 556C715F1C; Tue, 27 Sep 2005 12:08:32 +0100 (BST) Message-ID: <4339282F.1060900@archonet.com> Date: Tue, 27 Sep 2005 12:08:31 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?windows-1251?Q?=C0=ED=E4=F0=E5=E9_=D0=E5=EF=EA=EE?= Cc: pgsql-performance@postgresql.org Subject: Re: Index not used on group by References: <144520928.20050927121431@sart.must-ipra.com> <4339236F.7070403@archonet.com> <6110500029.20050927135716@sart.must-ipra.com> In-Reply-To: <6110500029.20050927135716@sart.must-ipra.com> Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.057 required=5 tests=[AWL=0.007, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200509/374 X-Sequence-Number: 14682 =C0=ED=E4=F0=E5=E9 =D0=E5=EF=EA=EE wrote: > RH> What happens if you use something like > RH> SELECT DISTINCT alias_id FROM ma_data; > sart_ma=3D# EXPLAIN ANALYZE SELECT DISTINCT alias_id FROM ma_data; > QUERY PLAN >=20 > -----------------------------------------------------------------------= -------------------------------------------------------- > Unique (cost=3D65262.63..66770.75 rows=3D32 width=3D4) (actual time=3D= 16780.214..18250.761 rows=3D32 loops=3D1) > -> Sort (cost=3D65262.63..66016.69 rows=3D301624 width=3D4) (actua= l time=3D16780.204..17255.129 rows=3D301624 loops=3D1) > Sort Key: alias_id > -> Seq Scan on ma_data (cost=3D0.00..37811.24 rows=3D301624 = width=3D4) (actual time=3D6.896..15321.023 rows=3D301624 loops=3D1) > Total runtime: 18292.542 ms > sart_ma=3D# EXPLAIN ANALYZE SELECT alias_id FROM ma_data GROUP BY alias= _id; > QUERY PLAN > -----------------------------------------------------------------------= -------------------------------------------------- > HashAggregate (cost=3D38565.30..38565.62 rows=3D32 width=3D4) (actual= time=3D15990.863..15990.933 rows=3D32 loops=3D1) > -> Seq Scan on ma_data (cost=3D0.00..37811.24 rows=3D301624 width=3D= 4) (actual time=3D3.446..14572.141 rows=3D301624 loops=3D1) > Total runtime: 15991.244 ms OK - the planner thinks it's doing the right thing, your cost estimates=20 are way off. If you look back at where you got an index-scan, it's cost=20 was 1.1 million. Index Scan using reference_9_fk on ma_data (cost=3D0.00..1139526.57 That's way above the numbers for seq-scan+hash/sort, so if the cost=20 estimate was right PG would be making the right choice. Looks like you=20 need to check your configuration settings. Have you read: http://www.powerpostgresql.com/PerfList or http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.html -- Richard Huxton Archonet Ltd