Re: Severe performance problems for simple query

From: Matthew <matthew(at)flymine(dot)org>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Severe performance problems for simple query
Date: 2008-04-07 16:27:57
Message-ID: Pine.LNX.4.64.0804071723490.20402@aragorn.flymine.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Mon, 7 Apr 2008, Dimi Paun wrote:
> * bad performance on queries of the form:
> select * from ipTable where ipFrom <= val and val <= ipTo

Oh yes, if you can guarantee that no two entries overlap at all, then
there is a simpler way. Just create a B-tree index on ipFrom as usual,
sort by ipFrom, and LIMIT to the first result:

SELECT blah FROM table_name
WHERE ipFrom <= 42 ORDER BY ipFrom DESC LIMIT 1

This should run *very* quickly. However, if any entries overlap at all
then you will get incorrect results.

Matthew

--
I'm always interested when [cold callers] try to flog conservatories.
Anyone who can actually attach a conservatory to a fourth floor flat
stands a marginally better than average chance of winning my custom.
(Seen on Usenet)

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Heikki Linnakangas 2008-04-07 16:32:22 Re: Severe performance problems for simple query
Previous Message Matthew 2008-04-07 16:19:27 Re: Severe performance problems for simple query