#3524 closed defect (fixed)
ST_Distance for geography should be cancellable
Reported by: | robe | Owned by: | pramsey |
---|---|---|---|
Priority: | high | Milestone: | PostGIS 2.2.3 |
Component: | postgis | Version: | 2.2.x |
Keywords: | Cc: |
Description (last modified by )
My server seems pretty frozen computing these and it's still trying to compute the distance between these two countries and it's been 15 minutes already.
After about 17 minutes of waiting I decided to just cancel the query and the query would not cancel even after 7 minutes of waiting. Then I tried to pg_terminate_backend it, and that still did not work. So I had to finally end up killing my service entirely.
I know they are big but really? I should at least be able to cancel.
We were testing on 2.2.1, but decided to also test on 2.1.8 (postgresql 9.4). Same issue on both.
Us has 36054 points and Russia has 36352
Query is as follows:
SELECT ST_Distance(a.geog, b.geog) FROM (SELECT geom::geography As geog, ST_NPoints(geom) As npoints FROM ur_test WHERE name = 'United States') AS a , (SELECT geom::geography AS geog, ST_NPoints(geom) As npoints FROM ur_test WHERE name = 'Russia') AS b
Casting to geography is quick. Doing distance on geometry I think was about 2 seconds.
Attachments (1)
Change History (10)
by , 9 years ago
Attachment: | ur_test.sql added |
---|
comment:1 by , 9 years ago
Description: | modified (diff) |
---|
comment:2 by , 9 years ago
comment:3 by , 9 years ago
Okay it finally returned an answer, so I guess it really does take that long to figure out how far these political boundaries are. Still it should be a cancellable/interruptable operation.
Final answer - 3987.91690476 in (1 hr, 54 minutes, 36 seconds)
comment:4 by , 9 years ago
Summary: | Getting distance between united States and Russia in geography hangs up the server → ST_Distance for geography should be cancellable |
---|
comment:5 by , 9 years ago
So, "yes" to interruptible, I'll do that right away. It's easy to see why it takes forever: with the first, uncached call happening in the "brute force" algorithm, you get 36K x 36K edge-edge distance calculations, which is... a lot 1.2B. So it takes a while. Running the tree-based calculation, I get a result in a under a second (and that's with four calculations!):
postgis23=# select _st_distancetree(a.geog, b.geog) from ur_test_g a, ur_test_g b; _st_distancetree ------------------ 0 3987.916904757 3987.916904757 0 (4 rows) Time: 801.691 ms
So that maybe argues for forgoing the brute force calculation altogether and just using the tree every time. (Although we have other tickets that still show failure cases in the tree, compared to the brute force, in terms of correct results.)
comment:6 by , 9 years ago
Wow that's a big improvement. Is there the same issue with the geometry ST_Distance? My ST_Distance on geometry was 2 seconds (I think 1.8 to be exact) which is even slower than your new geography answer.
comment:7 by , 9 years ago
Well, if we *had* a tree-based distance query for geometry (I still have my 1/2 built one) it could be quite a bit faster too, at least for these really large inputs.
comment:8 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:9 by , 9 years ago
Milestone: | PostGIS 2.1.9 → PostGIS 2.2.3 |
---|
np 2.1 is dead to me :)
So I will consider this closed and move on.
For more fun, I decided to see what would happen if I simplified. Took 15:31 minutes to complete and returned an answer of 4434.16000.
I also started the old unsimplified running, after 1 hr, 38 minutes and 36 seconds, I still have no idea how far Russia is from US. I'll keep it running because I really want to know now.