Re: Optimize WindowAgg's use of tuplestores - Mailing list pgsql-hackers

From David Rowley
Subject Re: Optimize WindowAgg's use of tuplestores
Date
Msg-id CAApHDvqbHxpiExo-krM7H+5NNL41QXdWp7ekzwgJk7Y8ff5gcQ@mail.gmail.com
Whole thread Raw
In response to Re: Optimize WindowAgg's use of tuplestores  (Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>)
Responses Re: Optimize WindowAgg's use of tuplestores
Re: Optimize WindowAgg's use of tuplestores
Re: Optimize WindowAgg's use of tuplestores
List pgsql-hackers
On Wed, 10 Jul 2024 at 02:42, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
> Observations
> 1. The numbers corresponding to 10 and 100 partitions are higher when
> patched. That might be just noise. I don't see any reason why it would
> impact negatively when there are a small number of partitions. The
> lower partition cases also have a higher number of rows per partition,
> so is the difference between MemoryContextDelete() vs
> MemoryContextReset() making any difference here. May be worth
> verifying those cases carefully. Otherwise upto 1000 partitions, it
> doesn't show any differences.

I think this might just be noise as a result of rearranging code. In
terms of C code, I don't see any reason for it to be slower.  If you
look at GenerationDelete() (as what is getting called from
MemoryContextDelete()), it just calls GenerationReset(). So resetting
is going to always be less work than deleting the context, especially
given we don't need to create the context again when we reset it.

I wrote the attached script to see if I can also see the slowdown and
I do see the patched code come out slightly slower (within noise
levels) in lower partition counts.

To get my compiler to produce code in a more optimal order for the
common case, I added unlikely() to the "if (winstate->all_first)"
condition.  This is only evaluated on the first time after a rescan,
so putting that code at the end of the function makes more sense.  The
attached v2 patch has it this way.  You can see the numbers look
slightly better in the attached graph.

Thanks for having a look at this.

David

Attachment

pgsql-hackers by date:

Previous
From: Rafia Sabih
Date:
Subject: Re: Things I don't like about \du's "Attributes" column
Next
From: Justin Pryzby
Date:
Subject: Re: CREATE INDEX CONCURRENTLY on partitioned index