BUG #4810: Complex Contains, Bad Performace.

Started by Paul Matthewsalmost 17 years ago3 messagesbugs
Jump to latest
#1Paul Matthews
plm@netspace.net.au

The following bug has been logged online:

Bug reference: 4810
Logged by: Paul Mathews
Email address: plm@netspace.net.au
PostgreSQL version: 8.3.7
Operating system: Linux SuSE 11.0
Description: Complex Contains, Bad Performace.
Details:

Consider a table :
Postcodes
postcode char[4]
boundary polygon
with an GIST index on boundary.

The table contains about 500 postcodes. Each boundary object is very
complicated however. Each one may contain up to 2000 (latitude, longitude)
points.

Despite the existence of the index, postgresql is determined to full table
scan when given.
SELECT
postcode
WHERE
boundary @> point 'x,y';

This is slow. 4m19 for 500 points.

Adding a bounding box to the table:
Postcodes
postcode char[4]
boundary polygon
boxbound box

Allows 500 points to be processed in less than 2 seconds.
SELECT
postcode
WHERE
boxbound @> box( point 'x,y', point 'x,y' ) and
boundary @> point 'x,y';

Issue: For complex polygon contains, users have to write their own bounding
box routines.

Issue: The existence of a GIST index on the boundary polygons is ignored,
despite the horrendous complexity of the polygons.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Paul Matthews (#1)
Re: BUG #4810: Complex Contains, Bad Performace.

"Paul Mathews" <plm@netspace.net.au> writes:

Despite the existence of the index, postgresql is determined to full table
scan when given.
SELECT
postcode
WHERE
boundary @> point 'x,y';

polygon @> point isn't an indexable operator. The indexable operators
for a gist index on polygon are

<<(polygon,polygon)
&<(polygon,polygon)
&&(polygon,polygon)
&>(polygon,polygon)

(polygon,polygon)

~=(polygon,polygon)
@>(polygon,polygon)
<@(polygon,polygon)
&<|(polygon,polygon)
<<|(polygon,polygon)
|>>(polygon,polygon)
|&>(polygon,polygon)
~(polygon,polygon)
@(polygon,polygon)

So it looks like you need to convert the point to a one-point polygon.

regards, tom lane

#3Paul Matthews
plm@netspace.net.au
In reply to: Tom Lane (#2)
Re: BUG #4810: Complex Contains, Bad Performace.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Tom Lane wrote:
<blockquote cite="mid:2470.1242396221@sss.pgh.pa.us" type="cite">
<pre wrap="">"Paul Mathews" <a class="moz-txt-link-rfc2396E" href="mailto:plm@netspace.net.au">&lt;plm@netspace.net.au&gt;</a> writes:
</pre>
<blockquote type="cite">
<pre wrap="">Despite the existence of the index, postgresql is determined to full table
scan when given.
SELECT
postcode
WHERE
boundary @&gt; point 'x,y';
</pre>
</blockquote>
<pre wrap=""><!---->
polygon @&gt; point isn't an indexable operator. The indexable operators
for a gist index on polygon are

&lt;&lt;(polygon,polygon)
&amp;&lt;(polygon,polygon)
&amp;&amp;(polygon,polygon)
&amp;&gt;(polygon,polygon)
&gt;&gt;(polygon,polygon)
~=(polygon,polygon)
@&gt;(polygon,polygon)
&lt;@(polygon,polygon)
&amp;&lt;|(polygon,polygon)
&lt;&lt;|(polygon,polygon)
|&gt;&gt;(polygon,polygon)
|&amp;&gt;(polygon,polygon)
~(polygon,polygon)
@(polygon,polygon)

So it looks like you need to convert the point to a one-point polygon.

regards, tom lane

</pre>
</blockquote>
WHERE<br>
&nbsp;&nbsp; g.boundary @&gt; polygon(box(w.geocode,w.geocode));<br>
<br>
Is there are more convenient, less ugly, way to convert a point to a
polygon?<br>
<br>
</body>
</html>