PL/R is not ALTREP aware
mlt opened this issue · 1 comments
mlt commented
The following test code
create or replace function altrep_test() returns int[] as $$
as.numeric( .Internal(mmap_file("postmaster.opts", "int", FALSE, FALSE, FALSE)) )
$$ language plr;
select cardinality(altrep_test());
create or replace function altrep_test2() returns int[] as $$
.Internal(mmap_file("postmaster.opts", "int", FALSE, FALSE, FALSE))
$$ language plr;
select cardinality(altrep_test2());
will crash on the second test with
Error: cannot access data pointer for this mmaped vector
Fatal error: unable to initialize the JIT
Calls like INTEGER()
and REAL()
try to materialize objects (unless explicitly prohibited in the example above) whereas INTEGER_ELT
and REAL_ELT
won't at the expense of not being inlined in newer R.
All fast track copy code should check if (!ALTREP(rval))
. Alternatively, I suggest to use corresponding xxx_ELT
ALTREP-aware accessors with a small performance penalty. Since there are checks for NA anyway, we might as well just copy an element to avoid extra code complexity.
davecramer commented
closed lack of activity, please reopen if still relevant