Re: assertion failure with unique index + partitioning + join

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Alexander Kuzmenkov <akuzmenkov(at)tigerdata(dot)com>, Richard Guo <guofenglinux(at)gmail(dot)com>
Subject: Re: assertion failure with unique index + partitioning + join
Date: 2026-06-16 04:06:28
Message-ID: CAHewXN=LUW2xLt1-c=G0mARjq=wJhx+P7cY1KwPU1mdChJOS_Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

Tender Wang <tndrwang(at)gmail(dot)com> 于2026年6月16日周二 09:58写道:
>
> I can reproduce this issue on HEAD.
> The root->outer_join_rels is empty, and the i is 3(rel: t r).
> The left join can be removed in remove_useless_joins(), in which
> root->outer_join_rels is changed to be empty.
> But the from->qual in this case has already been distributed to its rel.
> (gdb) pgprint brel->baserestrictinfo
> RestrictInfo [is_pushed_down=true can_join=false pseudoconstant=false
> has_clone=false is_clone=false leakproof=false
> has_volatile=VOLATILITY_UNKNOWN security_level=0
> num_base_rels=1 rinfo_serial=1 eval_cost={startup = -1,
> per_tuple = 0} norm_selec=-1 outer_selec=-1 outer_is_left=false
> hashjoinoperator=0 left_bucketsize=-1
> right_bucketsize=-1 left_mcvfreq=-1 right_mcvfreq=-1
> left_hasheqoperator=0 right_hasheqoperator=0]
> [clause]
> PlaceHolderVar [phid=1 phlevelsup=0]
> [phexpr] Var [varno=2 varattno=1 vartype=16
> varreturningtype=VAR_RETURNING_DEFAULT varnosyn=2 varattnosyn=1]
> [phrels] Bitmapset [4 3 2]
> [clause_relids] Bitmapset [2]
> [required_relids] Bitmapset [2]
> I need to dig deeper to find out how to fix it.

I tried on the old version (pg1212), I got the correct plan, no crash.
And after pulling up the subquery, no PlaceHolderVar. I found after
commit cc5d98525d43,

commit cc5d98525d43c22b98f360ef0f2c8d7dc57f04dc
Author: Richard Guo <rguo(at)postgresql(dot)org>
Date: Thu Mar 13 16:36:03 2025 +0900

Fix incorrect handling of subquery pullup

the from->qual will include PHV, because this query contains groupingsets.
I reverted this commit, I got correct plan, too:
postgres=# explain SELECT
FROM (
SELECT *
FROM t
LEFT JOIN t r USING (a)
) ss
WHERE a
GROUP BY ();
QUERY PLAN
------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0)
(1 row)

I added Richard to the cc list. He may know more about this.

--
Thanks,
Tender Wang

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2026-06-16 04:13:19 Re: synchronized_standby_slots behavior inconsistent with quorum-based synchronous replication
Previous Message Daisuke Higuchi 2026-06-16 04:01:48 [PATCH] Fix sequence value may rollback after CREATE DATABASE TEMPLATE with WAL_LOG strategy