Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ef6ZG-00005s-OZ for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2018 16:09:31 +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 1ef6ZG-0004Wm-9s for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2018 16:09:30 +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 1ef6XS-00081E-0Y for pgsql-hackers@lists.postgresql.org; Fri, 26 Jan 2018 16:07:38 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ef6XM-0003LB-RT for pgsql-hackers@postgresql.org; Fri, 26 Jan 2018 16:07:35 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 71FAE21C1C29; Fri, 26 Jan 2018 19:07:29 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.109] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 063BE21C0757; Fri, 26 Jan 2018 19:07:28 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1516982849; bh=LgiMRblAU9xMANa7c+1a9k7ljZcJT59pdKmXhkGKJk4=; h=Subject:To:References:Cc:From:Date:In-Reply-To; b=D5qKx3BZBvYOCvaDbhuG0npHl6B5jxNpz24KSoJ1N3MhzarIXEYmvsubaXfgc3MXP wbRrb1FmL1HsiMKPS0kWwmTzmKCcKlHtfiBvybC1AfZ3T3P+DeoM76T6Ff6b/d7g4c KdKzN6gT7FTwHQW1wjIF8IMAjLxQ1Z+jIc7SyZE4= Subject: Re: [HACKERS] Custom compression methods To: Ildus Kurbangaliev References: <20171201194859.le5hvnnrjzhxhm2t@alvherre.pgsql> <20171206180716.75ba9ba9@postgrespro.ru> <20171211155555.05ddd2fc@postgrespro.ru> <20171213151818.75a20259@postgrespro.ru> <20171218115431.2b3e29ba@wp.localdomain> <20180115024930.48583c69@hh> <0633c6e5-5328-5c5b-708b-c4409e3fd131@postgrespro.ru> <20180123160454.131ade09@wp.localdomain> <6fd5dea3-8889-c7bb-9df2-79493b2b6ab0@postgrespro.ru> <20180125172457.5967c022@wp.localdomain> Cc: Robert Haas , Alexander Korotkov , Tomas Vondra , Alvaro Herrera , =?UTF-8?B?0JXQstCz0LXQvdC40Lkg0KjQuNGI0LrQuNC9?= , Andres Freund , Oleg Bartunov , Craig Ringer , Peter Eisentraut , PostgreSQL Hackers , Chapman Flack From: Ildar Musin Message-ID: Date: Fri, 26 Jan 2018 19:07:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <20180125172457.5967c022@wp.localdomain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello Ildus, I continue reviewing your patch. Here are some thoughts. 1. When I set column storage to EXTERNAL then I cannot set compression. Seems reasonable: create table test(id serial, msg text); alter table test alter column msg set storage external; alter table test alter column msg set compression pg_lz4; ERROR: storage for "msg" should be MAIN or EXTENDED But if I reorder commands then it's ok: create table test(id serial, msg text); alter table test alter column msg set compression pg_lz4; alter table test alter column msg set storage external; \d+ test Table "public.test" Column | Type | ... | Storage | Compression --------+---------+ ... +----------+------------- id | integer | ... | plain | msg | text | ... | external | pg_lz4 So we could either allow user to set compression settings even when storage is EXTERNAL but with warning or prohibit user to set compression and external storage at the same time. The same thing is with setting storage PLAIN. 2. I think TOAST_COMPRESS_SET_RAWSIZE macro could be rewritten like following to prevent overwriting of higher bits of 'info': ((toast_compress_header *) (ptr))->info = \ ((toast_compress_header *) (ptr))->info & ~RAWSIZEMASK | (len); It maybe does not matter at the moment since it is only used once, but it could save some efforts for other developers in future. In TOAST_COMPRESS_SET_CUSTOM() instead of changing individual bits you may do something like this: #define TOAST_COMPRESS_SET_CUSTOM(ptr) \ do { \ ((toast_compress_header *) (ptr))->info = \ ((toast_compress_header *) (ptr))->info & RAWSIZEMASK | ((uint32) 0x02 << 30) \ } while (0) Also it would be nice if bit flags were explained and maybe replaced by a macro. 3. In AlteredTableInfo, BulkInsertStateData and some functions (eg toast_insert_or_update) there is a hash table used to keep preserved compression methods list per attribute. I think a simple array of List* would be sufficient in this case. 4. In optionListToArray() you can use list_qsort() to sort options list instead of converting it manually into array and then back to a list. 5. Redundunt #includes: In heap.c: #include "access/reloptions.h" In tsvector.c: #include "catalog/pg_type.h" #include "common/pg_lzcompress.h" In relcache.c: #include "utils/datum.h" 6. Just a minor thing: no reason to change formatting in copy.c - heap_insert(resultRelInfo->ri_RelationDesc, tuple, mycid, - hi_options, bistate); + heap_insert(resultRelInfo->ri_RelationDesc, tuple, + mycid, hi_options, bistate); 7. Also in utility.c the extra new line was added which isn't relevant for this patch. 8. In parse_utilcmd.h the 'extern' keyword was removed from transformRuleStmt declaration which doesn't make sense in this patch. 9. Comments. Again, they should be read by a native speaker. So just a few suggestions: toast_prepare_varlena() - comment needed invalidate_amoptions_cache() - comment format doesn't match other functions in the file In htup_details.h: /* tuple contain custom compressed * varlenas */ should be "contains" -- Ildar Musin i.musin@postgrespro.ru