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.94.2) (envelope-from ) id 1quNkF-000G8T-6O for pgsql-hackers@arkaria.postgresql.org; Sun, 22 Oct 2023 01:59:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1quNkC-00AEBP-V0 for pgsql-hackers@arkaria.postgresql.org; Sun, 22 Oct 2023 01:59:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1quNkC-00AE9M-LA for pgsql-hackers@lists.postgresql.org; Sun, 22 Oct 2023 01:59:09 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1quNkA-001zdv-5I for pgsql-hackers@postgresql.org; Sun, 22 Oct 2023 01:59:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2023062407; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=sk6VexDy839ICBMMuHRSA8z6M8A/jcH+qVxfYe7jvUU=; b=1HZ1y W/bjMnyyy0XhmCFUYpun0alH9iaDsfCQSM74saY313yT02otw1gMEs1MNkofRt9q5Xl7Guepxr9+e nKHDvBFkFOU+cMJ5167CB7rbG/Dny4nLR7txcSEBemx1dO4ojpmsKwEwZ6eqrNQ047y6ulojF+TGO 0x5n3Pxt6b+3EbA7xrosXEeiWEvE7YyCUgXBVRpRzic7O2HIJQJUM8e+ZYfbkO1ulGqh2n//5W87C u/49wfLnrgzGhcD0l6I8gRGB2JIehK5mKvQnzwqmAp6Z0raqmqd0hEWT0ps9gMqtS4xe3QOJz/6Bt p+lZJ3/pE1n6gaKA+vMuAQH9ubemw==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1quNk8-0028mU-1M; Sat, 21 Oct 2023 21:59:04 -0400 Date: Sat, 21 Oct 2023 21:59:04 -0400 From: Bruce Momjian To: Tom Lane Cc: Laurenz Albe , suchithjn22@gmail.com, PostgreSQL-development Subject: Re: The documentation for storage type 'plain' actually allows single byte header Message-ID: References: <167336599095.2667301.15497893107226841625@wrigleys.postgresql.org> <4977c12e127250fe9777ae57f6f5884b8f5c84ae.camel@cybertec.at> <1421365.1696027552@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="u2LQugKEmWTJtBfn" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --u2LQugKEmWTJtBfn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Oct 21, 2023 at 09:56:13PM -0400, Bruce Momjian wrote: > I did some more research. It turns out that the source slot/planSlot is > populating its pg_attribute information via makeTargetEntry() and it > has no concept of a storage type. > > Digging further, I found that we cannot get rid of the the use of > att->attstorage != TYPSTORAGE_PLAIN in macros ATT_IS_PACKABLE and > VARLENA_ATT_IS_PACKABLE macros in src/backend/access/common/heaptuple.c > because there are internal uses of fill_val() that can't handle packed > varlena headers. > > I ended up with a doc patch that adds a C comment about this odd > behavior and removes doc text about PLAIN storage not using packed > headers. Oops, patch attached. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you. --u2LQugKEmWTJtBfn Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="varlena_short.diff" diff --git a/doc/src/sgml/storage.sgml b/doc/src/sgml/storage.sgml index 148fb1b49d..3ea4e5526d 100644 --- a/doc/src/sgml/storage.sgml +++ b/doc/src/sgml/storage.sgml @@ -456,9 +456,7 @@ for storing TOAST-able columns on disk: PLAIN prevents either compression or - out-of-line storage; furthermore it disables use of single-byte headers - for varlena types. - This is the only possible strategy for + out-of-line storage. This is the only possible strategy for columns of non-TOAST-able data types. diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index d6a4ddfd51..c52d40dce0 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -68,7 +68,16 @@ #include "utils/memutils.h" -/* Does att's datatype allow packing into the 1-byte-header varlena format? */ +/* + * Does att's datatype allow packing into the 1-byte-header varlena format? + * While functions that use TupleDescAttr() and assign attstorage = + * TYPSTORAGE_PLAIN cannot use packed varlena headers, functions that call + * TupleDescInitEntry() use typeForm->typstorage (TYPSTORAGE_EXTENDED) and + * can use packed varlena headers, e.g.: + * CREATE TABLE test(a VARCHAR(10000) STORAGE PLAIN); + * INSERT INTO test VALUES (repeat('A',10)); + * This can be verified with pageinspect. + */ #define ATT_IS_PACKABLE(att) \ ((att)->attlen == -1 && (att)->attstorage != TYPSTORAGE_PLAIN) /* Use this if it's already known varlena */ diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c index d65e5625c7..24bad52923 100644 --- a/src/backend/utils/adt/rangetypes.c +++ b/src/backend/utils/adt/rangetypes.c @@ -2608,7 +2608,8 @@ range_contains_elem_internal(TypeCacheEntry *typcache, const RangeType *r, Datum * values into a range object. They are modeled after heaptuple.c's * heap_compute_data_size() and heap_fill_tuple(), but we need not handle * null values here. TYPE_IS_PACKABLE must test the same conditions as - * heaptuple.c's ATT_IS_PACKABLE macro. + * heaptuple.c's ATT_IS_PACKABLE macro. See the comments thare for more + * details. */ /* Does datatype allow packing into the 1-byte-header varlena format? */ --u2LQugKEmWTJtBfn--