Re: Severe performance problems for simple query

From: Matthew <matthew(at)flymine(dot)org>
To: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Severe performance problems for simple query
Date: 2008-04-07 17:02:52
Message-ID: Pine.LNX.4.64.0804071749580.20402@aragorn.flymine.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Mon, 7 Apr 2008, Heikki Linnakangas wrote:
> In that case, a regular index on (ipFrom, ipTo) should work just fine, and
> that's what he's got. Actually, an index on just ipFrom would probably work
> just as well. The problem is that the planner doesn't know about that special
> relationship between ipFrom and ipTo. Perhaps it could be hinted by
> explicitly specifying "AND ipTo > ipFrom" in the query?

Actually, the problem is that the database doesn't know that the entries
don't overlap. For all it knows, you could have data like this:

0 10
10 20
20 30
... ten million rows later
100000030 100000040
100000040 100000050
0 100000050

So say you wanted to search for the value of 50,000,000. The index on
ipFrom would select five million rows, all of which then have to be
filtered by the constraint on ipTo. Likewise, an index on ipTo would
return five million rows, all of which then have to be filtered by the
constraint on ipFrom. If you just read the index and took the closest
entry to the value, then you would miss out on the last entry which
overlaps with the whole range. An R-tree on both fields will correctly
find the small set of entries that are relevant.

It would be very cool to be able to create an R-tree index that would just
make the original query run fast without needing alteration. I had a look
at this a while back, but it is not currently possible in GiST, because
only one field is handed to the index at a time. So all the current R-tree
implementations require that you generate an object containing the two
values, like the box, and then index that.

Something for 8.4?

Matthew

--
$ rm core
Segmentation Fault (core dumped)

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Albert Cervera Areny 2008-04-07 18:06:14 Re: performance using table partitions in Postgres 8.2.6
Previous Message Janet Jacobsen 2008-04-07 16:57:34 performance using table partitions in Postgres 8.2.6