X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id D4AD3D1C4DC for ; Mon, 21 Jul 2003 03:47:27 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 81185-07 for ; Mon, 21 Jul 2003 03:47:27 +0000 (GMT) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id D3360D1C4B7 for ; Mon, 21 Jul 2003 00:47:25 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id h6L3l4L23262; Sun, 20 Jul 2003 23:47:04 -0400 (EDT) From: Bruce Momjian Message-Id: <200307210347.h6L3l4L23262@candle.pha.pa.us> Subject: Re: inet versus text for ip addresses In-Reply-To: <3F05DEA4.5526.6F4CF1C5@localhost> To: Dan Langille Date: Sun, 20 Jul 2003 23:47:04 -0400 (EDT) Cc: pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/301 X-Sequence-Number: 14415 Dan Langille wrote: > The PostgreSQL inet datatype stores an holds an IP host address, and > optionally the identity of the subnet it is in, all in one field. > This requires 12 bytes. > > Using my "random" data of approximately 8000 IP addresses collected > during previous polls, I've found the average length of an IP address > is 13.1 bytes. An integer requires 4 bytes. > > First question: Why not store an option to store just an IP address? > That should require less than the 12 bytes for inet. We store inet and cidr in similar structures, and they are of variable length (4 byte overhead): /* * This is the internal storage format for IP addresses * (both INET and CIDR datatypes): */ typedef struct { unsigned char family; unsigned char bits; unsigned char type; union { unsigned int ipv4_addr; /* network byte order */ /* add IPV6 address type here */ } addr; } inet_struct; /* * Both INET and CIDR addresses are represented within Postgres as varlena * objects, ie, there is a varlena header (basically a length word) in front * of the struct type depicted above. * * Although these types are variable-length, the maximum length * is pretty short, so we make no provision for TOASTing them. */ typedef struct varlena inet; In 7.4, we support IPv6, so they will be even larger. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073