-
Notifications
You must be signed in to change notification settings - Fork 215
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
Add an efficient Count
method to find the number of items in each index.
#83
Comments
I can see how a dedicated txn := db.Txn(false)
it, err := txn.Get("person", "id")
if err != nil {
panic(err)
}
count := 0
for obj := it.Next(); obj != nil; obj = it.Next() {
count += 1
} As for MIN() and MAX() - Unlike in case of However given the right index (e.g. |
There are a few subtleties here. First up It's possible to get the min/max of the keys of any index efficiently already: I'm not sure any further API can make that much simpler. min, _ := db.First(table, index)
max, _ := db.Last(table, index) But if you were thinking the min/max of some numeric field within each object in a table... that's way more involved and not something we support now - only indexes are even in the schema so as Radek said it would only work over numeric fields that were indexed and in that case the methods above should work. Any non-indexed field would require a whole lot more schema handling etc. I think at that point it's best to just iterate the index or maintain summary statistics about the data in a separate table that you updated transactionally with each update. Id say the same for any more complex aggregation - either calculate it yourself by iterating (which is the best we could do internally anyway) or if that's too expensive then de-normalize and keep the stats up to date in another table! I'll change the title of this because I think the count part is reasonable and would be a nice addition but does depend on changes to iradix to do better than Radek's example above of just iterating every time. |
Count
method to find the number of items in each index.
Thanks for the explanation @banks and @radeksimko |
Is there a reason why functions like
COUNT(), MIN()
, etc are not provided?Or is there a way to achieve these using existing functionalities?
The text was updated successfully, but these errors were encountered: