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 1okp5O-0005EY-Iz for pgsql-general@arkaria.postgresql.org; Tue, 18 Oct 2022 16:04:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1okp5N-0002G4-Ey for pgsql-general@arkaria.postgresql.org; Tue, 18 Oct 2022 16:04:57 +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 1okp5N-00024z-48 for pgsql-general@lists.postgresql.org; Tue, 18 Oct 2022 16:04:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okp5J-0002nv-0Q for pgsql-general@lists.postgresql.org; Tue, 18 Oct 2022 16:04:56 +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 29IG4mtD2655107; Tue, 18 Oct 2022 12:04:48 -0400 From: Tom Lane To: Dominique Devienne cc: pgsql-general@lists.postgresql.org Subject: Re: byte-size of column values In-reply-to: References: Comments: In-reply-to Dominique Devienne message dated "Tue, 18 Oct 2022 17:51:26 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2655105.1666109088.1@sss.pgh.pa.us> Date: Tue, 18 Oct 2022 12:04:48 -0400 Message-ID: <2655106.1666109088@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dominique Devienne writes: > Hi. I'm surprised by the result for bit(3) and char, when calling > pg_column_size(). > Why 6, instead of 1? The doc does mention 5-8 bytes overhead, but I > expected those for varying bit, not fixed-sized bit typed values. How > come? Your expectation is incorrect. Postgres always treats these types as variable-length, whether or not the column has a length constraint. 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). Because of the popularity of variable-width character encodings, a column declared as N characters wide isn't necessarily a fixed number of bytes wide, making it a lot less useful than you might think to have optimizations for fixed-width storage. Between that and the fact that most Postgres developers regard CHAR(N) as an obsolete hangover from the days of punched cards, no such optimizations have been attempted. regards, tom lane