You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think at the moment the filter with the get is the most efficient one. At least I cannot think of a more efficient alternative. I suspect that the outer join that @thelinuxlich describes is also going to be a bit slower than the filter(other.get.ne(null)).
I would have thought that loading 4K keys into a hashmap upfront and doing lookups against that would have been significantly faster than calling .get() 1.7M times. @danielmewes any insight into this?
Aside from that, my questions have been answered so feel free to close this in favor of #2720.
@marshall007 Ah, that's an interesting thought. While objects aren't stored as hash-maps on the server (instead they are sorted arrays of key/value pairs, on which we perform binary search to look up a key), I would still imagine this to be somewhat faster if there are few documents in the second table since it avoids all kinds of usual subquery processing overhead.
I wonder if the slow part in this case is building the object with 4K keys one by one. Every element being added to the object in the reduction function will essentially build a new object structure, including having the keys sorted again.
A slightly different way of doing that step that might or might not be faster is:
@danielmewes I was mistaken yesterday, loading the keys upfront is actually ~4-5x faster!
You're right, good catch. I always forget about #3408. The time it took to build up the object was pretty negligible compared to the total query duration, though.
Your suggestion can be further simplified which also makes it a bit faster:
Closing as a duplicate of #2720.
Once this functionality is supported by a join command, we should just spend our effort on making that generic command as fast as possible.
Sorry to bump this again, but one more quick question. I don't know enough about how indices are persisted or the data structures used to speak about this intelligently (is it documented somewhere?), but would it be possible to optimize the case of getting primary/secondary index values from a table? For example, is table('id') any more efficient than table('any_other_field') or do both require scanning every document? Likewise, it seems like table.distinct({ index: 'secondary' }) ends up doing a lot of reads and I'd be interested to better understand why that's necessary.
@marshall007 This is currently not optimized and whether you read the primary key or another field is equally expensive. See #4342 for the secondary index case. In short it's often not necessary. We just need to implement the optimized code path for this case.
Activity
marshall007 commentedon Jul 23, 2015
I think this would be solved by the
include_missingoptarg mentioned in #2720, but is there a workaround in the meantime?thelinuxlich commentedon Jul 23, 2015
Outer join(hope that someday this will be easier to write)
danielmewes commentedon Jul 23, 2015
I think at the moment the filter with the get is the most efficient one. At least I cannot think of a more efficient alternative. I suspect that the outer join that @thelinuxlich describes is also going to be a bit slower than the
filter(other.get.ne(null)).marshall007 commentedon Jul 24, 2015
Thanks for the suggestions. I also tried loading all the keys in from the right table first, but that didn't help much either:
I would have thought that loading 4K keys into a hashmap upfront and doing lookups against that would have been significantly faster than calling
.get()1.7M times. @danielmewes any insight into this?Aside from that, my questions have been answered so feel free to close this in favor of #2720.
danielmewes commentedon Jul 24, 2015
@marshall007 Ah, that's an interesting thought. While objects aren't stored as hash-maps on the server (instead they are sorted arrays of key/value pairs, on which we perform binary search to look up a key), I would still imagine this to be somewhat faster if there are few documents in the second table since it avoids all kinds of usual subquery processing overhead.
I wonder if the slow part in this case is building the object with 4K keys one by one. Every element being added to the object in the reduction function will essentially build a new object structure, including having the keys sorted again.
A slightly different way of doing that step that might or might not be faster is:
marshall007 commentedon Jul 24, 2015
@danielmewes I was mistaken yesterday, loading the keys upfront is actually ~4-5x faster!
You're right, good catch. I always forget about #3408. The time it took to build up the object was pretty negligible compared to the total query duration, though.
Your suggestion can be further simplified which also makes it a bit faster:
I found it slightly odd that
sequence.coerceTo('object')fails. It seems like that should implicitly coerce to array first.mlucy commentedon Jul 24, 2015
@marshall007 -- long term the plan is to implement #2721 which should fix the
.coerceTo('object')case as a side-effect.danielmewes commentedon Jul 24, 2015
Ah, good to know that this is faster.
Closing as a duplicate of #2720.
Once this functionality is supported by a join command, we should just spend our effort on making that generic command as fast as possible.
marshall007 commentedon Jul 25, 2015
Sorry to bump this again, but one more quick question. I don't know enough about how indices are persisted or the data structures used to speak about this intelligently (is it documented somewhere?), but would it be possible to optimize the case of getting primary/secondary index values from a table? For example, is
table('id')any more efficient thantable('any_other_field')or do both require scanning every document? Likewise, it seems liketable.distinct({ index: 'secondary' })ends up doing a lot of reads and I'd be interested to better understand why that's necessary.danielmewes commentedon Jul 25, 2015
@marshall007 This is currently not optimized and whether you read the primary key or another field is equally expensive. See #4342 for the secondary index case. In short it's often not necessary. We just need to implement the optimized code path for this case.