I am trying to join two big tables; lets call them tableA (150million rows) and tableB (140 million rows). Following query returns 490 rows and takes about 20-25s to execute (which is not acceptable).
select distinct
a.key_fk
from tableA a
join tableB b on a.key_fk = b.key_fk
where customFunc(b.valueX) = 'xyz'
and customFunc(a.valueY) = 'abc';
a.key_fkandb.key_fkare foreign keys referencing another tablec(but that is not relevant)- both tables have indexes on
key_fk tableAhas an index oncustomFunc(valueY)andtableBhas an index oncustomFunc(valueX)select count(key_fk) from tableA where customFunc(valueY)='abc'takes about 7-8s and returns 5million rowsselect count(key_fk) from tableB where customFunc(valueX)='xyz'takes about 0,5s and returns 80k rows
Is there anything else I can do to improve the performance of mentioned query?