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

From Richard Guo
Subject Re: BUG #18252: Assert in CheckOpSlotCompatibility() fails when recursive union filters tuples in non-recursive term
Date
Msg-id CAMbWs4-LHk1tQmj6gYL3ESh9fvP21Zmo9yHSscBzua0Kx=pOHw@mail.gmail.com
Whole thread Raw
In response to BUG #18252: Assert in CheckOpSlotCompatibility() fails when recursive union filters tuples in non-recursive term  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18252: Assert in CheckOpSlotCompatibility() fails when recursive union filters tuples in non-recursive term
Re: BUG #18252: Assert in CheckOpSlotCompatibility() fails when recursive union filters tuples in non-recursive term
List pgsql-bugs

On Tue, Dec 19, 2023 at 12:30 AM PG Bug reporting form <noreply@postgresql.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

pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #18246: pgstathashindex() attempts to read invalid file for hash index attached to partitioned table
Next
From: Tom Lane
Date:
Subject: Re: BUG #18247: Integer overflow leads to negative width