Re: A qsort template

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Justin Pryzby <pryzby(at)telsasoft(dot)com>, John Naylor <john(dot)naylor(at)enterprisedb(dot)com>, Peter Geoghegan <pg(at)bowt(dot)ie>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <rhaas(at)postgresql(dot)org>
Subject: Re: A qsort template
Date: 2022-04-12 00:58:09
Message-ID: CAApHDvoO0sJiGgqK3vx=XX4TF6qik3YbLT-XAfvQLW6uq=t-NQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 11 Apr 2022 at 09:44, Thomas Munro <thomas(dot)munro(at)gmail(dot)com> wrote:
> Planning to look at this more closely after I've sorted out some other
> problems, but thought I'd post this draft/problem report early in case
> John or others have thoughts or would like to run some experiments.

Thanks for putting the patch together.

I had a look at the patch and I wondered if we really need to add an
entire dimension of sort functions for just this case. My thought
process here is that when I look at a function such as
ApplySignedSortComparator(), I think that it might be better to save
adding another dimension for a sort case such as a column that does
not contain any NULLs. There's quite a bit more branching saved from
getting rid of NULL tests there than what we could save by checking if
we need to call the tiebreaker function in a function like
qsort_tuple_signed_compare().

I didn't really know what the performance implications would be of
checking an extra flag would be, so I very quickly put a patch
together and ran the benchmarks.

The 4GB work_mem 1 million tuple test with values MOD 100 comes out as:

Thomas' patch: 10.13% faster than v14
My patch: 9.48% faster than v14
master: 15.62% *slower* than v14

So it does seem like we can fix the regression in a more simple way.
We could then maybe do some more meaningful performance tests during
the v16 cycle to explore the most useful dimension to add that gains
the most performance. Perhaps that's NULLs, or maybe it's something
else.

I've attached the patch I tested. It was thrown together very quickly
just to try out the performance. If it's interesting I can polish it
up a bit. If not, I didn't waste too much time.

David

Attachment Content-Type Size
skip_calling_sort_tiebreak_when_not_needed.patch text/plain 3.9 KB
1m_tup_mod_100_v2.png image/png 82.8 KB
v14_vs_v15_sorting_v2 .ods application/vnd.oasis.opendocument.spreadsheet 89.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message houzj.fnst@fujitsu.com 2022-04-12 01:31:15 RE: row filtering for logical replication
Previous Message Masahiko Sawada 2022-04-12 00:45:23 Re: Skip partition tuple routing with constant partition key