X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id DEDDDD1B989 for ; Mon, 23 Feb 2004 16:14:22 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 43748-07 for ; Mon, 23 Feb 2004 12:14:19 -0400 (AST) Received: from gp.word-to-the-wise.com (gp.word-to-the-wise.com [64.71.176.18]) by svr1.postgresql.org (Postfix) with ESMTP id 1F2C3D1B9A8 for ; Mon, 23 Feb 2004 12:14:19 -0400 (AST) Received: by gp.word-to-the-wise.com (Postfix, from userid 500) id 52F70900013; Mon, 23 Feb 2004 08:07:34 -0800 (PST) Date: Mon, 23 Feb 2004 08:07:34 -0800 From: Steve Atkins To: pgsql-performance Subject: Re: Slow join using network address function Message-ID: <20040223160734.GA11052@gp.word-to-the-wise.com> References: <000701c3fa02$e4e3d180$c300000a@caliente> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000701c3fa02$e4e3d180$c300000a@caliente> User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/262 X-Sequence-Number: 5786 On Mon, Feb 23, 2004 at 12:48:02PM +0100, Eric Jain wrote: > I'm trying to join two tables on an inet column, where one of the > columns may contain a subnet rather than a single host. Somehow the > operation isn't completing quite fast enough, even though neither table > is very large: > > table | rows > --------------------+-------- > clients | 115472 > clients_commercial | 11670 [snip] > Anything else I could try? BTREE indexes don't seem to work with the <<= > operator; is this not possible in principal, or simply something that > has not been implmented yet? I've been looking at a similar problem for a while. I found that the inet type didn't really give me the flexibility I needed, and indexing it in a way that worked with CIDR blocks didn't seem easy (and maybe not possible). So I rolled my own, based on the seg sample. is a datatype that contains a range of IPv4 addresses, and which has the various operators to make it GIST indexable. Untar it into contrib and make as usual. Input is of the form '10.11.12.13' or '10.11.12.13.0/25' or '10.11.12.13-10.11.12.13.127'. The function display() takes an ipr type and returns it formatted for display (as a dotted-quad if a /32, as CIDR format if possible, as a range of dotted-quads otherwise). A bunch of operators are included, but '&&' returns true if two ipr fields intersect. Bugs include: 0.0.0.0/0 doesn't do what it should on input. No documentation. No cast operators between ipr and inet types. No documentation. I was planning on doing some docs before releasing it, but here it is anyway. Cheers, Steve -- -- Steve Atkins -- steve@blighty.com