X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6B4039DC82A for ; Fri, 3 Mar 2006 06:27:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20975-03 for ; Fri, 3 Mar 2006 06:27:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx1.hive.is (scania.ipf.is [85.197.192.147]) by postgresql.org (Postfix) with SMTP id D48359DCCEC for ; Fri, 3 Mar 2006 06:27:02 -0400 (AST) Received: (qmail 70750 invoked by uid 1010); 3 Mar 2006 10:27:19 -0000 Received: from 85.197.216.186 by scania.ipf.is (envelope-from , uid 1009) with qmail-scanner-1.25-st-qms (clamdscan: 0.88/1283. spamassassin: 3.1.0. perlscan: 1.25-st-qms. Clear:RC:1(85.197.216.186):SA:0(-4.1/4.0):. Processed in 0.677543 secs); 03 Mar 2006 10:27:19 -0000 X-Antivirus-HIVE-Mail-From: gnari@hive.is via scania.ipf.is X-Antivirus-HIVE: 1.25-st-qms (Clear:RC:1(85.197.216.186):SA:0(-4.1/4.0):. Processed in 0.677543 secs Process 70741) Received: from dsl-216-186.hive.is (HELO ?192.168.1.34?) (85.197.216.186) by mx1.hive.is with SMTP; 3 Mar 2006 10:27:18 -0000 Subject: Re: Physical column size From: Ragnar To: Paul Mackay Cc: pgsql-general@postgresql.org In-Reply-To: <786c2f6d0603030203m3b7c62a1k6950ceca066dc5ce@mail.gmail.com> References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> <786c2f6d0603030203m3b7c62a1k6950ceca066dc5ce@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Date: Fri, 03 Mar 2006 10:27:59 +0000 Message-Id: <1141381679.18656.141.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.148 required=5 tests=[AWL=0.148] X-Spam-Score: 0.148 X-Spam-Level: X-Archive-Number: 200603/117 X-Sequence-Number: 91982 On fös, 2006-03-03 at 11:03 +0100, Paul Mackay wrote: > Hi, > > I've created a table like this : > CREATE TABLE tmp_A ( > c "char", > i int4 > ); > > And another one > CREATE TABLE tmp_B ( > i int4, > ii int4 > ); > > I then inserted a bit more than 19 million rows in each table (exactly > the same number of rows in each). > > The end result is that the physical size on disk used by table tmp_A > is exactly the same as table tmp_B (as revealed by the > pg_relation_size function) ! Given that a "char" field is supposed to > be 1 byte in size and a int4 4 bytes, shouldn't the tmp_A use a > smaller disk space ? Or is it that any value, whatever the type, > requires at least 4 bytes to be stored ? the int4 needs to be aligned at 4 bytes boundaries, making wasted space after the char. this would probably be the same size: CREATE TABLE tmp_C ( c "char", cc "char", i int4 ); and this would be smaller: CREATE TABLE tmp_D ( c "char", cc "char", ccc "char", ); P.S.: I did not actually check to see if the "char" type needs to be aligned, by I assumed not.