Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOiwW-0006MA-Dc for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Dec 2017 11:41:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOiwV-0004Sl-Ma for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Dec 2017 11:41:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eOiwV-0004Sb-Ad for pgsql-hackers@lists.postgresql.org; Tue, 12 Dec 2017 11:41:47 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eOiwS-0007od-F3 for pgsql-hackers@postgresql.org; Tue, 12 Dec 2017 11:41:46 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 6239121C1E4D; Tue, 12 Dec 2017 14:41:43 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from localhost.localdomain (unknown [217.23.185.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 2CAD721C1ADB; Tue, 12 Dec 2017 14:41:43 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1513078903; bh=91/U6LrismAu0ElLVHKm5NxtfXxyBQDhiIS2GgFY4gM=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=Ua3b4mBoxC3Db1RvCN3cdVN88b93B7jYEHN6aLs3wuQWDrSLyMGcTCZqOw72asu3J DkQcv74Hna4eUXM3IgN/X7nPbS2NVGjz1JS0dZCZc8xmki1KUBymWfY7xf2jw6LV62 VL/JOR6/eMVKA7m2/jc/0QP6Dctgt7g4ote26F6k= Date: Tue, 12 Dec 2017 14:41:42 +0300 From: Ildus Kurbangaliev To: Tomas Vondra Cc: pgsql-hackers@postgresql.org Subject: Re: [HACKERS] Custom compression methods Message-ID: <20171212144142.4bfc7aac@postgrespro.ru> In-Reply-To: <29527031-c837-59e1-760d-677bb33d6b0f@2ndquadrant.com> References: <20170907194236.4cefce96@wp.localdomain> <29527031-c837-59e1-760d-677bb33d6b0f@2ndquadrant.com> X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 11 Dec 2017 20:53:29 +0100 Tomas Vondra wrote: > But let me play the devil's advocate for a while and question the > usefulness of this approach to compression. Some of the questions were > mentioned in the thread before, but I don't think they got the > attention they deserve. Hi. I will try to explain why this approach could be better than others. > > > Replacing the algorithm used to compress all varlena values (in a way > that makes it transparent for the data type code). > ---------------------------------------------------------------------- > > While pglz served us well over time, it was repeatedly mentioned that > in some cases it becomes the bottleneck. So supporting other state of > the art compression algorithms seems like a good idea, and this patch > is one way to do that. > > But perhaps we should simply make it an initdb option (in which case > the whole cluster would simply use e.g. lz4 instead of pglz)? > > That seems like a much simpler approach - it would only require some > ./configure options to add --with-lz4 (and other compression > libraries), an initdb option to pick compression algorithm, and > probably noting the choice in cluster controldata. Replacing pglz for all varlena values wasn't the goal of the patch, but it's possible to do with it and I think that's good. And as Robert mentioned pglz could appear as builtin undroppable compresssion method so the others could be added too. And in the future it can open the ways to specify compression for specific database or cluster. > > Custom datatype-aware compression (e.g. the tsvector) > ---------------------------------------------------------------------- > > Exploiting knowledge of the internal data type structure is a > promising way to improve compression ratio and/or performance. > > The obvious question of course is why shouldn't this be done by the > data type code directly, which would also allow additional benefits > like operating directly on the compressed values. > > Another thing is that if the datatype representation changes in some > way, the compression method has to change too. So it's tightly coupled > to the datatype anyway. > > This does not really require any new infrastructure, all the pieces > are already there. > > In some cases that may not be quite possible - the datatype may not be > flexible enough to support alternative (compressed) representation, > e.g. because there are no bits available for "compressed" flag, etc. > > Conclusion: IMHO if we want to exploit the knowledge of the data type > internal structure, perhaps doing that in the datatype code directly > would be a better choice. It could be, but let's imagine there will be internal compression for tsvector. It means that tsvector has two formats now and minus one bit somewhere in the header. After a while we found a better compression but we can't add it because there is already one and it's not good to have three different formats for one type. Or, the compression methods were implemented and we decided to use dictionaries for tsvector (if the user going to store limited number of words). But it will mean that tsvector will go two compression stages (for its internal and for dictionaries). > > > Custom datatype-aware compression with additional column-specific > metadata (e.g. the jsonb with external dictionary). > ---------------------------------------------------------------------- > > Exploiting redundancy in multiple values in the same column (instead > of compressing them independently) is another attractive way to help > the compression. It is inherently datatype-aware, but currently can't > be implemented directly in datatype code as there's no concept of > column-specific storage (e.g. to store dictionary shared by all values > in a particular column). > > I believe any patch addressing this use case would have to introduce > such column-specific storage, and any solution doing that would > probably need to introduce the same catalogs, etc. > > The obvious disadvantage of course is that we need to decompress the > varlena value before doing pretty much anything with it, because the > datatype is not aware of the compression. > > So I wonder if the patch should instead provide infrastructure for > doing that in the datatype code directly. > > The other question is if the patch should introduce some > infrastructure for handling the column context (e.g. column > dictionary). Right now, whoever implements the compression has to > implement this bit too. Column specific storage sounds optional to me. For example compressing timestamp[] using some delta compression will not require it. -- ---- Regards, Ildus Kurbangaliev