Re: Use virtual tuple slot for Unique node - Mailing list pgsql-hackers

From David Rowley
Subject Re: Use virtual tuple slot for Unique node
Date
Msg-id CAApHDvq3W0mvKTMe9r032Jbzb1E8dwE1SCCZ1WnkuLvc45r8wg@mail.gmail.com
Whole thread Raw
In response to Re: Use virtual tuple slot for Unique node  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Use virtual tuple slot for Unique node
List pgsql-hackers
On Thu, 19 Oct 2023 at 22:29, David Rowley <dgrowleyml@gmail.com> 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 on the queries.

I ran pgbench for 1 minute on each query and did pg_prewarm on each
table. Here are the times I got in milliseconds:

Query   master   Master + 0001   compare
Q1        2.576     1.979                 130.17%
Q2        9.546     9.941                   96.03%
Q3        9.069     9.536                   95.10%
Q4        7.285     7.208                 101.07%
Q5        7.585     6.904                 109.86%
Q6     162.253 161.434                100.51%
Q7       62.507   58.922                106.08%

I also noted down the slot type that nodeUnique.c is using in each of
the queries:

Q1 TTSOpsVirtual
Q2 TTSOpsVirtual
Q3 TTSOpsVirtual
Q4 TTSOpsMinimalTuple
Q5 TTSOpsVirtual
Q6 TTSOpsMinimalTuple
Q7 TTSOpsMinimalTuple

So, I'm not really expecting Q4, Q6 or Q7 to change much. However, Q7
does seem to be above noise level faster and I'm not sure why.

We can see that Q2 and Q3 become a bit slower.  This makes sense as
tts_virtual_materialize() is quite a bit more complex than
heap_copy_minimal_tuple() which is a simple palloc/memcpy.

We'd likely see Q2 and Q3 do better with the patched version if there
were more duplicates as there'd be less tuple deforming going on
because of the virtual slots.

Overall, the patched version is 5.55% faster than master.  However,
it's pretty hard to say if we should do this or not. Q3 has a mix of
varlena and byval types and that came out slower with the patched
version.

I've attached the script I used to get the results and the setup,
which is just your tables shrunk down to 10k rows.

David

Attachment

pgsql-hackers by date:

Previous
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: RE: [PoC] pg_upgrade: allow to upgrade publisher node
Next
From: Marko Tiikkaja
Date:
Subject: Re: [HACKERS] Allow INSTEAD OF DELETE triggers to modify the tuple for RETURNING