pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Clarify the logic in a few places in the new balanced merge code
Date: Mon, 25 Oct 2021 06:32:58 +0000
Message-ID: <E1metXW-0005yl-Gm@gemulon.postgresql.org> (raw)

Clarify the logic in a few places in the new balanced merge code.

In selectnewtape(), use 'nOutputTapes' rather than 'nOutputRuns' in the
check for whether to start a new tape or to append a new run to an
existing tape. Until 'maxTapes' is reached, nOutputTapes is always equal
to nOutputRuns, so it doesn't change the logic, but it seems more logical
to compare # of tapes with # of tapes. Also, currently maxTapes is never
modified after the merging begins, but written this way, the code would
still work if it was. (Although the nOutputRuns == nOutputTapes assertion
would need to be removed and using nOutputRuns % nOutputTapes to
distribute the runs evenly across the tapes wouldn't do a good job
anymore).

Similarly in mergeruns(), change to USEMEM(state->tape_buffer_mem) to
account for the memory used for tape buffers. It's equal to availMem
currently, but tape_buffer_mem is more direct and future-proof. For
example, if we changed the logic to only allocate half of the remaining
memory to tape buffers, USEMEM(state->tape_buffer_mem) would still be
correct.

Coverity complained about these. Hopefully this patch helps it to
understand the logic better. Thanks to Tom Lane for initial analysis.

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/166f94377c886516ca986ef8a623cd2e854fe911

Modified Files
--------------
src/backend/utils/sort/tuplesort.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)



Message-ID: <E1metXW-0005yl-Gm@gemulon.postgresql.org>
Permalink:  ../E1metXW-0005yl-Gm@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1metXW-0005yl-Gm@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi
  Subject: Re: pgsql: Clarify the logic in a few places in the new balanced merge code
  In-Reply-To: <E1metXW-0005yl-Gm@gemulon.postgresql.org>
  References: <E1metXW-0005yl-Gm@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox