pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Andrey Borodin <x4mmm@yandex-team.ru>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Binguo Bao <djydewang@gmail.com>
Cc: Paul Ramsey <pramsey@cleverelephant.ca>
Cc: Pgsql Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Optimize partial TOAST decompression
Date: Mon, 30 Sep 2019 19:29:51 +0200
Message-ID: <20190930172951.gdedvexnf4d2wv5e@development> (raw)
In-Reply-To: <E11354D1-6980-408D-AC4B-E147EB7CCDED@yandex-team.ru>
References: <20190710144725.kaswinyw2bdgb6tz@development>
	<20190925203834.GA25060@alvherre.pgsql>
	<20190926230036.ubxzgkqsphbzmbdl@development>
	<20190930155607.5tnyzksijgm4imbg@development>
	<E11354D1-6980-408D-AC4B-E147EB7CCDED@yandex-team.ru>

On Mon, Sep 30, 2019 at 09:20:22PM +0500, Andrey Borodin wrote:
>
>
>> 30 сент. 2019 г., в 20:56, Tomas Vondra <tomas.vondra@2ndquadrant.com> написал(а):
>>
>> I mean this:
>>
>>   /*
>>    * Use int64 to prevent overflow during calculation.
>>    */
>>   compressed_size = (int32) ((int64) rawsize * 9 + 8) / 8;
>>
>> I'm not very familiar with pglz internals, but I'm a bit puzzled by
>> this. My first instinct was to compare it to this:
>>
>>   #define PGLZ_MAX_OUTPUT(_dlen)	((_dlen) + 4)
>>
>> but clearly that's a very different (much simpler) formula. So why
>> shouldn't pglz_maximum_compressed_size simply use this macro?

>
>compressed_size accounts for possible increase of size during
>compression. pglz can consume up to 1 control byte for each 8 bytes of
>data in worst case.

OK, but does that actually translate in to the formula? We essentially
need to count 8-byte chunks in raw data, and multiply that by 9. Which
gives us something like

   nchunks = ((rawsize + 7) / 8) * 9;

which is not quite what the patch does.

>Even if whole data is compressed well - there can be prefix compressed
>extremely ineffectively. Thus, if you are going to decompress rawsize
>bytes, you need at most compressed_size bytes of compressed input.

OK, that explains why we can't use the PGLZ_MAX_OUTPUT macro.

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





view thread (32+ messages)  latest in thread

Message-ID: <20190930172951.gdedvexnf4d2wv5e@development>
Permalink:  ../20190930172951.gdedvexnf4d2wv5e@development/
Also on:    postgresql.org/message-id/20190930172951.gdedvexnf4d2wv5e@development

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tomas.vondra@2ndquadrant.com, x4mmm@yandex-team.ru, alvherre@2ndquadrant.com, djydewang@gmail.com, pramsey@cleverelephant.ca
  Subject: Re: Optimize partial TOAST decompression
  In-Reply-To: <20190930172951.gdedvexnf4d2wv5e@development>

* 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