This wrong order resulted in CJ (with default sorted = TRUE) is causing bugs in .[i,  join
a = CJ(c(1,2,2),c(1,2,3))
a
V1 V2
1:  1  1
2:  1  2
3:  1  3
4:  2  1
5:  2  2
6:  2  3
7:  2  1
8:  2  2
9:  2  3
setkey(a,V1,V2)
Warning message:
In setkeyv(x, cols, verbose = verbose, physical = physical) :
Already keyed by this key but had invalid row order, key rebuilt. If you didn't go under the hood please let datatable-help know so the root cause can be fixed.