segasai / q3c

PostgreSQL extension for spatial indexing on a sphere
GNU General Public License v2.0
77 stars 27 forks source link

Unexpected 'too large' error with q3c_poly_query() #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I have a table (usnob1) and three fields: ra (double), dec (double) and mag 
(real, NULL is allowed).  I've created a q3c index on the table with 
q3c_ang2ipix, and clustered the table on the index.  Up until now, I've used 
many q3c functions on this table with no problems. The usnob1 table has about 
300M rows and takes up ~60GB of disk space.

The crux of the problem is performing a query with q3c_poly_query() in a WHERE 
clause along with another filter on the 'mag' field.  The polygon is quite 
small (~0.25 deg on a side), but I am getting an error:

"ERROR:  The polygon is too large. Polygons having diameter >~23 degrees are 
unsupported"

An example query that causes the problem is:

SELECT ra, dec, mag
FROM usnob1 
WHERE 
q3c_poly_query(
ra, dec, 
{'{49.875,11.875,50.125,11.875,50.125,12.125,49.875,12.125}'}
)
AND 
mag < 20.0
;

If I change the coordinates of the polygon just a little bit (and preserve the 
area of the polygon), the problem goes away (sometimes). The problem seems to 
depend on the properties of the 'mag' field.  For example, if I keep the 
polygon vertices as above, but change the 'mag < 20.0' clause to 'mag > 10.0 , 
then I get rows with no error.  I have not been able to identify the full set 
of conditions on 'mag' that give the 'too large' error. 

If I use a brute force approach by putting constraints on the ra and dec fields 
(e.g. WHERE ra BETWEEN 49.875 AND 50.125, etc.), I get sensible results (but 
the query takes forever).  

What is the expected output? What do you see instead?

I expect to get a list of (~1000) objects from the table that satisfy the WHERE 
clause. Instead, I get the error message:

ERROR:  The polygon is too large. Polygons having diameter >~23 degrees are 
unsupported

********** Error **********

ERROR: The polygon is too large. Polygons having diameter >~23 degrees are 
unsupported
SQL state: XX000

What version of the product are you using? On what operating system?

Postgresql: 8.4.10
q3c: 1.4.12
OS: MacOS 10.6.8

Please provide any additional information below.

Original issue reported on code.google.com by greg.j.m...@gmail.com on 20 Apr 2012 at 5:40

GoogleCodeExporter commented 9 years ago
Hi, 

I've committed a set of changes which probably fix your problem. 
http://code.google.com/p/q3c/source/detail?r=ac0bf1cf8393a5914af3c45ebb3f9f4fcef
8035d
Please test, whether that fixes your problem, because I wasn't able to 
replicate the exact problem your are seeing. 

Cheers,
        Sergey

Original comment by koposov on 23 Apr 2012 at 6:31

GoogleCodeExporter commented 9 years ago
I've ran some tests now and don't get any errors. 

Thanks for the quick fix!

 - Greg

Original comment by greg.j.m...@gmail.com on 24 Apr 2012 at 1:16

GoogleCodeExporter commented 9 years ago

Original comment by koposov on 24 Apr 2012 at 2:26