Re: partition table optimizer join cost misestimation

From: James Pang <jamespang886(at)gmail(dot)com>
To: Andrei Lepikhov <lepihov(at)gmail(dot)com>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: partition table optimizer join cost misestimation
Date: 2025-04-03 00:46:28
Message-ID: CAHgTRfdOsgSkHcgB+q-=M-+hb_jyyV1icwTSaCHFbby8C-CUxQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Andrei,
Yes, from explain output, since optimizer already get the merge_append
cost but not take account into total cost, that make a big difference. I
shared table DDLs and explain analyze,buffers output , I think the data
maybe generated by other way to reproduce this issue. sorry for not sharing
the commercial production data here.

Andrei Lepikhov <lepihov(at)gmail(dot)com> 於 2025年4月2日週三 下午7:03寫道:

> On 4/2/25 12:18, James Pang wrote:
> > Hi,
> > Postgresq v14.8, we found optimizer doest not take "merge append"
> > cost into sql plan total cost and then make a bad sql plan. attached
> > please find details.
> I suppose there is a different type of issue.
> MegeJoin sometimes doesn't need to scan the whole inner or outer side
> (see the MergeScanSelCache structure and how it is used in the cost
> estimation routine).
>
> So, the cost can be less because the optimizer predicted that only a
> small part of the Append will be scanned and used some sort of
> interpolation between startup cost and total cost.
>
> But to be sure, could you send the results of EXPLAIN ANALYZE VERBOSE?
> If you also send the data to reproduce the case, we may find the source
> of the problem more precisely.
>
> --
> regards, Andrei Lepikhov
>

Attachment Content-Type Size
table_and_explain_buffers.txt text/plain 32.1 KB

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Andrei Lepikhov 2025-04-03 06:32:44 Re: partition table optimizer join cost misestimation
Previous Message Andrei Lepikhov 2025-04-02 11:03:37 Re: partition table optimizer join cost misestimation