Re: row estimation off the mark when generate_series calls are involved - Mailing list pgsql-hackers

From Takahiro Itagaki
Subject Re: row estimation off the mark when generate_series calls are involved
Date
Msg-id 20100420095416.938D.52131E4D@oss.ntt.co.jp
Whole thread Raw
In response to row estimation off the mark when generate_series calls are involved  (Nikhil Sontakke <nikhil.sontakke@enterprisedb.com>)
Responses Re: row estimation off the mark when generate_series calls are involved  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Nikhil Sontakke <nikhil.sontakke@enterprisedb.com> wrote:

> I observed the following behavior on PG head:
> postgres=# explain verbose insert into public.x values (generate_series(1,10));
> ------------------------------------------------
> �Insert �(cost=0.00..0.01 rows=1 width=0)

Hmmm, there are differences between "SELECT SRF()" and "SELECT * FROM SRF()":

postgres=# EXPLAIN INSERT INTO public.x SELECT generate_series(1,10);                  QUERY PLAN
------------------------------------------------Insert  (cost=0.00..0.02 rows=1 width=4)  ->  Result  (cost=0.00..0.01
rows=1width=0) 

postgres=# EXPLAIN INSERT INTO public.x SELECT * FROM generate_series(1,10);                                 QUERY PLAN
------------------------------------------------------------------------------Insert  (cost=0.00..10.00 rows=1000
width=4) ->  Function Scan on generate_series  (cost=0.00..10.00 rows=1000 width=4) 


> I think the place where we set the
> targetlist of the result_plan to sub_tlist, immediately after that we
> should update the plan_rows estimate by walking this latest
> targetlist. I did that and now we seem to get proper row estimates.

I agree the estimation should be improved, but your patch *adds*
the estimated number of rows to the result:

postgres=# EXPLAIN INSERT INTO public.x SELECT generate_series(1,10);                   QUERY PLAN
---------------------------------------------------Insert  (cost=0.00..12.52 rows=1002 width=4)  ->  Result
(cost=0.00..2.51rows=1001 width=0) 

Should it be 1000 rather than 1001?

Regards,
---
Takahiro Itagaki
NTT Open Source Software Center




pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: unresolved bugs
Next
From: Robert Haas
Date:
Subject: Re: Streaming replication and a disk full in primary