Re: Use virtual tuple slot for Unique node

2024-03-28 Thread Andrey M. Borodin
> On 29 Oct 2023, at 21:30, Denis Smirnov wrote: > > I have taken a look at this discussion, at the code and I am confused how we > choose tuple table slot (TTS) type in PG. After offline discussion with Denis, we decided to withdraw this patch from CF for now. If anyone is willing to revi

Re: Use virtual tuple slot for Unique node

2023-10-29 Thread Denis Smirnov
I have taken a look at this discussion, at the code and I am confused how we choose tuple table slot (TTS) type in PG. May be you can clarify this topic or me. 1. Brief intro. There are four types of TTS. Plan tree «leaves»: - buffer heap (produced by index and table scans, has system columns a

Re: Use virtual tuple slot for Unique node

2023-10-29 Thread David Rowley
On Fri, 27 Oct 2023 at 22:05, Ashutosh Bapat wrote: > > On Fri, Oct 27, 2023 at 8:48 AM David Rowley wrote: > > I was uncertain if the old behaviour of when srcslot contains fewer > > attributes than dstslot was intended or not. What happens there is > > that we'd leave the additional old dstslo

Re: Use virtual tuple slot for Unique node

2023-10-27 Thread Ashutosh Bapat
On Fri, Oct 27, 2023 at 8:48 AM David Rowley wrote: > > On Wed, 25 Oct 2023 at 22:48, Ashutosh Bapat > wrote: > > We may save the size of data in VirtualTupleTableSlot, thus avoiding > > the first loop. I assume that when allocating > > VirtualTupleTableSlot->data, we always know what size we are

Re: Use virtual tuple slot for Unique node

2023-10-26 Thread David Rowley
On Wed, 25 Oct 2023 at 22:48, Ashutosh Bapat wrote: > We may save the size of data in VirtualTupleTableSlot, thus avoiding > the first loop. I assume that when allocating > VirtualTupleTableSlot->data, we always know what size we are > allocating so it should be just a matter of saving it in > Vir

Re: Use virtual tuple slot for Unique node

2023-10-25 Thread Ashutosh Bapat
On Tue, Oct 24, 2023 at 4:30 AM David Rowley wrote: > > On Fri, 20 Oct 2023 at 22:30, Ashutosh Bapat > wrote: > > I ran my experiments again. It seems on my machine the execution times > > do vary a bit. I ran EXPLAIN ANALYZE on the query 5 times and took > > average of execution times. I did thi

Re: Use virtual tuple slot for Unique node

2023-10-23 Thread David Rowley
On Fri, 20 Oct 2023 at 22:30, Ashutosh Bapat wrote: > I ran my experiments again. It seems on my machine the execution times > do vary a bit. I ran EXPLAIN ANALYZE on the query 5 times and took > average of execution times. I did this three times. For each run the > standard deviation was within 2

Re: Use virtual tuple slot for Unique node

2023-10-20 Thread Ashutosh Bapat
On Thu, Oct 19, 2023 at 4:26 PM David Rowley wrote: > > On Thu, 19 Oct 2023 at 22:29, David Rowley wrote: > > It's hard to imagine why there would be a slowdown as this query uses > > a TTSOpsMinimalTuple slot type in the patch and the unpatched version. > > I shrunk down your table sizes to 10k

Re: Use virtual tuple slot for Unique node

2023-10-19 Thread David Rowley
On Thu, 19 Oct 2023 at 22:29, David Rowley wrote: > It's hard to imagine why there would be a slowdown as this query uses > a TTSOpsMinimalTuple slot type in the patch and the unpatched version. I shrunk down your table sizes to 10k rows instead of 1 million rows to reduce the CPU cache pressure

Re: Use virtual tuple slot for Unique node

2023-10-19 Thread David Rowley
On Thu, 12 Oct 2023 at 23:06, Ashutosh Bapat wrote: > Q7 select distinct a,b from (select string_agg(left(a, 100), ', ') > over (order by a rows 2 preceding) a, b from t_text) q > HEAD: 16070.62 ms > patched: 16182.16 ms Did you time the SELECT or EXPLAIN ANALYZE? With SELECT, I'm unable to recr

Re: Use virtual tuple slot for Unique node

2023-10-12 Thread Ashutosh Bapat
On Tue, Oct 10, 2023 at 2:23 PM David Rowley wrote: > > On Wed, 27 Sept 2023 at 20:01, David Rowley wrote: > > > > On Sat, 23 Sept 2023 at 03:15, Heikki Linnakangas wrote: > > > So not a win in this case. Could you peek at the outer slot type, and > > > use the same kind of slot for the Unique's

Re: Use virtual tuple slot for Unique node

2023-10-10 Thread David Rowley
On Wed, 27 Sept 2023 at 20:01, David Rowley wrote: > > On Sat, 23 Sept 2023 at 03:15, Heikki Linnakangas wrote: > > So not a win in this case. Could you peek at the outer slot type, and > > use the same kind of slot for the Unique's result? Or some more > > complicated logic, like use a virtual s

Re: Use virtual tuple slot for Unique node

2023-09-27 Thread David Rowley
On Sat, 23 Sept 2023 at 03:15, Heikki Linnakangas wrote: > So not a win in this case. Could you peek at the outer slot type, and > use the same kind of slot for the Unique's result? Or some more > complicated logic, like use a virtual slot if all the values are > pass-by-val? I'd also like to keep

Re: Use virtual tuple slot for Unique node

2023-09-22 Thread Heikki Linnakangas
I did a little more perf testing with this. I'm seeing the same benefit with the query you posted. But can we find a case where it's not beneficial? If I understand correctly, when the input slot is a virtual slot, it's cheaper to copy it to another virtual slot than to form a minimal tuple. Li

Re: Use virtual tuple slot for Unique node

2023-08-31 Thread Денис Смирнов
Again the new patch hasn't been attached to the thread, so resend it. v3-use-virtual-slots-for-unique-node.patch Description: Binary data

Re: Use virtual tuple slot for Unique node

2023-08-31 Thread Denis Smirnov
I have made a small research and found out that though the patch itself is correct (i.e. we can benefit from replacing TTSOpsMinimalTuple with TTSOpsVirtual for the Unique node), my explanation WHY was wrong.1. We always materialize the new unique tuple in the slot, never mind what type of tuple ta

Re: Use virtual tuple slot for Unique node

2023-08-30 Thread Denis Smirnov
It looks like my patch was not analyzed by the hackers mailing list due to incorrect mime type, so I duplicate it here. commit 2852a3f2fab8e723f208d81c1ad1eb6a6a377b09 Author: Denis Smirnov Date: Thu Aug 31 08:51:14 2023 +0700 Change tuple table slot for Unique node to "virtual" T

Re: Use virtual tuple slot for Unique node

2023-08-30 Thread David Rowley
On Thu, 31 Aug 2023 at 05:37, Денис Смирнов wrote: > I have inspected the performance of the GROUP BY and DISTINCT queries for the > sorted data streams and found out, that Group node (produced by GROUP BY) > works faster then the Unique node (produced by DISTINCT). The flame graph > should ou