Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHCeS-00051y-SH for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Nov 2017 17:48:04 +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 1eHCeQ-0004AF-He for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Nov 2017 17:48:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eHCeQ-00049z-47 for pgsql-hackers@lists.postgresql.org; Tue, 21 Nov 2017 17:48:02 +0000 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eHCeI-0006s8-Ad for pgsql-hackers@postgresql.org; Tue, 21 Nov 2017 17:48:00 +0000 Received: by mail-wm0-x22e.google.com with SMTP id b189so5122653wmd.5 for ; Tue, 21 Nov 2017 09:47:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=OAx8om4msRPj0efgRy4jz8RJQnUY3zCFMGdnCfxddyU=; b=QYANk9BayEXnAiuy9u5CyaGvYrRrpBSJu2+d1zGHHCIDHYNgCm/PT9pQIRR9L/SQSR d6MhEygjpeHq5BgVhyENliBwbhyfKCQMqfyXyvbwI2IuzckNvs9sf+Iri1bhizqnpLki qe7Z/3EhW0FvVmnkF4d8aIz7jpXzUBFiGQK/7fSm5ipgxapdP8Ry1+s4sUWGE2wC0gub h+Jtzb7qP9ZK8DpORsjObM9jcpdLqo5WzHH619FfXov5Rxbk4Pi7bXq1lh1y4UUlnOW8 4bG126QU5xbNm/t4RHVFWIoSD6bUrRSDdZGHUe+rSipiAzk7fbfochq4alORGoAL0LC0 gdTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OAx8om4msRPj0efgRy4jz8RJQnUY3zCFMGdnCfxddyU=; b=ttskMZlglduCZVDrr4LRz4YTrK8josl2SGnk9rSBvceIetzKtakv+5cmsx3SiWePO/ ZzFrO1plXfyG2kmRwp/SS23GDUyV6ndHW51IwboOJYU5SCkDihbh0mAmS0aUTOJ5oFeS WQIVZMaWnnULssrJTk1Uw91MVSlaO2KVHmzstTWw5a6FpjMtuNEX8KIs2wtuKZ19R3eK 7dPG/g3XZvpoqahN4l54GdkXCkiMuBsZcustQ+/bcnv0FA/5LOW9XNWl7oeRowLEoey0 /37VUdzkWU1+BaYV3tCzJg7EcXGtLFE22jrQ+oRvJC+iBQygclPbPbsw8RF9qK2dJcyn Httw== X-Gm-Message-State: AJaThX518RjNnxjg/EyHmTxK+QL9soFmXDQS2yhHIEbidsi2b4QZkGtU xsd57FJ8H5Oo5J/Nc/fRTQ96uzifVRKTAJppQDuv8OwhVIFCAhg2ViW1ec4KsZQ0x07SBOgEUvC T4QQTxye7umKITB5sx0A3GBJzQtj73MjUUqyH7VfNI+iqykH/HE5pZbURb2K9ZPvO6Ent3nm/0G qhSNnpPuVu X-Google-Smtp-Source: AGs4zMYFwcjkJVA47RTpwrAh2TN0GKRNcxWFN8xpSK/khxgxGuCp7Kdph4Uracdf7E9frl17n6F+RQ== X-Received: by 10.28.0.6 with SMTP id 6mr1959948wma.109.1511286472219; Tue, 21 Nov 2017 09:47:52 -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 n64sm2032582wmd.36.2017.11.21.09.47.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 09:47:51 -0800 (PST) Subject: Re: [HACKERS] Custom compression methods To: Ildus Kurbangaliev Cc: pgsql-hackers@postgresql.org References: <20170907194236.4cefce96@wp.localdomain> <20170912175505.4afa11fd@wp.localdomain> <20171102152836.60c041e4@wp.localdomain> <20171114162356.52e3d388@wp.localdomain> <62e46a47-08a8-6e06-5e4f-6f52e0a13202@2ndquadrant.com> <20171121174717.69ecd8f4@wp.localdomain> From: Tomas Vondra Message-ID: Date: Tue, 21 Nov 2017 18:47:49 +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: <20171121174717.69ecd8f4@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, On 11/21/2017 03:47 PM, Ildus Kurbangaliev wrote: > On Mon, 20 Nov 2017 00:04:53 +0100 > Tomas Vondra wrote: > > ... > >> 6) I'm rather confused by AttributeCompression vs. >> ColumnCompression. I mean, attribute==column, right? Of course, one >> is for data from parser, the other one is for internal info. But >> can we make the naming clearer? > > For now I have renamed AttributeCompression to CompressionOptions, > not sure that's a good name but at least it gives less confusion. > I propose to use either CompressionMethodOptions (and CompressionMethodRoutine) or CompressionOptions (and CompressionRoutine) >> >> 7) The docs in general are somewhat unsatisfactory, TBH. For example >> the ColumnCompression has no comments, unlike everything else in >> parsenodes. Similarly for the SGML docs - I suggest to expand them to >> resemble FDW docs >> (https://www.postgresql.org/docs/10/static/fdwhandler.html) which >> also follows the handler/routines pattern. > > I've added more comments. I think I'll add more documentation if the > committers will approve current syntax. > OK. Haven't reviewed this yet. >> >> 8) One of the unclear things if why we even need 'drop' routing. It >> seems that if it's defined DropAttributeCompression does something. >> But what should it do? I suppose dropping the options should be done >> using dependencies (just like we drop columns in this case). >> >> BTW why does DropAttributeCompression mess with att->attisdropped in >> this way? That seems a bit odd. > > 'drop' routine could be useful. An extension could do something > related with the attribute, like remove extra tables or something > else. The compression options will not be removed after unlinking > compression method from a column because there is still be stored > compressed data in that column. > OK. So something like a "global" dictionary used for the column, or something like that? Sure, seems useful and I've been thinking about that, but I think we badly need some extension using that, even if in a very simple way. Firstly, we need a "how to" example, secondly we need some way to test it. >> >> 13) When writing the experimental extension, I was extremely >> confused about the regular varlena headers, custom compression >> headers, etc. In the end I stole the code from tsvector.c and >> whacked it a bit until it worked, but I wouldn't dare to claim I >> understand how it works. >> >> This needs to be documented somewhere. For example postgres.h has >> a bunch of paragraphs about varlena headers, so perhaps it should >> be there? I see the patch tweaks some of the constants, but does >> not update the comment at all. > > This point is good, I'm not sure how this documentation should look > like. I've just assumed that people should have deep undestanding of > varlenas if they're going to compress them. But now it's easy to > make mistake there. Maybe I should add some functions that help to > construct varlena, with different headers. I like the way is how > jsonb is constructed. It uses StringInfo and there are few helper > functions (reserveFromBuffer, appendToBuffer and others). Maybe they > should be not static. > Not sure. My main problem was not understanding how this affects the varlena header, etc. And I had no idea where to look. >> >> Perhaps it would be useful to provide some additional macros >> making access to custom-compressed varlena values easier. Or >> perhaps the VARSIZE_ANY / VARSIZE_ANY_EXHDR / VARDATA_ANY already >> support that? This part is not very clear to me. > > These macros will work, custom compressed varlenas behave like old > compressed varlenas. > OK. But then I don't understand why tsvector.c does things like VARSIZE(data) - VARHDRSZ_CUSTOM_COMPRESSED - arrsize VARRAWSIZE_4B_C(data) - arrsize instead of VARSIZE_ANY_EXHDR(data) - arrsize VARSIZE_ANY(data) - arrsize Seems somewhat confusing. >>> Still it's a problem if the user used for example `SELECT >>> INTO * FROM *` because postgres will copy >>> compressed tuples, and there will not be any dependencies >>> between destination and the options. >>> >> >> This seems like a rather fatal design flaw, though. I'd say we need >> to force recompression of the data, in such cases. Otherwise all >> the dependency tracking is rather pointless. > > Fixed this problem too. I've added recompression for datum that use > custom compression. > Hmmm, it still doesn't work for me. See this: test=# create extension pg_lz4 ; CREATE EXTENSION test=# create table t_lz4 (v text compressed lz4); CREATE TABLE test=# create table t_pglz (v text); CREATE TABLE test=# insert into t_lz4 select repeat(md5(1::text),300); INSERT 0 1 test=# insert into t_pglz select * from t_lz4; INSERT 0 1 test=# drop extension pg_lz4 cascade; NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to compression options for lz4 drop cascades to table t_lz4 column v DROP EXTENSION test=# \c test You are now connected to database "test" as user "user". test=# insert into t_lz4 select repeat(md5(1::text),300);^C test=# select * from t_pglz ; ERROR: cache lookup failed for compression options 16419 That suggests no recompression happened. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services