Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 26D4C2E48F8 for ; Fri, 11 Jan 2008 18:02:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 42750-05 for ; Fri, 11 Jan 2008 18:02:37 -0400 (AST) Received: from vms173003pub.verizon.net (vms173003pub.verizon.net [206.46.173.3]) by postgresql.org (Postfix) with ESMTP id B3E642E306E for ; Fri, 11 Jan 2008 18:02:40 -0400 (AST) Received: from osgiliath.mathom.us ([71.178.47.70]) by vms173003.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JUI004J32HMU863@vms173003.mailsrvcs.net> for pgsql-performance@postgresql.org; Fri, 11 Jan 2008 16:00:59 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id 052456E61F for ; Fri, 11 Jan 2008 17:02:38 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id tToOSLFpU2Op for ; Fri, 11 Jan 2008 17:02:36 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id 627541F80E; Fri, 11 Jan 2008 17:02:36 -0500 (EST) Date: Fri, 11 Jan 2008 17:02:36 -0500 From: Michael Stone Subject: Re: Best way to index IP data? In-reply-to: <20080111213710.GD8260@alvh.no-ip.org> To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20080111220235.GX5294@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Virus-Scanned: Debian amavisd-new at mathom.us X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 References: <200801101614.54729.kevin@kevinkempterllc.com> <36e682920801101541o7626bbddj428617144240c554@mail.gmail.com> <13179.1200064791@sss.pgh.pa.us> <20080111162747.GT5294@mathom.us> <24044.1200082058@sss.pgh.pa.us> <20080111212703.GU5294@mathom.us> <20080111213710.GD8260@alvh.no-ip.org> User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/80 X-Sequence-Number: 28319 On Fri, Jan 11, 2008 at 06:37:10PM -0300, Alvaro Herrera wrote: >So what this means is that our type oughta be optimized. How about >having a separate bit to indicate whether there is a netmask or not, and >chop the storage earlier. (I dunno if this already done) Why not just have a type that indicates whether there is a netmask or not? We currently have this (8.3 docs, which I see reflects the 3 byte overhead--down to 20% rather than 50% for IPv6): cidr 7 or 19 bytes IPv4 and IPv6 networks inet 7 or 19 bytes IPv4 and IPv6 hosts and networks Note that there's a type for (networks), and there's a type for (hosts and networks), but there's a conspicuous lack of a type for (hosts). I suppose if you really are sure that you want to store hosts and not networks you should use inet and then set a constraint like if (family() == 4 && masklen() == 32) elsif (family() == 6 && masklen() == 128) (For people whose databases don't resolve around network data, this probably seems like not a big deal. OTOH, I can only imagine the outcry if the only available arithmetic type was an intfloat, which can be either an integer or a real number, has very low overhead to keep track of whether there's a decimal point, and can easily be made to behave like an integer if you set a constraint forbidding fractional parts. Because, hey, you *never know* when you might need a real number, and wouldn't want to paint yourself into a corner by stupidly specifying an integer-only type.) Mike Stone