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.
Cheers, Greg -- Crunchy Data - https://www.crunchydata.com Enterprise Postgres Software Products & Tech Support
