Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOU8x-0006hz-OY for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Dec 2017 19:53:40 +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 1eOU8x-00057K-7t for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Dec 2017 19:53:39 +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 1eOU8w-000578-TG for pgsql-hackers@lists.postgresql.org; Mon, 11 Dec 2017 19:53:39 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eOU8t-0004Mm-DC for pgsql-hackers@postgresql.org; Mon, 11 Dec 2017 19:53:38 +0000 Received: by mail-wr0-x242.google.com with SMTP id y21so18858944wrc.1 for ; Mon, 11 Dec 2017 11:53:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=xyxQ3Q4sys59JJ89FBZjVWpaGZNl1T9TBDXLQsOF+m0=; b=axko4VMWhtpyFl+E9gNDzMT2MbbuozscoLP9dpFGMMx+g79RgiL8Uyx6jU9x/PXxCc 76JVyxJvbtomj9eO5WE5L0EiJIs9fPxoeaTB31x6oqeQFu4MZULZerULFfF+IDiRyqwG iYncdAz3LQLz1WGfnXqVTJrklKttYeAjQGKXGjMjdAMVNh1END/kU5o311OPgsB65RnL n7qwWF1sXii6MgXvnavGDJ1fMyGT78B4z9wFvCHkdLKYCXR+B4JbjRJTUTpCLCU/bm6B hD7sKAM//RQGZ1GzYb9V3JSRrFQxcAWH1lDuRsjWch3cVA5eY/3bc7BudU+CpgAi5mf0 WvMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=xyxQ3Q4sys59JJ89FBZjVWpaGZNl1T9TBDXLQsOF+m0=; b=CqVc9WkC3yE/1YIIpNZmAuesicMEJNp/x2vr7+QC1zSilfm18Dbvr38l+fxpl6lb50 8QrfzeU+dR9VhMdUovRkUVq5GjkB0OacMgV/dQqAZHrONLEhZpaG2+JxLJMPJuvT1yry tF7r5I2mpmPmHCxhzeHSFzy1M0sa6T781RDdIoRdMtIdODjoq7bG3TMWdilZGsqdIuhF Ql/u3mti7vLPXayiXYmdbpeUn/pSLcp4jwPnR0eHopxnvy+2TkYN+pnYxdMSTickE0Nx 3H/mgPbCUM4u9RK+7Vd9PwwG7CVetCvjSGb/R4jpmW4oHdXGM0QHGStjxv1cJK1Hqams 2oZg== X-Gm-Message-State: AKGB3mIn/9l17Oa4Qj2cu59yVtRMjmKxZe4tqv2ZWBCjDIVyB2CLHqco Pq9jmPgCSPFeiTnrjL8MPrQgQNxlWwI3Ln09nZUABaaxeQAOYFhasU9jgOrnAFdwPnde3tCygUM Piev3fhgwJ3aVZQPwrQnPuS+4e/vW+SmBuf561809tx2VAZ4t8pBr4jMB0uypaEJZvkk6MgbvfX RDDc/XSSC4 X-Google-Smtp-Source: ACJfBotlWaySXiD+vXvOADBeRaq79qCj7xSdECSple1c3+Az9Ofe8yKfi17gFVZisc1v5Qi+sgFk7A== X-Received: by 10.223.129.3 with SMTP id 3mr1541729wrm.90.1513022013255; Mon, 11 Dec 2017 11:53:33 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id r15sm16396108wrc.36.2017.12.11.11.53.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Dec 2017 11:53:32 -0800 (PST) Subject: Re: [HACKERS] Custom compression methods To: Ildus Kurbangaliev , pgsql-hackers@postgresql.org References: <20170907194236.4cefce96@wp.localdomain> From: Tomas Vondra Message-ID: <29527031-c837-59e1-760d-677bb33d6b0f@2ndquadrant.com> Date: Mon, 11 Dec 2017 20:53:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170907194236.4cefce96@wp.localdomain> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I see there's an ongoing discussion about the syntax and ALTER TABLE behavior when changing a compression method for a column. So the patch seems to be on the way to be ready in the January CF, I guess. 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. FWIW I don't know the answers, but I think it's important to ask them. Also, apologies if this post looks to be against the patch - that's part of the "devil's advocate" thing. The main question I'm asking myself is what use cases the patch addresses, and whether there is a better way to do that. I see about three main use-cases: 1) Replacing the algorithm used to compress all varlena types (in a way that makes it transparent for the data type code). 2) Custom datatype-aware compression (e.g. the tsvector). 3) Custom datatype-aware compression with additional column-specific metadata (e.g. the jsonb with external dictionary). Now, let's discuss those use cases one by one, and see if there are simpler (or better in some way) solutions ... 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. No dependencies tracking, no ALTER TABLE issues, etc. Of course, it would not allow using different compression algorithms for different columns (although it might perhaps allow different compression level, to some extent). Conclusion: If we want to offer a simple cluster-wide pglz alternative, perhaps this patch is not the right way to do that. 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. 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. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services