-
Notifications
You must be signed in to change notification settings - Fork 82
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
Sort labels #527
base: main
Are you sure you want to change the base?
Sort labels #527
Conversation
5f89b53
to
164143d
Compare
Setting this to draft because I think if you're sorting on a particular label but don't mention that label in a query we should add a query specifying the label exists. Otherwise the results don't sort on that label. I haven't figured out why. The simple but probably wrong answer is that the sqlite engine ignores the field because it isn't being queried or selected. The more probably correct answer that I haven't worked out is that the So my solution to give the user what they probably expect is for each label that we're sorting on that isn't mentioned in a query, we add an EXISTS query on it. And then I think the answers will be as expected (if not strictly correct from a SQL point of view). This comes from a random result I noticed:
The underlying SQL for the last query:
Getting deeper into the SQL weeds shows why we get the ordering by name:
The last bit of SQL is what we're having sqlite do. Adding an existence test for |
164143d
to
fbc6527
Compare
The key to doing this is if we want to sort on, say, `metadata.labels.foo`, we need to search for all rows with a label of the name `foo` in all the various join tables we create for each label the query references. We ignore nulls by giving them lowest priority using "NULLS LAST" ("NULLS FIRST" if sorting in descending order).
fbc6527
to
2120517
Compare
I implemented "forced selection" in the second commit (
|
If we don't do this -- say we sort on metadata.labels.foo but never make a test on it, the sort resuilts are ignored.
2120517
to
4d212d1
Compare
Last change: I realized that my label-sort command had a sql injection vulnerability -- |
Follow up to #46333: I didn't implement sorting by arbitrary labels.