Hi, On Tue, 11 May 2021 at 10:34, Tom Lane <tgl@xxxxxxxxxxxxx> wrote: [...] > As Adrian noted, you haven't provided enough detail to let anyone > offer more than generalities. I'll be providing the output of EXPLAIN (ANALYZE, BUFFERS) in a separate post. > However, in the spirit of generalities ... [.. helpful explanation snipped ..] > Rather than blaming the planner for not being lucky, you should be > thinking about what you can do to help it out. Can you get rid of > the additional join to account_move? (Note that the one I'm > suspecting is extra is the LEFT JOIN, not the IN.) I'd also > counsel losing the ORDER BY in the sub-select, as that's either > going to be ignored altogether or force a probably-useless sort, > not to mention creating an optimization barrier. Unfortunately, the SQL is generated by Odoo's ORM, and as much as I'd like to be able to 'help it', their code has too many feature-hooks for me to easily hack their code ... Odoo has used Postgresql as it s database since its inception back in 2008. It is just unfortunate that it has hit this stumbling block with the latest version of the planner. Cheers. -- Jonathan Chen <jonc@xxxxxxxxxxx>