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 0BDEFD8788 for ; Tue, 27 Sep 2005 07:57:57 -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 03215-05 for ; Tue, 27 Sep 2005 10:57:49 +0000 (GMT) Received: from sart.must-ipra.com (unknown [80.91.172.78]) by svr1.postgresql.org (Postfix) with ESMTP id 3D4F1D98D4 for ; Tue, 27 Sep 2005 07:57:50 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by sart.must-ipra.com (Postfix) with ESMTP id 6E8F03C162; Tue, 27 Sep 2005 13:55:13 +0300 (EEST) Received: from sart.must-ipra.com ([127.0.0.1]) by localhost (sart.must-ipra.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 12977-20; Tue, 27 Sep 2005 13:55:09 +0300 (EEST) Received: from PRG-45 (unknown [10.0.0.45]) by sart.must-ipra.com (Postfix) with ESMTP id 73F4C3C140; Tue, 27 Sep 2005 13:55:09 +0300 (EEST) Date: Tue, 27 Sep 2005 13:57:16 +0300 From: =?Windows-1251?Q?=C0=ED=E4=F0=E5=E9_=D0=E5=EF=EA=EE?= X-Mailer: The Bat! (v3.5.25) Professional Reply-To: =?Windows-1251?Q?=C0=ED=E4=F0=E5=E9_=D0=E5=EF=EA=EE?= Organization: =?Windows-1251?Q?=CE=CE=CE_=22=D1=C0=D0=D2=22?= X-Priority: 3 (Normal) Message-ID: <6110500029.20050927135716@sart.must-ipra.com> To: Richard Huxton Cc: pgsql-performance@postgresql.org Subject: Re: Index not used on group by In-Reply-To: <4339236F.7070403@archonet.com> References: <144520928.20050927121431@sart.must-ipra.com> <4339236F.7070403@archonet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=Windows-1251 Content-Transfer-Encoding: 8bit X-Virus-Scanned: amavisd-new at sart.must-ipra.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.02 required=5 tests=[AWL=0.020] X-Spam-Level: X-Archive-Number: 200509/371 X-Sequence-Number: 14679 Здравствуйте Richard, Tuesday, September 27, 2005, 1:48:15 PM, Вы писали: RH> Andrey Repko wrote: >> >> I have table ma_data, that contain above 300000 rows. >> This table has primary key id, and field alias_id. >> I create index (btree)on this field. >> Set statistic: >> >> ALTER TABLE "public"."ma_data" >> ALTER COLUMN "alias_id" SET STATISTICS 998; >> >> So, when I do something like >> SELECT alias_id FROM ma_data GROUP BY alias_id RH> Why are you using GROUP BY without any aggregate functions? RH> What happens if you use something like RH> SELECT DISTINCT alias_id FROM ma_data; sart_ma=# EXPLAIN ANALYZE SELECT DISTINCT alias_id FROM ma_data; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------- Unique (cost=65262.63..66770.75 rows=32 width=4) (actual time=16780.214..18250.761 rows=32 loops=1) -> Sort (cost=65262.63..66016.69 rows=301624 width=4) (actual time=16780.204..17255.129 rows=301624 loops=1) Sort Key: alias_id -> Seq Scan on ma_data (cost=0.00..37811.24 rows=301624 width=4) (actual time=6.896..15321.023 rows=301624 loops=1) Total runtime: 18292.542 ms (5 rows) sart_ma=# EXPLAIN ANALYZE SELECT alias_id FROM ma_data GROUP BY alias_id; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- HashAggregate (cost=38565.30..38565.62 rows=32 width=4) (actual time=15990.863..15990.933 rows=32 loops=1) -> Seq Scan on ma_data (cost=0.00..37811.24 rows=301624 width=4) (actual time=3.446..14572.141 rows=301624 loops=1) Total runtime: 15991.244 ms (3 rows) -- С наилучшими пожеланиями, Репко Андрей Владимирович mailto:repko@sart.must-ipra.com