-
Notifications
You must be signed in to change notification settings - Fork 22
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
Why is Relation#one only available on sorted relations? #60
Why is Relation#one only available on sorted relations? #60
Comments
I should probably add that I think that there's probably a good reason to have a means of extracting the first tuple in an ordered sequence, but I don't want that to be the only means of getting at one tuple. This also seems related to the fact that DM1 exposed Also, we already have a means of getting at the first tuple in an ordered sequence by doing: |
@snusnu this is a good point. I think the only reason I did that is that I wanted to apply a limit to the relation, since limiting an unordered relation is nondeterministic. However, thinking more about this, I think that I will say that I am using the |
@dkubb I'm not entirely sure i get your last point. By "since they not only do what i want ...", are you referring to In any case, I'm happy we seem to agree that Is there anything I can do to help? |
* Allow #one to be called on unsorted relations [Fix #60]
@snusnu my point was that lots of ORMs give people
It turns out I didn't need to create a special node, and it couldn't really work since |
@dkubb can you elaborate a bit more on |
@dkubb anything i can do to help merging the |
I’ve recently started to question the current implementation of
Axiom::Relation#one
. It currently must be called on a sorted relation, but i actually see no reason for this restriction. Why would i have to do something likerelation.restrict(some_key: value).sort.one
?It’s purpose is to extract one tuple from a relation, and bail out if there is more than one tuple present. I don’t see any necessity for sorting here.
The only reason, it seems, is that when the relation gets compiled to sql, sorting it can prevent from loading shitloads of records by passing a
LIMIT
, which itself is only available on sorted relations. I’m not at all sure tho, if this safety net justifies having to sort everytime i want one tuple. After all, probably the most common usecase is when i know that i get only one result, because i restricted on a key field.I’m having a hard time imagining (frequent) real life queries, where i want to retrieve one tuple, that is not identified by a (candidate) key. If this means that
#one
is potentially expensively loading shitloads of records, then so be it. I’m finding the current behavior too defensive.Please correct me if I'm missing something. Any thoughts are highly appreciated. Thx!
The text was updated successfully, but these errors were encountered: