I have 3 tables (all simplified here)
job (id int, type char(1))
data (job_id int, owner int, creator int, value int)
user (id int)
My query is
select user.id, job.id, sum(data.value)
from job
join data on job.id = data.job_id
join user on case job.type when 'O' then data.owner else data.creator end = user.id
group by user.id, job.id
How do I create an index in Postgres which caters for the case statement in the join?
Job would have maybe a dozen rows, users 1000s and data millions.
Thanks
UNION ALL.