Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 7214B9FB1DA for ; Mon, 29 Jan 2007 13:21:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 41781-03 for ; Mon, 29 Jan 2007 13:20:53 -0400 (AST) X-Greylist: delayed 00:35:52.257436 by SQLgrey-1.7.4 Received: from ebrsrv01.ebravo.it (host53-205-static.34-85-b.business.telecomitalia.it [85.34.205.53]) by postgresql.org (Postfix) with ESMTP id BCCFE9FB1C6 for ; Mon, 29 Jan 2007 13:20:50 -0400 (AST) Received: from [192.168.11.103] ([192.168.11.103]) by ebrsrv01.ebravo.it (8.11.6/8.12.5) with ESMTP id l0TGiHs30397 for ; Mon, 29 Jan 2007 17:44:17 +0100 Message-ID: <45BE245D.3040006@streppone.it> Date: Mon, 29 Jan 2007 17:44:13 +0100 From: Cosimo Streppone User-Agent: Mozilla Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: Postgresql Performance list Subject: Re: int4 vs varchar to store ip addr References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/408 X-Sequence-Number: 23009 Nicolas wrote: > I have an authorization table that associates 1 customer IP to a service > IP to determine a TTL (used by a radius server). > > table auth > client varchar(15); > service varchar(15); > ttl int4; > client and service are both ip addr. > > The number of distinct clients can be rather large (say around 4 > million) and the number of distinct service around 1000. > > there's a double index on ( client , service ). It comes to mind another solution... I don't know if it is better or worse, but you could give it a try. Store IP addresses as 4 distinct columns, like the following: CREATE TABLE auth ( client_ip1 shortint, client_ip2 shortint, client_ip3 shortint, client_ip4 shortint, service varchar(15), ttl int4, ); And then index by client_ip4/3/2/1, then service. CREATE INDEX auth_i1 ON auth (client_ip4, client_ip3, client_ip2, client_ip1); or: CREATE INDEX auth_i1 ON auth (client_ip4, client_ip3, client_ip2, client_ip1, service); I'm curious to know from pg internals experts if this could be a valid idea or is totally non-sense. Probably the builtin ip4 type is better suited for these tasks? -- Cosimo