X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 3D723B439FE for ; Sat, 5 Jul 2003 00:08:13 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 59238-09 for ; Fri, 4 Jul 2003 21:08:02 -0300 (ADT) Received: from bast.unixathome.org (bast.unixathome.org [66.11.174.150]) by svr1.postgresql.org (Postfix) with ESMTP id 2354CB439FC for ; Fri, 4 Jul 2003 21:08:02 -0300 (ADT) Received: from wocker (wocker.unixathome.org [192.168.0.99]) by bast.unixathome.org (Postfix) with ESMTP id E903C3D29 for ; Fri, 4 Jul 2003 20:08:04 -0400 (EDT) From: "Dan Langille" To: pgsql-sql@postgresql.org Date: Fri, 04 Jul 2003 20:08:04 -0400 MIME-Version: 1.0 Subject: inet versus text for ip addresses Message-ID: <3F05DEA4.5526.6F4CF1C5@localhost> X-mailer: Pegasus Mail for Windows (v4.02a) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Archive-Number: 200307/51 X-Sequence-Number: 14165 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. On to the real question: The existing tables are: create table recount_ips ( ipid serial not null, ipaddress inet not null, primary key (ipid) ); create unique index recount_ips_ip_address on recount_ips (ipaddress); create table recount_iptopolls ( pollid integer not null, ipid integer not null, primary key (pollid, ipid) ); alter table recount_iptopolls add foreign key (pollid) references recount_polls (pollid) on update restrict on delete restrict; alter table recount_iptopolls add foreign key (ipid) references recount_ips (ipid) on update restrict on delete restrict; I think a better solution is one table: create table recount_iptopolls ( pollid integer not null, ipaddress inet not null, primary key (pollid, ipaddress) ); alter table recount_iptopolls add foreign key (pollid) references recount_polls (pollid) on update restrict on delete restrict; It removes a table and the associated primary key, and removed a foreign key from the modified recount_iptopolls table. Comments? -- Dan Langille : http://www.langille.org/