Skip to content

Avoid loading documents for certain indexed operations #4342

Open

Description

@danielmewes

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).

Activity

  1. modified the milestones: backlog, subsequent on Jun 4, 2015
  2. ajselvig commented on May 25, 2016

    @ajselvig

    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 second
    r.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 minute
    r.table("work_orders").distinct({"index" => "technician_id"}).count
  3. danielmewes commented on May 25, 2016

    @danielmewes
    MemberAuthor

    @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.

  4. ajselvig commented on May 25, 2016

    @ajselvig

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions