Use a temporary table to add relations
This avoids passing a (potentially quite large) list of rows as argument to a function call.