Is possible to cache in some variable results of subquery?

I have query in postgresql 9.1 like

FROM students
INNER JOIN exams ON /some condition

and when I run only the subquery it executes in 120ms, when I execute the previous query without condition with subquery it executes for 12 seconds, but when I add subquery it runs half hour Is possible to cache in some variable results of subquery (results are always same array of ids) and execute in console/pgadmin ? I found WITH statement but it looks like is not supported in postgres


First, the with statement is supported in Postgres.

Second, you need to identify where the performance problem is. Is it in the subquery? Or is it the not in?

You can put the subquery in a table, add indexes, and make the query more efficient.

You can rewrite the subquery using a left join, which often allows the query to be better optimized.

You can add appropriate indexes to make the entire query more efficient.

Without knowledge of what the subquery actually does, the right approach is speculation.

Need Your Help

How to add a blank page to a pdf using iTextSharp?

c# pdf itextsharp

I am trying to do something I thought would be quite simple, however it is not so straight forward and google has not helped.

How to create such a Path in code?


How to create the following xaml in code: