Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADQL ORDER BY DISTANCE fails #21

Open
almicol opened this issue Feb 20, 2017 · 1 comment
Open

ADQL ORDER BY DISTANCE fails #21

almicol opened this issue Feb 20, 2017 · 1 comment
Labels

Comments

@almicol
Copy link

almicol commented Feb 20, 2017

I get an error when executing the following query:

SELECT top 10 centroid(s_region), distance(centroid(s_region), point('', 187.48, 2.05))
FROM ivoa.ObsCore
ORDER BY distance(centroid(s_region), point('', 187.48, 2.05))

Without the ORDER BY it works smoothly.

Cheers,
Alberto

@pdowler pdowler added the bug label Jun 6, 2018
@pdowler
Copy link
Member

pdowler commented Jun 6, 2018

At least with postgresql, you can make it work by declaring an alias in the select list and using the alias in the order by....

However, that query has to do a table scan into a temp table so it will always be slow; you can make it faster by setting a limit on the distance that will also use an index to find candidates, say regions within ~5 deg, e.g.:

WHERE 1=INTERSECTS(s_region, circle('', 187.48, 2.05, 5.0))

Techncially, ADQL permits a function call in the order by clause so this is a bug. It could be made to work by detecting the equivalent item in the select list and order by and injecting the alias usage, but I'l not sure I would want to make it work. I don't see a way to make this use a spatial index though... Are you using the library in a TAP service? Which back-end db? How would you optimise query execution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants