Re: BUG #17207: Bad cost estimate of Merge Join despite correct row estimate

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: sema(at)sema(dot)in
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17207: Bad cost estimate of Merge Join despite correct row estimate
Date: 2021-10-01 13:56:45
Message-ID: 3312647.1633096605@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> [ seriously awful mergejoin cost estimate ]

> While it is possible for Merge Join to also finish quickly - if user_id are
> all low numbers - I'm not sure if that's a realistic expectation for the
> default plan.

Yeah, it looks like it's incorrectly adjusting based on a belief that
it won't have to scan all of the join input.

I found that the problem only appears in v11 and later; earlier versions
come out with a more realistic estimate of the cost of the merge.
"git bisect" says it changed at

7d08ce286cd5854d58152e428c28636a616bdc42 is the first bad commit
commit 7d08ce286cd5854d58152e428c28636a616bdc42
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Date: Wed Sep 13 11:12:39 2017 -0400

Distinguish selectivity of < from <= and > from >=.

I've not yet figured out what the connection is, but a reasonable
bet is that there's an edge case associated with the ranges of the
two join keys being exactly the same. Anyway, I'll find it and
fix it. Thanks for the report!

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Devrim Gündüz 2021-10-01 13:58:31 Re: BUG #17209: The latest pgdg-redhat-repo-latest.noarch has incorrect path for pgdg14
Previous Message Magnus Hagander 2021-10-01 13:50:56 Re: BUG #17210: Postgres Let'sEncrypt root certificate is expired and breaks installation of postgres-client