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
{{ message }}
Repository navigation
Avoid loading documents for certain indexed operations #4342
Take for example r.table(...).distinct({index: "idx"}).
At the moment I think we always load every document and then recompute the index value from the document.
This is often unnecessary. If a given secondary index value isn't truncated, we could use the value from the btree key and wouldn't need to load the document itself.
There are probably a few other operations where similar optimizations make sense (min({index: ...}) for example).
Well, no one else has chimed in on this so I figured I'd give my two cents. It would be awesome to read the values directly from the index instead of pulling them from the document.
This is not really a matter of just performance, since we've seen prohibitively slow (minutes or longer) queries on datasets that should be trivial if this issue is implemented - e.g. hundreds of thousands of records but only hundreds of unique secondary index values. We seem to be able to count based on this index just fine:
# executes in under 1 secondr.table("work_orders").get_all("2mpizp5BluTKHS",{"index"=>"technician_id"}).count
But have no practical way to tell what the possible values are:
# not sure how long this takes, I killed it after a minuter.table("work_orders").distinct({"index"=>"technician_id"}).count
@ajose01 Note that the particular change described here wouldn't change the complexity of distinct. It would just make it faster by a constant factor.
It would still iterate over each document in the index. However it could iterate more quickly since checking whether a key has been seen before would not require loading the whole document.
I guess this is just my lack of understanding of how the internals work for secondary indexes. My naive assumption is that the index itself would contain all possible values, but that must not be the case. It would be interesting to see the performance improvement, regardless.
Activity
ajselvig commentedon May 25, 2016
Well, no one else has chimed in on this so I figured I'd give my two cents. It would be awesome to read the values directly from the index instead of pulling them from the document.
This is not really a matter of just performance, since we've seen prohibitively slow (minutes or longer) queries on datasets that should be trivial if this issue is implemented - e.g. hundreds of thousands of records but only hundreds of unique secondary index values. We seem to be able to count based on this index just fine:
But have no practical way to tell what the possible values are:
danielmewes commentedon May 25, 2016
@ajose01 Note that the particular change described here wouldn't change the complexity of
distinct. It would just make it faster by a constant factor.It would still iterate over each document in the index. However it could iterate more quickly since checking whether a key has been seen before would not require loading the whole document.
ajselvig commentedon May 25, 2016
I guess this is just my lack of understanding of how the internals work for secondary indexes. My naive assumption is that the index itself would contain all possible values, but that must not be the case. It would be interesting to see the performance improvement, regardless.