Greg Sabino Mullane <htamfids@gmail.com> writes:
> Please provide a self-contained use case, or (at the bare minimum) trim out
> the irrelevant parts of your query and show us the schema for the tables in
> question. Finally, please show the explain plans for the "good" and "bad"
> runs you are experiencing. Thanks.
There's a lot of good info about how to ask useful performance
questions at
https://wiki.postgresql.org/wiki/Slow_Query_Questions
regards, tom lane