Re: int4 vs varchar to store ip addr

From: Cosimo Streppone <cosimo(at)streppone(dot)it>
To: Postgresql Performance list <pgsql-performance(at)postgresql(dot)org>
Subject: Re: int4 vs varchar to store ip addr
Date: 2007-01-29 16:44:13
Message-ID: 45BE245D.3040006@streppone.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Carlos Moreno 2007-01-29 19:47:46 Re: [OT] Very strange postgresql behaviour
Previous Message Florian Weimer 2007-01-29 16:26:42 Re: int4 vs varchar to store ip addr