Where to store Foreign Key information

We are using Flowable currently we use process variables to store the Foreign Key to the thing that the task relates to.

What we have found is that performance when getting tasks by process variable is fairly slow as it has to join the ACT_RU_TASK to ACT_RU_VARIABLE and we are then filtering on Type which doesn’t have an index.

Is there a field on 'ACT_RU_TASK` that would could use to store a Foreign Key information.

That would only work if you put the index on the variable table side, which is most likely the TEXT_ column. And that column can have arbitrary values - so not feasable.