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

From houzj.fnst@fujitsu.com
Subject RE: [PATCH] Use optimized single-datum tuplesort in ExecSort
Date
Msg-id OS0PR01MB57164E138C3CB2E12A91214094E49@OS0PR01MB5716.jpnprd01.prod.outlook.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  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-hackers
From: David Rowley <dgrowleyml@gmail.com>
> On Wed, 21 Jul 2021 at 13:39, James Coleman <jtc331@gmail.com> wrote:
> > Thanks for doing the math measuring how much we could impact things.
> >
> > I'm +lots on getting this committed as is.
> 
> Ok good. I plan on taking a final look at the v10 patch tomorrow morning NZ
> time (about 12 hours from now) and if all is well, I'll push it.
> 
> If anyone feels differently, please let me know before then.
Hi,

I noticed a minor thing about the v10 patch.

-
-        for (;;)
+        if (node->datumSort)
         {
-            slot = ExecProcNode(outerNode);
-
-            if (TupIsNull(slot))
-                break;
-
-            tuplesort_puttupleslot(tuplesortstate, slot);
+            for (;;)
+            {
+                slot = ExecProcNode(outerNode);
+
+                if (TupIsNull(slot))
+                    break;
+                slot_getsomeattrs(slot, 1);
+                tuplesort_putdatum(tuplesortstate,
+                                   slot->tts_values[0],
+                                   slot->tts_isnull[0]);
+            }
+        }
+        else
+        {
+            for (;;)
+            {
+                slot = ExecProcNode(outerNode);
+
+                if (TupIsNull(slot))
+                    break;
+                tuplesort_puttupleslot(tuplesortstate, slot);
+            }

The above seems can be shorter like the following ?

for (;;)
{
    slot = ExecProcNode(outerNode);
    if (TupIsNull(slot))
        break;
    if (node->datumSort)
    {
        slot_getsomeattrs(slot, 1);
        tuplesort_putdatum(tuplesortstate,
                    slot->tts_values[0],
                    slot->tts_isnull[0]);
    }
    else
        tuplesort_puttupleslot(tuplesortstate, slot);
}

Best regards,
houzj


pgsql-hackers by date:

Previous
From: Ranier Vilela
Date:
Subject: Re: Micro-optimizations to avoid some strlen calls.
Next
From: "houzj.fnst@fujitsu.com"
Date:
Subject: RE: Added schema level support for publication.