Skip to content

Auto indexing on set() #1196

Closed
Closed

Description

@arunsrinivasan

set()'s i argument could also be optimised to use auto indexing..

Relevant SO post: http://stackoverflow.com/q/30997215/559784

Activity

  1. jangorecki commented on Mar 17, 2019

    @jangorecki
    Member

    set i argument takes integer rows identifiers already, so there is space to put index optimisation there.
    Index can already be utilised by passing dt[, which=TRUE] results to set's i arg.

    library(data.table)
    dt = data.table(a=1:4, b=5:2)
    setindex(dt, b)
    dt[b%in%3:4, which=TRUE, verbose=TRUE]
    #Optimized subsetting with index 'b'
    #on= matches existing index, using index
    #Starting bmerge ...done in 0.000s elapsed (0.000s cpu) 
    #Reordering 2 rows after bmerge done in ... 0 secs
    #[1] 2 3

    This of course will include overhead of [, but if set is used to the same subset of rows on multiple columns then the overhead will be implied only once. What we could eventually improve here is to reduce overhead of [ by figuring out that dt[a==b, which=TRUE] call was made, and redirect it early to C. The thing is that there are multiple kind of queries that could be optimised in such a way. Ultimately we need to move [ to C, or make it more modular #852, so different kinds of queries can be more easily/sooner redirected to C.

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions