SELECT a.COL1, a.COL2, b.COL3 ,
a.COL4, e.COL1 , e.COL5, e.COL6,
e.COL7, a.COL8,b.COL9, b.COL10 , a.COL11,
f.COL12 FROM TABLE1 a, TABLE2 b
TABLE3 c, TABLE4 d, TABLE5 e, TABLE6 f
WHERE a.COL1=b.COL1 and a.COL2=c.COL2 and c.COL3=d.COL3 and d.COL5='2'
ORDER BY date(a.COL8) DESC, a.COL2 desc, a.COL1
The query above when executed directly on the database using PGAdmin or Navicat is returning 570 results and finishes in less than a second. However when executed via pg_query it takes about 40(!) seconds.
Does anyone know why this is?