I have a query on two big tables that is too slow! I have a simple query:

SELECT  t1."TimeS" as TimeS, t1."JobID" as JobID, t1."TaskIndex" as TaskIndex,  t1."MachineID" as MachineID ,t2."EventType" as EventType,  t1."UserName" as UserName, t1."CpuReq" as CpuReq, t1."MemReq" as MemReq, 
  t2."TimeS" as FinTime  , (t2."TimeS"-t1."TimeS") as duration
FROM  scheduled_tasks_table  as t1 ,  public.dead_tasks_table as t2 
     WHERE t1. "TaskIndex"= t2. "TaskIndex"
     AND t1."JobID"= t2."JobID" AND (t2."TimeS"-t1."TimeS")&gt;='0' 


I have 15GB memory (RAM) and my Config File is: 

max_connections = 200
shared_buffers = 3840MB
effective_cache_size = 11520MB
work_mem = 19660kB
maintenance_work_mem = 960MB
min_wal_size = 1GB
max_wal_size = 2GB
checkpoint_completion_target = 0.7
wal_buffers = 16MB
default_statistics_target = 100


Both my tables both have a single primary key and a single indexe as:( TaskIndex, JobId, Timet)

But this query is really slow:

EXPLAIN:

" "Merge Join  (cost=19982628.08..1436656715.61 rows=20251904912 width=105)"
"  Merge Cond: ((t1."TaskIndex" = t2."TaskIndex") AND (t1."JobID" = t2."JobID"))"
"  Join Filter: ((t2."TimeS" - t1."TimeS") &gt;= '0'::bigint)"
"  -&gt;  Sort  (cost=12319742.87..12438008.64 rows=47306308 width=93)"
" Sort Key: t1."TaskIndex", t1."JobID""
"  -&gt;  Seq Scan on scheduled_tasks_table t1  (cost=0.00..1438498.08 rows=47306308 width=93)"
"  -&gt;  Materialize  (cost=7662858.23..7874671.39 rows=42362632 width=28)"
Probably problem is here:

(t2."TimeS"-t1."TimeS")&gt;='0'


Postgresql does not use index for this. Can you try just:

t2."TimeS" &gt;= t1."TimeS"