Re: Incorrect cost for MergeAppend

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Alexander Kuzmenkov <akuzmenkov(at)timescale(dot)com>
Cc: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Incorrect cost for MergeAppend
Date: 2024-01-30 12:20:21
Message-ID: CAApHDvpsDSR0ff6KkHuxmZWmM9V9kYHT_5AgRFwhoes=yeJiBA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 31 Jan 2024 at 00:06, Alexander Kuzmenkov
<akuzmenkov(at)timescale(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2024-01-30 12:36:54 scram_iterations is undocumented GUC_REPORT
Previous Message Aleksander Alekseev 2024-01-30 12:18:44 Re: Incorrect cost for MergeAppend