Re: Index not used on group by

Поиск
Список
Период
Сортировка
От Андрей Репко
Тема Re: Index not used on group by
Дата
Msg-id 6110500029.20050927135716@sart.must-ipra.com
обсуждение исходный текст
Ответ на Re: Index not used on group by  (Richard Huxton <dev@archonet.com>)
Ответы Re: Index not used on group by
Список pgsql-performance
Здравствуйте 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


В списке pgsql-performance по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Index not used on group by
Следующее
От: Андрей Репко
Дата:
Сообщение: Re: Index not used on group by