Re: Incorrect cost for MergeAppend - Mailing list pgsql-hackers

From David Rowley
Subject Re: Incorrect cost for MergeAppend
Date
Msg-id CAApHDvpsDSR0ff6KkHuxmZWmM9V9kYHT_5AgRFwhoes=yeJiBA@mail.gmail.com
Whole thread Raw
In response to Re: Incorrect cost for MergeAppend  (Alexander Kuzmenkov <akuzmenkov@timescale.com>)
Responses Re: Incorrect cost for MergeAppend
List pgsql-hackers
On Wed, 31 Jan 2024 at 00:06, Alexander Kuzmenkov
<akuzmenkov@timescale.com> wrote:
> Here is a small patch that reproduces the problem on two tables with
> inheritance, and fixes it. I'll add it to the Commitfest.

Good catch.

It seems to have been broken since MergeAppends were added in 11cad29c9.

The code fix looks good to me.

The tests look a bit heavy.  I wondered if you could have used a UNION
ALL query with the tenk1 table so you didn't have to create tables,
however, I see that case works ok since the parent->tuples is set in
set_subquery_size_estimates() from "rel->tuples =
sub_final_rel->cheapest_total_path->rows;".

I played around with the following and see your patch changes the plan
to a Merge Append away from an Append -> Sort plan.

create table tenk_parent (like tenk1);
alter table tenk1 inherit tenk_parent;
alter table tenk2 inherit tenk_parent;
explain (costs off) select * from tenk_parent where thousand = 0 order
by tenthous;
alter table tenk1 no inherit tenk_parent;
alter table tenk2 no inherit tenk_parent;

I'm just not sure if we should be messing with tenk1 and tenk2 like that.

You should likely focus on trying to find a test that does not require
making 2 tables with 10k rows.

David



pgsql-hackers by date:

Previous
From: Aleksander Alekseev
Date:
Subject: Re: Incorrect cost for MergeAppend
Next
From: Alvaro Herrera
Date:
Subject: scram_iterations is undocumented GUC_REPORT