Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x674l-0002HU-2m for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Sep 2026 13:50:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x674l-00DK1R-10 for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Sep 2026 13:50:27 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x6734-00DFlo-2c for pgsql-hackers@lists.postgresql.org; Mon, 14 Sep 2026 13:48:42 +0000 Received: from mail-wr2-x10.google.com ([2a00:1450:4864:30::10]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x6731-00000000OXS-1LNy for pgsql-hackers@lists.postgresql.org; Mon, 14 Sep 2026 13:48:42 +0000 Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-485b1d2874fso637714f8f.0 for ; Mon, 14 Sep 2026 06:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789393719; x=1789998519; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:content-type :message-id:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AOBX4KwRUNxsneY43kXTxFpLSyguzP5B/t7olJQ3H34=; b=PYf8gZYhkSzlPImID6fFfLDdk5MgHGAIzr0OQKLZKEUxIt5wSGlzCmVPGdVZydDgK1 0CYw88HDoteoMhcFQp9a7/L4S30wbrjLN6Z31lsti7Fly0bsMfPqN/2h25orQtAU+WSV dfKNEQTY576T2WrybltD/jSbA44YvSH0Wij9cxejAmOXnHoMhup8XAykri+EcyK7chpI 610YTDtoI+wj9psa3ZAGctxOdvSw0ISKclGMPzEhy5DGnR0JtJsrA8jHzGgJxY6JnPZX zTqQk26ly1CjewgeMCWxx9QAHKdFLdtoAaq5fUrIHj29QkzrrFMPubyr8Szgymy8eOBi Jf7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789393719; x=1789998519; h=references:to:cc:in-reply-to:date:subject:mime-version:content-type :message-id:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AOBX4KwRUNxsneY43kXTxFpLSyguzP5B/t7olJQ3H34=; b=GpTKHo+esKuL1eQNLBRp/ruD8LvMkNa5uF7hv3oNBbJdNymdvxsmj/vqDfRwflnZpf EY+E8agiP7CTashrMr2DBBJVzgcBz1yXuaNptOXhsZUliguNjOLlt166DmAGb30VqXXc +ecuaz8dPb4Ys0jxIw2SG2YGTjF1gmCLHB4WI5PHoLVPeQNt7mISqroRcWdTi/0YN71R 351UbHUZuwPXCDiGHotsu0Vo2ug8GJz6v2KssC+BwPGs+fM+mVf3VHgzCZmQ2awdJvib W4Mj1fO7vcmJH9V93tO0U2AcgAhmXsMw++Q5knSvpvyyALGQTPMT1oPOi7ZnLEJg9v8k 1+2A== X-Forwarded-Encrypted: i=1; AKwUvBwFAWkuGY6/FQ+qe5aNcsuGalCh1JRb0KM1ibiU90bU06AHpWxso8k54994hTGrCDLSMfWWR+FZvH0iS71d@lists.postgresql.org X-Gm-Message-State: AFuF++mDAUIqkh1gR8E2VTsZTxKoIJEYtCnwnudNQXHYIrxCCE11uxma NQ3Nslo4qYBl57l8pB8mYxDn7Bdu+QItPOj+YzjKRHW2TrwEEXsjCgql X-Gm-Gg: AYBFou2IL7eRJxGYOYrpYh+Cj5ntXIksuozbL48v7ViG1k6i6ivdvznSlRj19B+vMlO PgRQbnvH+j1mCw0PZu4/KZlwCosOw1FlEQ7mwGhAtOfmXFCBrzQ2nnOSG7/lo2aCiFPa4kI5N2G bQPvlrzNj6E+NnUY6+I4fUNmahahHQTCa2w3Zmli/owaYCKxujMI8MwnkhsRmsD1FzSdJZ1XONC B6X9BoAzgUqjfRO63SQPc6G/05CAGdKo/laRtRD1FjqxDs65OoA6Ez3dsJUj5dRQsBlPgqlBcMX YahuS9t12KMCAcH8xUhAXKadZOiPrcec7CHUiLU0cnUTDvHLRvLTblIILo0cpmHZQtS3yX75cka Nz1XxV65n7uphLpq5vbiiG69gzzSqZBAnNSjWkTM3Z3iiYV0VvYeBMx1fSOk+c0GQfQ53fI6yYM HxrYFNClfNzvRxXpYwQzdVHLiEJjXEpHDHJWFmQOvE6v5viLaUlK7+xCLzPKClzo/N94cHRwgUb ARBbG1OiSTKpK0WdhETfSJrn8ECw/YL9mUoG4F9L7ZBKgqeZgk= X-Received: by 2002:a05:600c:1910:b0:49c:e37e:4389 with SMTP id 5b1f17b1804b1-49e7a6573e4mr36058295e9.4.1789393719031; Mon, 14 Sep 2026 06:48:39 -0700 (PDT) Received: from smtpclient.apple (77.79.158.36.dynamic.ufanet.ru. [77.79.158.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49d26c39086sm369281075e9.10.2026.09.14.06.48.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2026 06:48:38 -0700 (PDT) From: Aidar Imamov Message-Id: <45654909-903F-42BD-A767-61B701992DE3@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_7935D01B-E680-4BEE-8996-0A9307F85CA5" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Re: Refactor code around GUC default_toast_compression Date: Mon, 14 Sep 2026 16:48:26 +0300 In-Reply-To: Cc: Chao Li , Ayush Tiwari , Postgres hackers To: Michael Paquier References: <7A329D19-A0F2-4558-A391-6E82699B9BC0@gmail.com> X-Mailer: Apple Mail (2.3864.700.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_7935D01B-E680-4BEE-8996-0A9307F85CA5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On May 11, 2026, at 11:06, Michael Paquier = wrote: >=20 > On Sat, May 02, 2026 at 09:55:30AM +0800, Chao Li wrote: >> Otherwise, a third-party extension that relies on this variable >> could silently misbehave. I understand that a major release is >> allowed to change API/ABI contracts, but a build failure would be >> better than silent misbehavior. Or at least we should document this >> change somewhere. >>=20 >> Would it better to also rename DEFAULT_TOAST_COMPRESSION to = DEFAULT_TOAST_COMPRESSION_GUC. >=20 > After pondering about this point, I think that you are touching > something sensible here, but not for the reason you mention: the _GUC > bits serve no actual purpose and we can keep using attcompression in > the GUC. >=20 >> 3 >> ``` >> +#define TOAST_COMPRESS_PGLZ 0 >> +#define TOAST_COMPRESS_LZ4 1 >> +#define TOAST_COMPRESS_INVALID 2 >> ``` >>=20 >> Now TOAST_COMPRESS_PGLZ is 0, and TOAST_PGLZ_COMPRESSION is >> =E2=80=98p=E2=80=99. When they appear together in the code, it=E2=80=99= s hard to guess which >> is 0 and which is =E2=80=98p=E2=80=99. So, would it better to rename >> TOAST_COMPRESS_PGLZ to TOAST_PGLZ_COMPRESS_ID, and rename >> TOAST_PGLZ_COMPRESSION to TOAST_PGLZ_COMPRESS_METHOD? >=20 > Here as well, I can get some of the confusion. We can just reuse the > same names, with _ID instead. >=20 >> As the switch/default explicitly rejects invalid cmethod, I feel >> slightly better for readability to place "cmid =3D >> MethodToCompressionId(cmethod);" after the switch clause. >=20 > WFM. >=20 > At the end I have the updated version attached, which still does the > job I want it to do, just simpler. >=20 > One extra thing to keep in mind is that we may want to make > CompressionIdIsValid() smarter in the future, especially across > multiple vartag_external or varlena types if the same ID values are > shared across multiple compression methods, but would be simpler after > this patch with all this knowledge kept local to toast_compression.c. > Something similar could be said about toast_compress_datum() at some > point, once/if we get there. Another argument would be to just switch > ToastCompressionId to a uint32 and move the numbers to varatt.h, but > I'd like to be more ambitious. This patch is just my take on the > matter. >=20 > What do you think? > -- > Michael > Hi Michael, I rebased this onto current master (a23ab4862cf). It doesn't apply cleanly anymore =E2=80=94 amcheck picked up the Oid8 TOAST-value-ID = rework (toast_pointer_valueid / OID8_FORMAT) on top of the VARATT_EXTERNAL_IS_COMPRESSED -> VARATT_EXTERNAL_OID_IS_COMPRESSED rename. Both were easy to sort out, and the rebased patch is attached. A couple of small things I noticed while reading through it. 1) varatt.h When the IDs moved here, the comment that used to sit above the ToastCompressionId enum got lost. It was the one warning that these raw bits shouldn't be used to identify a method (that's what TOAST_PGLZ_COMPRESSION etc. are for), and since both are just small integers in C, nothing else stops a mixup. Maybe it'd be worth keeping that note next to the defines (adjusted a bit, since the constants are now above it): * Don't use these values for anything other than understanding the * meaning of the raw bits from a varlena; in particular, if the * goal is to identify a compression method, use the constants * TOAST_PGLZ_COMPRESSION, etc. instead. 2) CompressionNameToMethod() I can see the hardcoded "lz4" next to the #ifndef makes the intent obvious, so it might well be deliberate. But the loop already has the matching registry entry in hand, and keeping the name in exactly one place was kind of the point of the registry. So I wonder whether it'd be cleaner to compare the method and reuse the entry's name =E2=80=94 = the error message then comes from the registry too: #ifndef USE_LZ4 if (toast_compression_registry[i].method =3D=3D = TOAST_LZ4_COMPRESSION) = NO_COMPRESSION_SUPPORT(toast_compression_registry[i].name); #endif 3) %d vs %u cmid is uint32 now, and elsewhere in the tree unsigned ids are generally printed with %u =E2=80=94 these four %d's (detoast.c twice, varlena.c, verify_heapam.c) look like the odd ones out. Would it make sense to switch them to %u? Purely cosmetic, though. 4) toast_internals.h TOAST_COMPRESS_SET_SIZE_AND_COMPRESS_METHOD() uses TOAST_*_COMPRESSION_ID, which now live in varatt.h, but the header doesn't include it =E2=80=94 it only works through transitive includes = today (the only file using the macro happens to get varatt.h via heaptoast.h -> htup_details.h). Maybe add a direct #include "varatt.h" so the header is self-contained? I also wondered about going further and moving the compress/decompress dispatch into the registry (function pointers + a cmid->name lookup). Probably out of scope for this patch, though =E2=80=94 the registry = centralizes the properties, and the dispatch part overlaps with the vartag direction you mention. Just flagging it in case it's worth a follow-up at some point. Regards, Aidar Imamov --Apple-Mail=_7935D01B-E680-4BEE-8996-0A9307F85CA5 Content-Disposition: attachment; filename*0=v3-0001-Refactor-some-code-logic-around-GUC-default_toast-rebase; filename*1=d-master-20260914.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v3-0001-Refactor-some-code-logic-around-GUC-default_toast-rebased-master-20260914.patch" Content-Transfer-Encoding: quoted-printable =46rom=20c42eed3cb1c4cf6052152a6649597ce319cf7000=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Michael=20Paquier=20=0A= Date:=20Mon,=2011=20May=202026=2016:54:04=20+0900=0ASubject:=20[PATCH]=20= Refactor=20some=20code=20logic=20around=20GUC=20= default_toast_compression=0A=0AThis=20commit=20refactors=20the=20code=20= around=20TOAST=20compression=20methods=20so=20as=20we=0Ahave=20a=20= cleaner=20split=20between=20the=20various=20concepts=20related=20to=20= TOAST=0Acompression,=20for:=0A-=20The=20on-disk=20varatt=20values.=0A-=20= The=20catalog=20attribute=20char=20values=20(attcompression).=0A-=20The=20= compression=20method=20names.=0A=0AThe=20knowledge=20of=20each=20= compression=20method=20is=20now=20localized=20in=20a=20single=0A= "registry",=20in=20toast_compression.c,=20with=20a=20set=20of=20routines=20= that=20are=20able=0Ato=20retrieve=20some=20of=20the=20properties.=20=20= The=20goal=20of=20this=20patch=20is=20to=20ease=0Athe=20addition=20of=20= future=20methods.=20=20One=20idea=20would=20be=20split=20the=20on-disk=0A= varatt=20properties=20across=20multiple=20vartags.=0A---=0A=20= contrib/amcheck/verify_heapam.c=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20|=2019=20+---=0A=20src/backend/access/common/detoast.c=20=20=20=20=20=20= =20=20=20=20=20|=20=204=20+-=0A=20= src/backend/access/common/toast_compression.c=20|=2097=20= +++++++++++++++----=0A=20src/backend/access/common/toast_internals.c=20=20= =20|=20=207=20+-=0A=20src/backend/utils/adt/varlena.c=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20|=20=202=20+-=0A=20= src/include/access/toast_compression.h=20=20=20=20=20=20=20=20|=2027=20= ++----=0A=20src/include/varatt.h=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20|=20=209=20++=0A=20= src/tools/pgindent/typedefs.list=20=20=20=20=20=20=20=20=20=20=20=20=20=20= |=20=202=20+-=0A=208=20files=20changed,=20105=20insertions(+),=2062=20= deletions(-)=0A=0Adiff=20--git=20a/contrib/amcheck/verify_heapam.c=20= b/contrib/amcheck/verify_heapam.c=0Aindex=2033b00fa4dc5..4aaed846f0d=20= 100644=0A---=20a/contrib/amcheck/verify_heapam.c=0A+++=20= b/contrib/amcheck/verify_heapam.c=0A@@=20-1792,26=20+1792,11=20@@=20= check_tuple_attribute(HeapCheckContext=20*ctx)=0A=20=0A=20=09if=20= (VARATT_EXTERNAL_OID_IS_COMPRESSED(toast_pointer))=0A=20=09{=0A-=09=09= ToastCompressionId=20cmid;=0A-=09=09bool=09=09valid=20=3D=20false;=0A+=09= =09uint32=09=09cmid;=0A=20=0A=20=09=09/*=20Compressed=20attributes=20= should=20have=20a=20valid=20compression=20method=20*/=0A=20=09=09cmid=20= =3D=20TOAST_COMPRESS_METHOD(&toast_pointer);=0A-=09=09switch=20(cmid)=0A= -=09=09{=0A-=09=09=09=09/*=20List=20of=20all=20valid=20compression=20= method=20IDs=20*/=0A-=09=09=09case=20TOAST_PGLZ_COMPRESSION_ID:=0A-=09=09= =09case=20TOAST_LZ4_COMPRESSION_ID:=0A-=09=09=09=09valid=20=3D=20true;=0A= -=09=09=09=09break;=0A-=0A-=09=09=09=09/*=20Recognized=20but=20invalid=20= compression=20method=20ID=20*/=0A-=09=09=09case=20= TOAST_INVALID_COMPRESSION_ID:=0A-=09=09=09=09break;=0A-=0A-=09=09=09=09= /*=20Intentionally=20no=20default=20here=20*/=0A-=09=09}=0A-=09=09if=20= (!valid)=0A+=09=09if=20(!CompressionIdIsValid(cmid))=0A=20=09=09=09= report_corruption(ctx,=0A=20=09=09=09=09=09=09=09=20=20psprintf("toast=20= value=20"=20OID8_FORMAT=20"=20has=20invalid=20compression=20method=20id=20= %d",=0A=20=09=09=09=09=09=09=09=09=09=20=20=20toast_pointer_valueid,=20= cmid));=0Adiff=20--git=20a/src/backend/access/common/detoast.c=20= b/src/backend/access/common/detoast.c=0Aindex=20a50aea7b6b1..15d8aa8b5a8=20= 100644=0A---=20a/src/backend/access/common/detoast.c=0A+++=20= b/src/backend/access/common/detoast.c=0A@@=20-470,7=20+470,7=20@@=20= toast_fetch_datum_slice(varlena=20*attr,=20int32=20sliceoffset,=0A=20= static=20varlena=20*=0A=20toast_decompress_datum(varlena=20*attr)=0A=20{=0A= -=09ToastCompressionId=20cmid;=0A+=09uint32=09=09cmid;=0A=20=0A=20=09= Assert(VARATT_IS_COMPRESSED(attr));=0A=20=0A@@=20-502,7=20+502,7=20@@=20= toast_decompress_datum(varlena=20*attr)=0A=20static=20varlena=20*=0A=20= toast_decompress_datum_slice(varlena=20*attr,=20int32=20slicelength)=0A=20= {=0A-=09ToastCompressionId=20cmid;=0A+=09uint32=09=09cmid;=0A=20=0A=20=09= Assert(VARATT_IS_COMPRESSED(attr));=0A=20=0Adiff=20--git=20= a/src/backend/access/common/toast_compression.c=20= b/src/backend/access/common/toast_compression.c=0Aindex=20= 3b1bd651926..74822e64374=20100644=0A---=20= a/src/backend/access/common/toast_compression.c=0A+++=20= b/src/backend/access/common/toast_compression.c=0A@@=20-31,6=20+31,27=20= @@=20int=09=09=09default_toast_compression=20=3D=20= DEFAULT_TOAST_COMPRESSION;=0A=20=09=09=09=20errmsg("compression=20method=20= %s=20not=20supported",=20method),=20\=0A=20=09=09=09=20errdetail("This=20= functionality=20requires=20the=20server=20to=20be=20built=20with=20%s=20= support.",=20method)))=0A=20=0A+/*=0A+=20*=20Compression=20Method=20= Registry=20for=20TOAST.=0A+=20*=0A+=20*=20This=20holds=20the=20metadata=20= associated=20to=20each=20compression=20method=20supported=0A+=20*=20by=20= TOAST:=20name,=20values=20in=20attcompression,=20and=20on-disk=20= compression=20ID=0A+=20*=20values=20in=20varlenas.=0A+=20*/=0A+typedef=20= struct=20ToastCompressionRegistryEntry=0A+{=0A+=09const=20char=20*name;=09= =09=09/*=20method=20name=20*/=0A+=09char=09=09method;=09=09=09/*=20= attcompression=20*/=0A+=09uint32=09=09cmid;=09=09=09/*=20varlena=20= on-disk=20ID=20*/=0A+}=20ToastCompressionRegistryEntry;=0A+=0A+static=20= const=20ToastCompressionRegistryEntry=20toast_compression_registry[]=20=3D= =20{=0A+=09{"pglz",=20TOAST_PGLZ_COMPRESSION,=20= TOAST_PGLZ_COMPRESSION_ID},=0A+=09{"lz4",=20TOAST_LZ4_COMPRESSION,=20= TOAST_LZ4_COMPRESSION_ID},=0A+};=0A+=0A+#define=20TOAST_NUM_COMPRESSIONS=09= lengthof(toast_compression_registry)=0A+=0A=20/*=0A=20=20*=20Compress=20= a=20varlena=20using=20PGLZ.=0A=20=20*=0A@@=20-250,10=20+271,10=20@@=20= lz4_decompress_datum_slice(const=20varlena=20*value,=20int32=20= slicelength)=0A=20=20*=0A=20=20*=20Returns=20= TOAST_INVALID_COMPRESSION_ID=20if=20the=20varlena=20is=20not=20= compressed.=0A=20=20*/=0A-ToastCompressionId=0A+uint32=0A=20= toast_get_compression_id(varlena=20*attr)=0A=20{=0A-=09= ToastCompressionId=20cmid=20=3D=20TOAST_INVALID_COMPRESSION_ID;=0A+=09= uint32=09=09cmid=20=3D=20TOAST_INVALID_COMPRESSION_ID;=0A=20=0A=20=09/*=0A= =20=09=20*=20If=20it=20is=20stored=20externally=20then=20fetch=20the=20= compression=20method=20id=20from=0A@@=20-278,39=20+299,79=20@@=20= toast_get_compression_id(varlena=20*attr)=0A=20/*=0A=20=20*=20= CompressionNameToMethod=20-=20Get=20compression=20method=20from=20= compression=20name=0A=20=20*=0A-=20*=20Search=20in=20the=20available=20= built-in=20methods.=20=20If=20the=20compression=20not=20found=0A-=20*=20= in=20the=20built-in=20methods=20then=20return=20= InvalidCompressionMethod.=0A+=20*=20Search=20the=20compression=20= registry=20by=20name.=20=20If=20the=20method=20name=20is=20not=20found=0A= +=20*=20then=20return=20InvalidCompressionMethod.=0A=20=20*/=0A=20char=0A= =20CompressionNameToMethod(const=20char=20*compression)=0A=20{=0A-=09if=20= (strcmp(compression,=20"pglz")=20=3D=3D=200)=0A-=09=09return=20= TOAST_PGLZ_COMPRESSION;=0A-=09else=20if=20(strcmp(compression,=20"lz4")=20= =3D=3D=200)=0A+=09for=20(int=20i=20=3D=200;=20i=20<=20= TOAST_NUM_COMPRESSIONS;=20i++)=0A=20=09{=0A+=09=09if=20= (strcmp(compression,=20toast_compression_registry[i].name)=20=3D=3D=200)=0A= +=09=09{=0A=20#ifndef=20USE_LZ4=0A-=09=09NO_COMPRESSION_SUPPORT("lz4");=0A= +=09=09=09if=20(strcmp(compression,=20"lz4")=20=3D=3D=200)=0A+=09=09=09=09= NO_COMPRESSION_SUPPORT("lz4");=0A=20#endif=0A-=09=09return=20= TOAST_LZ4_COMPRESSION;=0A+=09=09=09return=20= toast_compression_registry[i].method;=0A+=09=09}=0A=20=09}=0A=20=0A=20=09= return=20InvalidCompressionMethod;=0A=20}=0A=20=0A=20/*=0A-=20*=20= GetCompressionMethodName=20-=20Get=20compression=20method=20name=0A+=20*=20= GetCompressionMethodName=0A+=20*=0A+=20*=20Get=20compression=20method=20= name,=20based=20on=20a=20compression=20method=20char,=20or=0A+=20*=20= attcompression.=0A=20=20*/=0A=20const=20char=20*=0A=20= GetCompressionMethodName(char=20method)=0A=20{=0A-=09switch=20(method)=0A= +=09for=20(int=20i=20=3D=200;=20i=20<=20TOAST_NUM_COMPRESSIONS;=20i++)=0A= +=09{=0A+=09=09if=20(toast_compression_registry[i].method=20=3D=3D=20= method)=0A+=09=09=09return=20toast_compression_registry[i].name;=0A+=09}=0A= +=0A+=09elog(ERROR,=20"invalid=20compression=20method=20%c",=20method);=0A= +=09return=20NULL;=09=09=09=09/*=20keep=20compiler=20quiet=20*/=0A+}=0A+=0A= +/*=0A+=20*=20MethodToCompressionId=0A+=20*=0A+=20*=20Translate=20a=20= catalog=20compression=20method=20char=20(attcompression)=20to=20the=0A+=20= *=20corresponding=20on-disk=20varatt=20ID.=0A+=20*/=0A+uint32=0A= +MethodToCompressionId(char=20method)=0A+{=0A+=09for=20(int=20i=20=3D=20= 0;=20i=20<=20TOAST_NUM_COMPRESSIONS;=20i++)=0A+=09{=0A+=09=09if=20= (toast_compression_registry[i].method=20=3D=3D=20method)=0A+=09=09=09= return=20toast_compression_registry[i].cmid;=0A+=09}=0A+=0A+=09= elog(ERROR,=20"invalid=20compression=20method=20%c",=20method);=0A+=09= return=20TOAST_INVALID_COMPRESSION_ID;=09/*=20keep=20compiler=20quiet=20= */=0A+}=0A+=0A+/*=0A+=20*=20CompressionIdIsValid=0A+=20*=0A+=20*=20Check=20= whether=20a=20compression=20ID=20is=20registered.=20=20Returns=20true=20= if=20the=0A+=20*=20ID=20corresponds=20to=20a=20known=20compression=20= method,=20false=20otherwise.=0A+=20*/=0A+bool=0A= +CompressionIdIsValid(uint32=20cmid)=0A+{=0A+=09for=20(int=20i=20=3D=20= 0;=20i=20<=20TOAST_NUM_COMPRESSIONS;=20i++)=0A=20=09{=0A-=09=09case=20= TOAST_PGLZ_COMPRESSION:=0A-=09=09=09return=20"pglz";=0A-=09=09case=20= TOAST_LZ4_COMPRESSION:=0A-=09=09=09return=20"lz4";=0A-=09=09default:=0A-=09= =09=09elog(ERROR,=20"invalid=20compression=20method=20%c",=20method);=0A= -=09=09=09return=20NULL;=09=09/*=20keep=20compiler=20quiet=20*/=0A+=09=09= if=20(toast_compression_registry[i].cmid=20=3D=3D=20cmid)=0A+=09=09=09= return=20true;=0A=20=09}=0A+=0A+=09return=20false;=0A=20}=0Adiff=20--git=20= a/src/backend/access/common/toast_internals.c=20= b/src/backend/access/common/toast_internals.c=0Aindex=20= ca5ed8dfabc..bf9dbd8d623=20100644=0A---=20= a/src/backend/access/common/toast_internals.c=0A+++=20= b/src/backend/access/common/toast_internals.c=0A@@=20-47,7=20+47,7=20@@=20= toast_compress_datum(Datum=20value,=20char=20cmethod)=0A=20{=0A=20=09= varlena=20=20=20=20*tmp=20=3D=20NULL;=0A=20=09int32=09=09valsize;=0A-=09= ToastCompressionId=20cmid=20=3D=20TOAST_INVALID_COMPRESSION_ID;=0A+=09= uint32=09=09cmid=20=3D=20TOAST_INVALID_COMPRESSION_ID;=0A=20=0A=20=09= Assert(!VARATT_IS_EXTERNAL(DatumGetPointer(value)));=0A=20=09= Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));=0A@@=20-65,11=20= +65,9=20@@=20toast_compress_datum(Datum=20value,=20char=20cmethod)=0A=20=09= {=0A=20=09=09case=20TOAST_PGLZ_COMPRESSION:=0A=20=09=09=09tmp=20=3D=20= pglz_compress_datum((const=20varlena=20*)=20DatumGetPointer(value));=0A-=09= =09=09cmid=20=3D=20TOAST_PGLZ_COMPRESSION_ID;=0A=20=09=09=09break;=0A=20=09= =09case=20TOAST_LZ4_COMPRESSION:=0A=20=09=09=09tmp=20=3D=20= lz4_compress_datum((const=20varlena=20*)=20DatumGetPointer(value));=0A-=09= =09=09cmid=20=3D=20TOAST_LZ4_COMPRESSION_ID;=0A=20=09=09=09break;=0A=20=09= =09default:=0A=20=09=09=09elog(ERROR,=20"invalid=20compression=20method=20= %c",=20cmethod);=0A@@=20-78,6=20+76,9=20@@=20toast_compress_datum(Datum=20= value,=20char=20cmethod)=0A=20=09if=20(tmp=20=3D=3D=20NULL)=0A=20=09=09= return=20PointerGetDatum(NULL);=0A=20=0A+=09/*=20translate=20= attcompression=20to=20the=20on-disk=20compression=20ID=20*/=0A+=09cmid=20= =3D=20MethodToCompressionId(cmethod);=0A+=0A=20=09/*=0A=20=09=20*=20We=20= recheck=20the=20actual=20size=20even=20if=20compression=20reports=20= success,=20because=0A=20=09=20*=20it=20might=20be=20satisfied=20with=20= having=20saved=20as=20little=20as=20one=20byte=20in=20the=0Adiff=20--git=20= a/src/backend/utils/adt/varlena.c=20b/src/backend/utils/adt/varlena.c=0A= index=204533dac11a6..ae09f45fdbf=20100644=0A---=20= a/src/backend/utils/adt/varlena.c=0A+++=20= b/src/backend/utils/adt/varlena.c=0A@@=20-4208,7=20+4208,7=20@@=20= pg_column_compression(PG_FUNCTION_ARGS)=0A=20{=0A=20=09int=09=09=09= typlen;=0A=20=09char=09=20=20=20*result;=0A-=09ToastCompressionId=20= cmid;=0A+=09uint32=09=09cmid;=0A=20=0A=20=09/*=20On=20first=20call,=20= get=20the=20input=20type's=20typlen,=20and=20save=20at=20*fn_extra=20*/=0A= =20=09if=20(fcinfo->flinfo->fn_extra=20=3D=3D=20NULL)=0Adiff=20--git=20= a/src/include/access/toast_compression.h=20= b/src/include/access/toast_compression.h=0Aindex=20= 3265f10b734..433a33467b0=20100644=0A---=20= a/src/include/access/toast_compression.h=0A+++=20= b/src/include/access/toast_compression.h=0A@@=20-22,25=20+22,6=20@@=0A=20= =20*/=0A=20extern=20PGDLLIMPORT=20int=20default_toast_compression;=0A=20=0A= -/*=0A-=20*=20Built-in=20compression=20method=20ID.=20=20The=20toast=20= compression=20header=20will=20store=0A-=20*=20this=20in=20the=20first=20= 2=20bits=20of=20the=20raw=20length.=20=20These=20built-in=20compression=0A= -=20*=20method=20IDs=20are=20directly=20mapped=20to=20the=20built-in=20= compression=20methods.=0A-=20*=0A-=20*=20Don't=20use=20these=20values=20= for=20anything=20other=20than=20understanding=20the=20meaning=0A-=20*=20= of=20the=20raw=20bits=20from=20a=20varlena;=20in=20particular,=20if=20= the=20goal=20is=20to=20identify=0A-=20*=20a=20compression=20method,=20= use=20the=20constants=20TOAST_PGLZ_COMPRESSION,=20etc.=0A-=20*=20below.=20= We=20might=20someday=20support=20more=20than=204=20compression=20= methods,=20but=0A-=20*=20we=20can=20never=20have=20more=20than=204=20= values=20in=20this=20enum,=20because=20there=20are=0A-=20*=20only=202=20= bits=20available=20in=20the=20places=20where=20this=20is=20stored.=0A-=20= */=0A-typedef=20enum=20ToastCompressionId=0A-{=0A-=09= TOAST_PGLZ_COMPRESSION_ID=20=3D=200,=0A-=09TOAST_LZ4_COMPRESSION_ID=20=3D=20= 1,=0A-=09TOAST_INVALID_COMPRESSION_ID=20=3D=202,=0A-}=20= ToastCompressionId;=0A-=0A=20/*=0A=20=20*=20Built-in=20compression=20= methods.=20=20pg_attribute=20will=20store=20these=20in=20the=0A=20=20*=20= attcompression=20column.=20=20In=20attcompression,=20= InvalidCompressionMethod=0A@@=20-75,8=20+56,14=20@@=20extern=20varlena=20= *lz4_decompress_datum_slice(const=20varlena=20*value,=0A=20=09=09=09=09=09= =09=09=09=09=09=20=20=20int32=20slicelength);=0A=20=0A=20/*=20other=20= stuff=20*/=0A-extern=20ToastCompressionId=20= toast_get_compression_id(varlena=20*attr);=0A+extern=20uint32=20= toast_get_compression_id(varlena=20*attr);=0A=20extern=20char=20= CompressionNameToMethod(const=20char=20*compression);=0A=20extern=20= const=20char=20*GetCompressionMethodName(char=20method);=0A=20=0A+/*=0A+=20= *=20Registry=20translation=20functions.=20=20"cmid"=20is=20the=20on-disk=20= varatt=20value.=0A+=20*/=0A+extern=20uint32=20MethodToCompressionId(char=20= method);=0A+extern=20bool=20CompressionIdIsValid(uint32=20cmid);=0A+=0A=20= #endif=09=09=09=09=09=09=09/*=20TOAST_COMPRESSION_H=20*/=0Adiff=20--git=20= a/src/include/varatt.h=20b/src/include/varatt.h=0Aindex=20= 89b47db0833..0de641fce47=20100644=0A---=20a/src/include/varatt.h=0A+++=20= b/src/include/varatt.h=0A@@=20-49,6=20+49,15=20@@=20= StaticAssertDecl((sizeof(int32)=20+=20sizeof(uint32)=20+=202=20*=20= sizeof(Oid))=20=3D=3D=0A=20#define=20VARLENA_EXTSIZE_BITS=0930=0A=20= #define=20VARLENA_EXTSIZE_MASK=09((1U=20<<=20VARLENA_EXTSIZE_BITS)=20-=20= 1)=0A=20=0A+/*=0A+=20*=20On-disk=20compression=20method=20IDs=20stored=20= in=20the=20high=20bits=20of=20va_tcinfo=0A+=20*=20and=20va_extinfo.=20=20= Only=202=20bits=20are=20available,=20so=20at=20most=204=20values=20= should=0A+=20*=20be=20used=20here.=0A+=20*/=0A+#define=20= TOAST_PGLZ_COMPRESSION_ID=09=090=0A+#define=20TOAST_LZ4_COMPRESSION_ID=09= =091=0A+#define=20TOAST_INVALID_COMPRESSION_ID=092=0A+=0A=20/*=0A=20=20*=20= varatt_indirect=20is=20a=20"TOAST=20pointer"=20representing=20an=20= out-of-line=0A=20=20*=20Datum=20that's=20stored=20in=20memory,=20not=20= in=20an=20external=20toast=20relation.=0Adiff=20--git=20= a/src/tools/pgindent/typedefs.list=20b/src/tools/pgindent/typedefs.list=0A= index=20db45ee8881e..b580ffd385a=20100644=0A---=20= a/src/tools/pgindent/typedefs.list=0A+++=20= b/src/tools/pgindent/typedefs.list=0A@@=20-3207,7=20+3207,7=20@@=20= TimingClockSourceType=0A=20TmFromChar=0A=20TmToChar=0A=20ToastAttrInfo=0A= -ToastCompressionId=0A+ToastCompressionRegistryEntry=0A=20= ToastTupleContext=0A=20ToastedAttribute=0A=20TocEntry=0A--=20=0A2.47.1=0A= =0A= --Apple-Mail=_7935D01B-E680-4BEE-8996-0A9307F85CA5--