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

Already on GitHub? Sign in to your account

Using LIMIT/SKIP/ORDER BY with UNION is only applied to the last union set #1879

Closed
wenic opened this Issue Jan 29, 2014 · 8 comments

Comments

Projects
None yet
6 participants

wenic commented Jan 29, 2014

with the following cypher query;

MATCH (movie:com.test.domain.Movie) WHERE NOT (movie)<-[:RATED]-()
RETURN movie, 0.0 AS avgStars
UNION ALL
MATCH (movie:com.test.domain.Movie)<-[r:RATED]-() WITH movie, avg(r.stars) AS avgStars
RETURN movie, avgStars
LIMIT 100

LIMIT is only applied to the result set of the last MATCH, so it will limit the last MATCH to 100 and include what ever rows the first MATCH returns.

Same happens when using SKIP and ORDER BY.

Member

jexp commented Jan 29, 2014

You can apply a separate limit / skip / oder by to the first match too

Contributor

freeeve commented Jan 29, 2014

I think this is a valid feature request that I've been interested in as well. There's no way to apply a limit to the overall query (similarly, you can't aggregate over the UNION, etc.).

wenic commented Jan 29, 2014

sorry, i should have said the expected results would be. As wfreeman says would be good if you could apply the skip, limit, order by to the overall query.

The original issue came across when I tried to make the results pagable, so instead of getting a page of 100 results I got 100+. The issue was more noticeable, for example when you apply order by on the movie.title; the list you get back, the first half is unsorted and the second half is sorted.

So if you apply an order by on the first match as well, what you get back is two ordered lists joined together so you get [(A-Z)(A-Z)] and not the overall [A-Z] list.

Contributor

cleishm commented Jan 29, 2014

Yes, this is a current known limitation in the use of UNION. We'll look at ways to improve it in future.

wenic commented Jan 29, 2014

Thanks, would be good to see it working. Had a read around stackoverflow, but haven't found an alternative query that could do the same thing.

Is this feature is released?

zonito commented Nov 11, 2014

Can we have approx estimation time?

Thanks!

Contributor

cleishm commented Nov 11, 2014

Will track this in #2725

@cleishm cleishm closed this Nov 11, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment