X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 989EBD970B for ; Mon, 26 Sep 2005 15:43:03 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 66270-05 for ; Mon, 26 Sep 2005 18:42:53 +0000 (GMT) Received: from mx1.surnet.cl (mx2.surnet.cl [216.155.73.181]) by svr1.postgresql.org (Postfix) with ESMTP id 38D01D976D for ; Mon, 26 Sep 2005 15:42:52 -0300 (ADT) Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165]) by mx1.surnet.cl with ESMTP; 26 Sep 2005 14:42:30 -0400 X-IronPort-AV: i="3.97,114,1125892800"; d="scan'208"; a="12207882:sNHT35230056" Received: from alvh.no-ip.org (216.155.71.178) by cluster.surnet.cl (7.0.043) (authenticated as alvherre@surnet.cl) id 4327E85F0015B0E9; Mon, 26 Sep 2005 14:42:52 -0400 Received: by alvh.no-ip.org (Postfix, from userid 1000) id 46597C3A034; Mon, 26 Sep 2005 14:42:53 -0400 (CLT) Date: Mon, 26 Sep 2005 14:42:53 -0400 From: Alvaro Herrera To: Announce Cc: pgsql-performance@postgresql.org Subject: Re: int2 vs int4 in Postgres Message-ID: <20050926184253.GA8295@surnet.cl> Mail-Followup-To: Announce , pgsql-performance@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.10i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.877 required=5 tests=[AWL=0.077, DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376, FORGED_RCVD_HELO=0.05] X-Spam-Level: * X-Archive-Number: 200509/358 X-Sequence-Number: 14666 On Mon, Sep 26, 2005 at 12:54:05PM -0500, Announce wrote: > Is there an performance benefit to using int2 (instead of int4) in cases > where i know i will be well within its numeric range? I want to conserve > storage space and gain speed anywhere i can, but i know some apps simply end > up casting 2byte data to 4byte (like Java int/short). > > These int2 values will be used in primary and foreign key fields and I know > that i must explicitly use tick marks (ex: where int2_column = '12') in > order to make use of indexes, but my question is IS IT WORTH IT? IS THERE > ANY REAL GAIN FOR DOING THIS? > An simple scenario would be: > > Songs > ------- > song_id serial pkey > genre int2 fkey > title varchar Not in this case, because the varchar column that follows the int2 column needs 4-byte alignment, so after the int2 column there must be 2 bytes of padding. If you had two consecutive int2 fields you would save some the space. Or int2/bool/bool (bool has 1-byte alignment), etc. This assumes you are in a tipical x86 environment ... in other environments the situation may be different. -- Alvaro Herrera Valdivia, Chile ICBM: S 39º 49' 17.7", W 73º 14' 26.8" Voy a acabar con todos los humanos / con los humanos yo acabaré voy a acabar con todos / con todos los humanos acabaré (Bender)