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

Wrong "Order by" #4

Closed
filhodanuvem opened this issue Apr 13, 2014 · 2 comments
Closed

Wrong "Order by" #4

filhodanuvem opened this issue Apr 13, 2014 · 2 comments
Labels

Comments

@filhodanuvem
Copy link
Owner

Order by is wrong :
The "operator" just sorts a page, the result itself.

Eg:.
select author, message from commits

author message
cloudson 1
hgfischer 2
jeanpimentel 3

select author message from commits order by message desc limit 2

author message
hgfischer 2
cloudson 1

It happens because :

  1. gitql executes select author from commits limit 2
  2. it sorts the result page by message field

Why the obvious solution is a bad idea?
Because we would need:

  1. gitql executes select author from commits
  2. it sorts all commits (god, could be a lot of memory)
  3. choose just the two first lines
@vmeurisse
Copy link

Actually, you don't need to sort the full dataset to get the n first sorted.

You can take a look at https://en.wikipedia.org/wiki/Partial_sorting for some ideas.

@filhodanuvem
Copy link
Owner Author

Thanks @vmeurisse ! You are right about partial sorting, Gitql would sort just rows that match with where.
But I am unhappy about memory allocation.

Example:

author message
cloudson 1
cloudson 2
cloudson 3

For now, with select message from commits where author = 'cloudson' limit 2 gitql runs on O(k) - k >= 2 .
With the new solution, gitql always will run on O(n) - n is the total number for rows matched.
And O(k) < O(n) in best case.

I'm thinking that there is no other way.

References:

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