Re: Postgres Optimizer ignores information about foreign key relationship, severly misestimating number of returned rows in join

2020-10-26 Thread Tom Lane
David Rowley writes: > On Tue, 27 Oct 2020 at 06:54, Ehrenreich, Sigrid > wrote: >> -> Hash Join (cost=226.27..423.82 rows=115 width=0) (actual >> time=3.150..7.511 rows=3344 loops=1) <=== With the FK, the >> estimation should be 3344, but it is 115 rows > I'd have expected this t

Re: Postgres Optimizer ignores information about foreign key relationship, severly misestimating number of returned rows in join

2020-10-26 Thread David Rowley
On Tue, 27 Oct 2020 at 06:54, Ehrenreich, Sigrid wrote: > -> Hash Join (cost=226.27..423.82 rows=115 width=0) (actual > time=3.150..7.511 rows=3344 loops=1) <=== With the FK, the > estimation should be 3344, but it is 115 rows I'd have expected this to find the foreign key and hav

Re: Postgres Optimizer ignores information about foreign key relationship, severely misestimating number of returned rows in join

2020-10-26 Thread Justin Pryzby
On Mon, Oct 26, 2020 at 03:58:05PM +, Ehrenreich, Sigrid wrote: > Hi Performance Guys, > > I hope you can help me. I am joining two tables, that have a foreign key > relationship. So I expect the optimizer to estimate the number of the > resulting rows to be the same as the number of the ret

Re: Understanding bad estimate (related to FKs?)

2020-10-26 Thread Philip Semanchuk
> On Oct 26, 2020, at 1:20 PM, Michael Lewis wrote: > > On Mon, Oct 26, 2020 at 11:14 AM Philip Semanchuk > wrote: > >> The item I'm focused on is node 23. The estimate is for 7 rows, actual is > >> 896 (multiplied by 1062 loops). I'm confused about two things in this node. > >> > >> The f

Postgres Optimizer ignores information about foreign key relationship, severly misestimating number of returned rows in join

2020-10-26 Thread Ehrenreich, Sigrid
Hi Performance Guys, I hope you can help me. I am joining two tables, that have a foreign key relationship. So I expect the optimizer to estimate the number of the resulting rows to be the same as the number of the returned rows of one of the tables. But the estimate is way too low. I have bui

Re: Understanding bad estimate (related to FKs?)

2020-10-26 Thread Michael Lewis
On Mon, Oct 26, 2020 at 11:14 AM Philip Semanchuk < phi...@americanefficient.com> wrote: > >> The item I'm focused on is node 23. The estimate is for 7 rows, actual > is 896 (multiplied by 1062 loops). I'm confused about two things in this > node. > >> > >> The first is Postgres' estimate. The con

Re: Understanding bad estimate (related to FKs?)

2020-10-26 Thread Philip Semanchuk
> On Oct 26, 2020, at 1:04 PM, Justin Pryzby wrote: > > On Mon, Oct 26, 2020 at 12:50:38PM -0400, Philip Semanchuk wrote: >> I'm trying to understand a bad estimate by the planner, and what I can do >> about it. The anonymized plan is here: https://explain.depesz.com/s/0MDz > > What postgres

Re: Understanding bad estimate (related to FKs?)

2020-10-26 Thread Justin Pryzby
On Mon, Oct 26, 2020 at 12:50:38PM -0400, Philip Semanchuk wrote: > I'm trying to understand a bad estimate by the planner, and what I can do > about it. The anonymized plan is here: https://explain.depesz.com/s/0MDz What postgres version ? Since 9.6(?) FKs affect estimates. > The item I'm focus

Understanding bad estimate (related to FKs?)

2020-10-26 Thread Philip Semanchuk
I'm trying to understand a bad estimate by the planner, and what I can do about it. The anonymized plan is here: https://explain.depesz.com/s/0MDz The item I'm focused on is node 23. The estimate is for 7 rows, actual is 896 (multiplied by 1062 loops). I'm confused about two things in this node.