Re: [PATCH] Use optimized single-datum tuplesort in ExecSort - Mailing list pgsql-hackers

From Ranier Vilela
Subject Re: [PATCH] Use optimized single-datum tuplesort in ExecSort
Date
Msg-id CAEudQApgSfx1_fGYSk9hdAg0Noghdp+vM+gsHcwQkbVR=BviKA@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Use optimized single-datum tuplesort in ExecSort  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: [PATCH] Use optimized single-datum tuplesort in ExecSort
List pgsql-hackers
Em qua., 14 de jul. de 2021 às 07:14, David Rowley <dgrowleyml@gmail.com> escreveu:
On Tue, 13 Jul 2021 at 15:15, David Rowley <dgrowleyml@gmail.com> wrote:
> In theory, we likely could get rid of the small regression by having
> two versions of ExecSort() and setting the correct one during
> ExecInitSort() by setting the function pointer to the version we want
> to use in sortstate->ss.ps.ExecProcNode.

Just to see how it would perform, I tried what I mentioned above. I've
included what I ended up with in the attached POC patch.

I got the following results on my AMD hardware.

Test master v8 patch comparison
Test1   448.0   671.7   149.9%
Test2   316.4   317.5   100.3%
Test3   299.5   381.6   127.4%
Test4   219.7   229.5   104.5%
Test5   226.3   254.6   112.5%
Test6   197.9   217.9   110.1%
Test7   179.2   185.3   103.4%
Test8   389.2   544.8   140.0%
I'm a little surprised by your results.
Test1 and Test8 look pretty good to me.
What is compiler and environment?

I repeated (3 times) the benchmark with v8 here,
and the results were not good.


                  HEAD           v6             v7b           v8        v6 vs head             v8 vs v6            v8 vs v7b
Test1288,149636449,018541550,48505468,168165155,83%104,26%85,05%
Test294,76695595,45140694,71898294,800275100,72%99,32%100,09%
Test3190,521319260,279802278,115296262,538383136,61%100,87%94,40%
Test478,77934478,25345577,94148278,47154699,33%100,28%100,68%
Test5131,362614142,662223149,639041144,849303108,60%101,53%96,80%
Test6112,884298124,181671127,58497124,29376110,01%100,09%97,42%
Test769,30858768,64306769,08754469,43731299,04%101,16%100,51%
Test8243,674171364,681142419,259703369,239176149,66%101,25%88,07%



This time I saw no regression on tests 2, 4 and 7.

I looked to see if there was anywhere else in the executor that
conditionally uses a different exec function in this way and found
nothing, so I'm not too sure if it's a good idea to start doing this.
Specialized functions can be a way to optimize. The compilers themselves do it.
But the ExecSortTuple and ExecSortDatum are much more similar,
which can cause maintenance problems.
I don't think in this case it would be a good idea.
 

It would be good to get a 2nd opinion about this idea.  Also, more
benchmark results with v6 and v8 would be good too.
Yeah, another different machine.
I would like to see other results with v7b.

Attached the file with all results from v8.

regards,
Ranier Vilela
Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: SI messages sent when excuting ROLLBACK PREPARED command
Next
From: John Naylor
Date:
Subject: Re: Replacing pg_depend PIN entries with a fixed range check