Re: Custom TupleTableSlotOps while Initializing Custom Scan

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: V N G Samba Siva Reddy Chinta <sambasivareddychinta(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Custom TupleTableSlotOps while Initializing Custom Scan
Date: 2024-06-21 11:55:51
Message-ID: CAExHW5tFq_5F=NLLsmyBrnYLTjmN_q7RgrbMYxwZz8mxbeQgcQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Thu, Jun 20, 2024 at 5:58 PM V N G Samba Siva Reddy Chinta <
sambasivareddychinta(at)gmail(dot)com> wrote:

> Hello Team,
> Good Day,
>
> I have been working on adding a CustomScanState object in the executor
> state in my project. As part of CustomScanState, I execute queries and
> store their results in the Tuplestorestate object. After storing all
> tuples in the Tuplestorestate, I retrieve each tuple and place it in the
> TupleTableSlot using the tuplestore_gettupleslot() function.
>
> However, I encounter an error: *"trying to store a minimal tuple into the
> wrong type of slot."* Upon debugging, I discovered that the TupleTableSlot
> only holds virtual tuples (tupleTableSlot->tts_ops is set to TTSOpsVirtual).
> In contrast, tuplestore_gettupleslot() calls ExecStoreMinimalTuple(),
> which expects TupleTableSlotOps of type TTSOpsMinimalTuple.
>
> Further investigation revealed that in the ExecInitCustomScan() function
> within the nodeCustom.c source file, where ScanTupleSlot and
> ResultTupleSlots are initialized, users can choose custom slots by
> setting slotOps in CustomScanState. We initialize the ScanTupleSlot based
> on user-specified slotOps, but for ResultTupleSlot, we proceed with
> TTSOpsVirtual instead of the custom slotOps, which is causing the issue.
>
> Is this behavior expected? Is there a way to store tuples in slots
> according to the TupleTableSlot type?
>
> I found a function ExecForceStoreMinimalTuple() which can be used in my
> case. We need to pass the MinimalTuple to this function, but I was unable
> to find a way to fetch the tuple from tuple storestate. We do have tuplestore_gettuple()
> function to get the minimal tuple but it is a static function, is there any
> other function like that?
>

From the description I assume that you are passing ResultTupleSlot to
tuplestore_gettupleslot(). Please confirm.

I think the reason for CustomScan's ResultTupleSlot to be set to virtual
tuple slot is it's the most general kind of tuple - values and isnulls.
Other kinds depend upon the heap tuple format. And the rest of the code
needs CustomScans to produce a deterministic tuple slot type.

Without knowing the details of your code, I think what you need to do is
declare a minimal tuple slot, fetch the tuple from store using this slot
and then store it into ResultTupleSlot using its ttsops. Other types of
planstate nodes some times return the slot they get from their subplans as
is without going through ResultTupleSlot. You may want to do something like
that, if the result tuple contents are same as the tuple stored in
tuplestore

--
Best Wishes,
Ashutosh Bapat

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2024-06-21 12:07:21 Re: Small LO_BUFSIZE slows down lo_import and lo_export in libpq
Previous Message Hayato Kuroda (Fujitsu) 2024-06-21 11:21:22 pg_createsubscriber: drop pre-existing subscriptions from the converted node