Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpJ83-0006QO-Rn for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Jun 2021 23:21:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lpJ81-0000bO-9W for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Jun 2021 23:21:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpJ80-0000b2-6u for pgsql-hackers@lists.postgresql.org; Fri, 04 Jun 2021 23:21:25 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpJ7x-0003zW-5U for pgsql-hackers@postgresql.org; Fri, 04 Jun 2021 23:21:23 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 0DC56133C; Fri, 4 Jun 2021 19:21:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 04 Jun 2021 19:21:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=WrdUI2BnlgJ/7KbyR19Y7WhKu9ZH9TSNXkMIeiJfG+o=; b=fUH7v+G8 z8TX7eBmW4MiSJrK6Um75i0+cDNd5zKmkCxlfdnFt4KoE5tIm1Y62gFlQKVbYojA ZMFHB1zwC0Mj5OIl/u23BlvNBdj2eRQaCXqIOcU6RD8cGJs6cvQzIfDK0cSGg/uX eexDu4JmlhBgcEadZZm3Icmi8lHu+DYkiVYxaaYvXnpI8cYloU5+qVp+VXhin0gR 5U5OOTch3Z6K9n6GQtS7G7wQo7cXVBru/lezRjSheCJcoaSHzSckjuAVCqAO/zkp fQGGymwG0smCruXgKXPC70sMVNb6uoWTcC0R1pvuxd1BNeluLMw7f4dvLsRbUGZF HuMygOiGXpccQA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedtvddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfgjsehmkeerredttddunecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpeevveeitdetgfejheelhfevteevjeehveegffelhfejvdeh ueeuveelhefhueetheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 4 Jun 2021 19:21:15 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id AE2552A0D0C; Fri, 4 Jun 2021 19:21:11 -0400 (-04) Date: Fri, 4 Jun 2021 19:21:11 -0400 From: Alvaro Herrera To: Tom Lane Cc: Michael Paquier , Robert Haas , Dilip Kumar , Andres Freund , pgsql-hackers Subject: Re: Move pg_attribute.attcompression to earlier in struct for reduced size? Message-ID: <202106042321.6jx54yliy2l6@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ibgude2wazjmdkwy" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <449921.1622847060@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ibgude2wazjmdkwy Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2021-Jun-04, Tom Lane wrote: > Alvaro Herrera writes: > > Now, while this patch does seem to work correctly, it raises a number of > > weird cpluspluscheck warnings, which I think are attributable to the > > new macro definitions. I didn't look into it closely, but I suppose it > > should be fixable given sufficient effort: > > Didn't test, but the first one is certainly fixable by adding a cast, > and I guess the others might be as well. I get no warnings with this one. I'm a bit wary of leaving VARDATA_COMPRESSED_GET_EXTSIZE unchanged, but at least nothing in this patch requires a cast there. -- Álvaro Herrera Valdivia, Chile --ibgude2wazjmdkwy Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Reduce-overhead-of-TOAST-recompression-on-table-r.patch" From d1a0b624e316dcd50aabaf21c4ab4de19b15b604 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Fri, 4 Jun 2021 19:09:30 -0400 Subject: [PATCH v2] Reduce overhead of TOAST recompression on table rewrite --- src/backend/access/common/toast_compression.c | 30 --------------- src/include/access/toast_compression.h | 37 ++++++++++++++++++- src/include/postgres.h | 6 +-- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/backend/access/common/toast_compression.c b/src/backend/access/common/toast_compression.c index 9e9d4457ac..38688e7cfc 100644 --- a/src/backend/access/common/toast_compression.c +++ b/src/backend/access/common/toast_compression.c @@ -247,36 +247,6 @@ lz4_decompress_datum_slice(const struct varlena *value, int32 slicelength) #endif } -/* - * Extract compression ID from a varlena. - * - * Returns TOAST_INVALID_COMPRESSION_ID if the varlena is not compressed. - */ -ToastCompressionId -toast_get_compression_id(struct varlena *attr) -{ - ToastCompressionId cmid = TOAST_INVALID_COMPRESSION_ID; - - /* - * If it is stored externally then fetch the compression method id from - * the external toast pointer. If compressed inline, fetch it from the - * toast compression header. - */ - if (VARATT_IS_EXTERNAL_ONDISK(attr)) - { - struct varatt_external toast_pointer; - - VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr); - - if (VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer)) - cmid = VARATT_EXTERNAL_GET_COMPRESS_METHOD(toast_pointer); - } - else if (VARATT_IS_COMPRESSED(attr)) - cmid = VARDATA_COMPRESSED_GET_COMPRESS_METHOD(attr); - - return cmid; -} - /* * CompressionNameToMethod - Get compression method from compression name * diff --git a/src/include/access/toast_compression.h b/src/include/access/toast_compression.h index 9e2c1cbe1a..8756de77d8 100644 --- a/src/include/access/toast_compression.h +++ b/src/include/access/toast_compression.h @@ -13,6 +13,8 @@ #ifndef TOAST_COMPRESSION_H #define TOAST_COMPRESSION_H +#include "access/detoast.h" + /* * GUC support. * @@ -78,8 +80,41 @@ extern struct varlena *lz4_decompress_datum_slice(const struct varlena *value, int32 slicelength); /* other stuff */ -extern ToastCompressionId toast_get_compression_id(struct varlena *attr); extern char CompressionNameToMethod(const char *compression); extern const char *GetCompressionMethodName(char method); + +/* + * Extract compression ID from a varlena. + * + * Returns TOAST_INVALID_COMPRESSION_ID if the varlena is not compressed. + */ +static inline ToastCompressionId +toast_get_compression_id(struct varlena *attr) +{ + ToastCompressionId cmid = TOAST_INVALID_COMPRESSION_ID; + + /* + * If it is stored externally then fetch the compression method id from + * the external toast pointer. If compressed inline, fetch it from the + * toast compression header. + */ + if (VARATT_IS_EXTERNAL_ONDISK(attr)) + { + struct varatt_external toast_pointer; + + VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr); + + if (VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer)) + cmid = VARATT_EXTERNAL_GET_COMPRESS_METHOD(toast_pointer); + } + else if (VARATT_IS_COMPRESSED(attr)) + cmid = VARDATA_COMPRESSED_GET_COMPRESS_METHOD(attr); + + return cmid; +} + + + + #endif /* TOAST_COMPRESSION_H */ diff --git a/src/include/postgres.h b/src/include/postgres.h index 8e02f91108..7437f4dcf3 100644 --- a/src/include/postgres.h +++ b/src/include/postgres.h @@ -365,13 +365,13 @@ typedef struct #define VARDATA_COMPRESSED_GET_EXTSIZE(PTR) \ (((varattrib_4b *) (PTR))->va_compressed.va_tcinfo & VARLENA_EXTSIZE_MASK) #define VARDATA_COMPRESSED_GET_COMPRESS_METHOD(PTR) \ - (((varattrib_4b *) (PTR))->va_compressed.va_tcinfo >> VARLENA_EXTSIZE_BITS) + ((ToastCompressionId) (((varattrib_4b *) (PTR))->va_compressed.va_tcinfo >> VARLENA_EXTSIZE_BITS)) /* Same, when working directly with a struct varatt_external */ #define VARATT_EXTERNAL_GET_EXTSIZE(toast_pointer) \ - ((toast_pointer).va_extinfo & VARLENA_EXTSIZE_MASK) + ((int32) ((toast_pointer).va_extinfo & VARLENA_EXTSIZE_MASK)) #define VARATT_EXTERNAL_GET_COMPRESS_METHOD(toast_pointer) \ - ((toast_pointer).va_extinfo >> VARLENA_EXTSIZE_BITS) + ((ToastCompressionId) ((toast_pointer).va_extinfo >> VARLENA_EXTSIZE_BITS)) #define VARATT_EXTERNAL_SET_SIZE_AND_COMPRESS_METHOD(toast_pointer, len, cm) \ do { \ -- 2.20.1 --ibgude2wazjmdkwy--