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 1ol9DG-0002zD-D0 for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 13:34:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ol9DF-0000ih-9n for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 13:34:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ol9DE-0000iY-WB for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 13:34:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ol9DC-0006AS-Hn for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 13:34:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 29JDYKjQ2840903; Wed, 19 Oct 2022 09:34:20 -0400 From: Tom Lane To: Dominique Devienne cc: pgsql-general@lists.postgresql.org Subject: Re: byte-size of column values In-reply-to: References: <2655106.1666109088@sss.pgh.pa.us> Comments: In-reply-to Dominique Devienne message dated "Wed, 19 Oct 2022 10:21:02 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2840901.1666186460.1@sss.pgh.pa.us> Date: Wed, 19 Oct 2022 09:34:20 -0400 Message-ID: <2840902.1666186460@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dominique Devienne writes: > On Tue, Oct 18, 2022 at 6:04 PM Tom Lane wrote: >> Thus, there's always a header to store the actual length. That can >> be either 1 or 4 bytes (I think the doc you are looking at might be >> a little out of date on that point). > Even the doc on v15 (or devel) still says 5-to-8. > https://www.postgresql.org/docs/15/datatype-bit.html Oh, if you're thinking about bit rather than string types, that's correct: in addition to the overall-field-width header (1 or 4 bytes) there's a length-in-bits field (always 4 bytes), then the bits themselves. The overall width is clearly insufficient to know how many bits are valid in the last byte, so some additional storage is necessary. This could have been done in a more compact way no doubt, but we aren't likely to change it now. regards, tom lane