You might want to try a "not exists" constraint, like this:<div><br></div><div><div>SELECT *</div><div>FROM survey</div><div>WHERE NOT EXISTS </div><div>(SELECT parcel_esri.parcelnum</div><div>FROM parcels_esri WHERE parcel_esri.parcelnum = survey.parcelnum)</div>
<br><div class="gmail_quote">On Sat, Jul 24, 2010 at 2:09 PM, David Epstein <span dir="ltr"><<a href="mailto:davideps@umich.edu">davideps@umich.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I have one spatial table and one non-spatial table each with about 380k<br>
rows. They can be joined by "parcelnum". However, there are some parcel<br>
numbers in each table that do not match. I want the full rows of the<br>
non-matching from each. I've made a standard (b-tree) index for<br>
"parcelnum" in both tables and then ran this query to get non-matching<br>
rows in a single direction:<br>
<br>
SELECT *<br>
FROM survey<br>
WHERE survey.parcelnum NOT IN<br>
(SELECT parcel_esri.parcelnum<br>
FROM parcels_esri)<br>
<br>
This query has already run for 35 minutes and is still running. I have a<br>
laptop running Ubuntu 9.04 64bit with two P8700 2.53GHz CPUs and 3.8GB<br>
of memory. Only 1 CPU and 1.3GB of memory is being used. Is there<br>
anything I can do to speed up not-in (and join) queries?<br>
<br>
thank you,<br>
-david<br>
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</blockquote></div><br></div>