From: Андрей Репко <repko@sart.must-ipra.com>
To: Richard Huxton <dev@archonet.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Index not used on group by
Date: Tue, 27 Sep 2005 13:57:16 +0300
Message-ID: <6110500029.20050927135716@sart.must-ipra.com> (raw)
In-Reply-To: <4339236F.7070403@archonet.com>
References: <144520928.20050927121431@sart.must-ipra.com>
<4339236F.7070403@archonet.com>
Здравствуйте 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: repko@sart.must-ipra.com, dev@archonet.com
Subject: Re: Index not used on group by
In-Reply-To: <6110500029.20050927135716@sart.must-ipra.com>
References: <144520928.20050927121431@sart.must-ipra.com> <4339236F.7070403@archonet.com> <6110500029.20050927135716@sart.must-ipra.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox