Re: BUG #18252: Assert in CheckOpSlotCompatibility() fails when recursive union filters tuples in non-recursive term

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18252: Assert in CheckOpSlotCompatibility() fails when recursive union filters tuples in non-recursive term
Date: 2023-12-19 11:28:35
Message-ID: CAMbWs4-LHk1tQmj6gYL3ESh9fvP21Zmo9yHSscBzua0Kx=pOHw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Dec 19, 2023 at 12:30 AM PG Bug reporting form <
noreply(at)postgresql(dot)org> wrote:

> CREATE TABLE t(i int);
> INSERT INTO t VALUES (1), (1);
>
> WITH RECURSIVE rt(i) AS (
> SELECT * FROM t
> UNION
> SELECT * FROM rt
> )
> SELECT * FROM rt;

Nice catch. The TupleHashTable's tableslot is created as type
TTSOpsMinimalTuple. The RecursiveUnion's non-recursive term generates
tuples of type TTSOpsBufferHeapTuple. If the non-recursive term
produces duplicate tuples, we'd find non-empty bucket when inserting the
same key into the hashtable. In this case we need to check to see if
the two tuples match: one is of the hashtable's tableslot
(TTSOpsMinimalTuple), and the other comes from the non-recursive term
(TTSOpsBufferHeapTuple). And the incompatible slot type would fail
CheckOpSlotCompatibility.

I have no idea about how to fix it.

BTW, while reading the codes, I noticed two typos in simplehash.h, one
is in the comment of SH_INSERT, the other is in the comment of
SH_INSERT_HASH. Attached is a trivial patch for that.

Thanks
Richard

Attachment Content-Type Size
v1-0001-Fix-typos-in-simplehash.h.patch application/octet-stream 1.5 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2023-12-19 15:22:20 Re: BUG #18247: Integer overflow leads to negative width
Previous Message Michael Paquier 2023-12-19 09:20:44 Re: BUG #18246: pgstathashindex() attempts to read invalid file for hash index attached to partitioned table