Re: [HACKERS] Linear vs. nonlinear planner cost estimates - Mailing list pgsql-hackers

From Robert Haas
Subject Re: [HACKERS] Linear vs. nonlinear planner cost estimates
Date
Msg-id CA+TgmoYBd7Vx1tMdCuhK9B7BTxHx6-_1x6QEohYkZxgVnWej4A@mail.gmail.com
Whole thread Raw
In response to [HACKERS] Linear vs. nonlinear planner cost estimates  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] Linear vs. nonlinear planner cost estimates
List pgsql-hackers
On Wed, Dec 14, 2016 at 2:12 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I don't have a concrete proposal right now about how to fix this.  The
> most expansive response would be to decorate every path with an explicitly
> nonlinear cost function, which would need to be able to report the cost
> to fetch the first N tuples rather than the total scan cost.  That would
> be a lot of work though.

And it would have some significant overhead, I bet.

> Maybe we could make this work just by setting the startup cost of an
> indexscan differently.  We could redefine "startup cost" as "cost to fetch
> the first tuple and then stop", and compute that independently of the
> total cost for plan types where it'd matter.  That would fix the problem
> for LIMIT 1 cases, and even for cases with a larger limit, scaling
> linearly from that to the total cost would produce a better estimate than
> what we get now.  But it feels like it's still a band-aid.

I think that would be a good place to start.  I bet it would help
materially, and it's a lot less work than anything more sophisticated.
There are plenty of cases (semi joins, and many nested loops that are
not semi joins) where the number of rows that we expect to fetch is 1
or very close to 1; LIMIT 100 or LIMIT 1000 happens, but it's a lot
less common.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] Creating a DSA area to provide work space for parallel execution
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Linear vs. nonlinear planner cost estimates