This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… override Signed-off-by: Zach Musgrave <zach@liquidata.co>
…counted against the limit. Signed-off-by: Zach Musgrave <zach@liquidata.co>
Signed-off-by: Zach Musgrave <zach@liquidata.co>
Signed-off-by: Zach Musgrave <zach@liquidata.co>
Signed-off-by: Zach Musgrave <zach@liquidata.co>
Signed-off-by: Zach Musgrave <zach@liquidata.co>
Signed-off-by: Zach Musgrave <zach@liquidata.co>
634c5e8
to
bc077b1
Compare
Sorry the commit history is so messy here, missed a -s on one of my commits and had to scramble to fix it :p |
erizocosmico
approved these changes
Jun 28, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
juanjux
approved these changes
Jun 28, 2019
kuba--
approved these changes
Jun 28, 2019
Thanks for the review, friends! As soon as you merge this in I have another batch of bug fixes incoming. |
I have been thinking about this and perhaps there could be a simpler solution, which would just be adding the offset node before the limit node. What do you think? |
…en offset and limit nodes. Signed-off-by: Zach Musgrave <zach@liquidata.co>
Good suggestion, Miguel. Much simpler. Please review and merge at your convenience. |
Thanks a lot for the contribution! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this PR, the following query returns no rows on a table with many:
SELECT i FROM mytable LIMIT 1 OFFSET 1;
In fact, no queries combining offset and limit return correct results before this PR.
This is because the parser creates an offset node that wraps a limit node, and the limit node's counter is incremented for every row the offset node skips, so that when the offset node is done skipping rows, the wrapped limit node returns fewer rows than asked for.
The fix is to add the offset to the row count when constructing the limit node. This is much simpler than adding ResetCount() or similar, but has the disadvantage of making the plan slightly more difficult to understand to a naive reader, best illustrated by this modified test, where the limit node has a limit of 7 instead of 2 as expressed in the query:
Also included in this PR, queries with negative limits or offsets now return an error.