<html>
<head>
<title></title>
<meta name="GENERATOR" content="MSHTML 8.00.6001.18783"></meta>
</head>
<body>
<div>Hallo</div>
<div> </div>
<div>I have been investivating the st_dwithin-function. I have had a feeling that it is not bahaving consequently, and I think I have found en example proving something is wrong.</div>
<div> </div>
<div>The problem is about the bounding-box comparasion. I tdon't think it always is doing things in the right order. Sometimes it does the _st_dwithin before comparing boundingboxes.</div>
<div>At my upset this is always doing it the wrong way. On the dataset Regina has attached to ticket #137 <em>states.backup</em></div>
<div> </div>
<div>if I do:</div>
<div>select a.state, b.state <br />
from (select * from us.states where state != 'Hawaii') <br />
a cross join <br />
(select * from us.states where state = 'Hawaii') b<br />
where a.the_geom && b.the_geom</div>
<div> </div>
<div>I do get a fast answer that there is no match</div>
<div> </div>
<div>but if I use st_dwithin like:</div>
<div><br />
select a.state, b.state <br />
from (select * from us.states where state != 'Hawaii') <br />
a cross join <br />
(select * from us.states where state = 'Hawaii') b<br />
where st_dwithin(a.the_geom, b.the_geom,0)<br />
</div>
<div>it seems to start doing _st_dwithin(a.the_geom, b.the_geom,0) before doing the box-comparasion so I have never waited this out since _st_dwithin will have quite a har time with this dataset.</div>
<div>I find the same behavior in 1.3.6 with postgresql 8.3 as in postgis 1.4 with postgresql 8.4</div>
<div> </div>
<div>I have a feeling that this is happening in som occasions because I sometimes get strange run-times. I think it sometimes do it right at some rows and the wrong way at somerows in big datasets, but that is much harder to prove.</div>
<div> </div>
<div>another thought:</div>
<div>if I run as above </div>
<div>select a.state, b.state <br />
from (select * from us.states where state != 'Hawaii') <br />
a cross join <br />
(select * from us.states where state = 'Hawaii') b<br />
where a.the_geom && b.the_geom</div>
<div> </div>
<div>it takes about 47ms to get the answer</div>
<div>but if I do the same with Alaska instead of Hawaii it takes over 300ms. Alaska is a very much more complex multipolygon but I don't understand why that is afecting when we just ask it to compare the bounding-boxes. Isn't the bboxes already stored with the geometry especially since a have an index on the_geom.</div>
<div>Or is there a boundingbox for each subgeom??, in that case I will use that in the distance-calculations, but I read somewhere that there is room for bbox onsubgeoms but they are not used. Is that the case but it is iterating through them anyway.</div>
<div> </div>
<div>/Nicklas</div>
<div> </div>
<div><br />
</div>
<div> </div>
</body>
</html>