Обсуждение: how does the planer to estimate row when i use order by and group by

Поиск
Список
Период
Сортировка

how does the planer to estimate row when i use order by and group by

От
楊新波
Дата:
hi ,everybody

why does the planer estimate 200 rows when i use order by and group by .
evn:postgresql 8.4 and 9.3

table:
CREATE TABLE a
(
  id serial NOT NULL,
  name character varying(20),
  modifytime timestamp without time zone,
  CONSTRAINT a_pk PRIMARY KEY (id)
)

SQL:
explain  analyze
select * from 
( select id from a order by id ) d 
group by  id;

Query plan:
"Group  (cost=0.15..66.42 rows=200 width=4) (actual time=0.008..0.008 rows=0 loops=1)"
"  ->  Index Only Scan using a_pk on a  (cost=0.15..56.30 rows=810 width=4) (actual time=0.006..0.006 rows=0 loops=1)"
"        Heap Fetches: 0"
"Total runtime: 0.046 ms"

Can anybody suggest something or explain this behavior?

Re: how does the planer to estimate row when i use order by and group by

От
Marti Raudsepp
Дата:
On Tue, Aug 12, 2014 at 5:59 AM, 楊新波 <silent0608@gmail.com> wrote:
> why does the planer estimate 200 rows when i use order by and group by .
> evn:postgresql 8.4 and 9.3

> Can anybody suggest something or explain this behavior?

Because the table is empty, analyze doesn't store any stats for the
table, so the planner uses some default guesses.

This is actually beneficial for cases where you have done some inserts
to a new table, and autovacuum hasn't gotten around to analyzing it
yet. And it rarely hurts because any query plan will be fast when
there's no data.

Regards,
Marti