[PATCH] Use optimized single-datum tuplesort in ExecSort

From: Ronan Dunklau <ronan(dot)dunklau(at)aiven(dot)io>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: ranier(dot)vf(at)gmail(dot)com, James Coleman <jtc331(at)gmail(dot)com>
Subject: [PATCH] Use optimized single-datum tuplesort in ExecSort
Date: 2021-07-06 06:15:41
Message-ID: 3177670.itZtoPt7T5@aivenronan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

While testing the patch "Add proper planner support for ORDER BY / DISTINCT
aggregates" [0] I discovered the performance penalty from adding a sort node
essentially came from not using the single-datum tuplesort optimization in
ExecSort (contrary to the sorting done in ExecAgg).

I originally proposed this patch as a companion in the same thread [1], but
following James suggestion I'm making a separate thread just for this as the
optimization is worthwhile independently of David's patch: it looks like we
can expect a 2x speedup on a "select a single ordered column" case.

The patch aimed to be as simple as possible: we only turn this optimization on
when the tuple being sorted has only one attribute, it is "byval" (so as not
to incur copies which would be hard to track in the execution tree) and
unbound (again, not having to deal with copying borrowed datum anywhere).

The attached patch is originally by me, with some cleanup by Ranier Vilela.
I'm sending Ranier's version here.

[0]: https://commitfest.postgresql.org/33/3164/
[1]: https://www.postgresql.org/message-id/4480689.ObhdGn8bVM%40aivenronan

--
Ronan Dunklau

Attachment Content-Type Size
v2-0001-Allow-Sort-nodes-to-use-the-fast-single-datum-tuples.patch text/x-patch 3.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message r.takahashi_2@fujitsu.com 2021-07-06 06:15:44 RE: Transactions involving multiple postgres foreign servers, take 2
Previous Message Fabien COELHO 2021-07-06 06:13:36 Re: rand48 replacement