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: Clean up the Simple-8b encoder code.
Date: Mon, 25 Mar 2019 09:40:00 +0000
Message-ID: <E1h8M5I-0002Lw-Hq@gemulon.postgresql.org> (raw)

Clean up the Simple-8b encoder code.

Coverity complained that simple8b_encode() might read beyond the end of
the 'diffs' array, in the loop to encode the integers. That was a false
positive, because we never get into the loop in modes 0 or 1, and the
array is large enough for all the other modes. But I admit it's very
subtle, so it's not surprising that Coverity didn't see it, and it's not
very obvious to humans either. Refactor it, so that the second loop
re-computes the differences, instead of carrying them over from the first
loop in the 'diffs' array. This way, the 'diffs' array is not needed
anymore. It makes no measurable difference in performance, and seems more
straightforward this way.

Also, improve the comments in simple8b_encode(): fix the comment about its
return value that was flat-out wrong, and explain the condition when it
returns EMPTY_CODEWORD better.

In the passing, move the 'selector' from the codeword's low bits to the
high bits. It doesn't matter much, but looking at the original paper, and
googling around for other Simple-8b implementations, that's how it's
usually done.

Per Coverity, and Tom Lane's report off-list.

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d303122eab616ccbcfb0bab0fc674bf625d17a7b

Modified Files
--------------
src/backend/lib/integerset.c                       | 52 +++++++++++++---------
src/test/modules/test_integerset/test_integerset.c | 17 ++++---
2 files changed, 41 insertions(+), 28 deletions(-)



Message-ID: <E1h8M5I-0002Lw-Hq@gemulon.postgresql.org>
Permalink:  ../E1h8M5I-0002Lw-Hq@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1h8M5I-0002Lw-Hq@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: Clean up the Simple-8b encoder code.
  In-Reply-To: <E1h8M5I-0002Lw-Hq@gemulon.postgresql.org>
  References: <E1h8M5I-0002Lw-Hq@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