Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEzUn-0000b7-Bs for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Sep 2019 17:30:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iEzUm-00059F-6c for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Sep 2019 17:30:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEzUl-000596-RJ for pgsql-hackers@lists.postgresql.org; Mon, 30 Sep 2019 17:29:59 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iEzUj-0003AB-0I for pgsql-hackers@postgresql.org; Mon, 30 Sep 2019 17:29:58 +0000 Received: by mail-wr1-x442.google.com with SMTP id y19so12308801wrd.3 for ; Mon, 30 Sep 2019 10:29:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=AtVLdbhxEcsexRXwkCfVC/WSPbdoVFSAxEvEFiJ9Rt8=; b=ZIAI9xuDj0FCJeZxeDxciw635uYBnpNR2j/pp4dK42JD/KtcUtYCCj6tNxkcZPKkVM U+ghYFbmsD8D9TlWqq/KjyX1vcUqv1VQBrf4gymzLEyKlq0ILa09adJq3O9ro+y8+wUD 3/+4xJLhSIwxzBNQMJm6yPGkH96u6WJFZ1oiBm2O57JUoOWT/eah0yUhCos9nsYmuR3b fqm3raas6nH8rBlnmelewX2kX2QytXUQmXFvJGROiXhhO9JixjEUlwdtq325BT+U4PJH UlHvGPmOglpFNlG+/+yJO2vgvw5gO7dd54ahDDdYstWrcB6npUr8Icy92hhTCZZBpSYT MtZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=AtVLdbhxEcsexRXwkCfVC/WSPbdoVFSAxEvEFiJ9Rt8=; b=hsEvcP/Ixfy8c0BWwI8AKW/uHkOYM1dSANC2lA6Za2J7glrGa3vFhh4Gq3UjO49X/i k+od1bFcwEL7VYsXUV3J0jUDvklDrj0HNaYiYazFufv8HDRfHfujaI+Se0hulCEVUR63 qWpOZGrMAZEk90y4jlMv6CMO1dcc9eJ3magS4YImT9bkQix/aUKz3xMcYDzAeNDsmT22 VdBrNPD8IqMrUOoiKFNXD+sftrPuuCynOwoTvqUFNcqb3TFIf55c89IF18s4YWCCi0bX kemnEJ9Nk2wb0kzB826Y23SAWEAr3fOuq3vjM+Uyp1W57tXvxYLStapddKlSGv0mn2Q5 m5ng== X-Gm-Message-State: APjAAAXK1yY6krvmPLyqQVkP6drCmQsWn5an6y2smMKO3pWvw0L0dFQr ILsgUtDiJMBrwKFW0A+/VShcAg== X-Google-Smtp-Source: APXvYqwWcViKRNWSvjAQqs3WAGKgP78jNoj2fggPdZxk732nWqWkz9lrKpM04a59yoyrLAZvBrm6Aw== X-Received: by 2002:a5d:628f:: with SMTP id k15mr13818778wru.124.1569864595510; Mon, 30 Sep 2019 10:29:55 -0700 (PDT) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id o19sm306270wmh.27.2019.09.30.10.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 10:29:54 -0700 (PDT) Date: Mon, 30 Sep 2019 19:29:51 +0200 From: Tomas Vondra To: Andrey Borodin Cc: Alvaro Herrera , Binguo Bao , Paul Ramsey , Pgsql Hackers Subject: Re: Optimize partial TOAST decompression Message-ID: <20190930172951.gdedvexnf4d2wv5e@development> References: <20190710144725.kaswinyw2bdgb6tz@development> <20190925203834.GA25060@alvherre.pgsql> <20190926230036.ubxzgkqsphbzmbdl@development> <20190930155607.5tnyzksijgm4imbg@development> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Sep 30, 2019 at 09:20:22PM +0500, Andrey Borodin wrote: > > >> 30 сент. 2019 г., в 20:56, Tomas Vondra написал(а): >> >> 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