rolling join is unexpectedly slow

Open
#2,490 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data, performance

Research direction

No repository files or tests are named. Start by running the issue's reproducible data.table benchmark and comparing the indexed non-rolling join plus subset with the rolling join; determine what accounts for the timing difference and document or address the behavior so both approaches have an explained, validated result.

Written by the indexing model from the issue text.

Description

IDate/ITime non-equi joins

It seems that joining two tables based on non-roll columns and then subsetting the result based on the roll condition works faster than doing it all in one step. For example

set.seed(0)
dt <- data.table(
  A = sample(x = 10^2, size = 10^8, replace = TRUE),
  B = sample(x = 10^4, size = 10^8, replace = TRUE),
  C = sample(seq.Date(as.Date("2000-01-01"), as.Date("2010-12-31"), by = "day"), size = 10^8, replace = TRUE)
)
jt <- data.table(A = 94L, B = 4778L, C = as.Date("2005-01-01"))


# Join on (A, B), then subset rows >= 2005-01-01
setindex(dt, "A", "B")
system.time(result1 <- dt[jt[, list(A, B)], on=c("A", "B"), nomatch = 0][C >= as.Date("2005-01-01")])

# user  system elapsed 
# 0.002   0.000   0.002 


# Rolling join on (A, B, C)
setindex(dt, "A", "B", "C")
system.time(result2 <- jt[dt, on=c("A", "B", "C"), roll = TRUE, nomatch = 0])

# user  system elapsed 
# 10.943   0.809  11.793 

all.equal(result1, result2)  # TRUE

Why is the second join so much slower than the first in this example? Thanks!

sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.