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.
Чтобы сделать работу с сайтом удобнее, мы используем cookie и аналитический сервис «Яндекс.Метрика». Продолжая пользоваться сайтом, вы соглашаетесь с их использованием.