On Tue, 2024-10-01 at 09:36 +0100, David Mullineux wrote: > > On Tue, 1 Oct 2024, 08:53 Siraj G, <tosiraj.g@xxxxxxxxx> wrote: > > Can you please help with the attached query as it is taking time to > > execute. The execution plan for the same is below: > > > > [EXPLAIN (ANALYZE, BUFFERS) output] > > Its usually helpful to give some details on what 'slow' means and then define what > 'fast enough ' means. Just so we know when to stop optimizing. > You should also help by giving the DDL of those.tables and any indexes they have etc.. Table definitions and the actual query text would be most helpful, yes. The PostgreSQL version is essential too. > The plan shows me that there are expensive seq scans on 2 tables : conversations and tasks. Those sequential scans are quite cheap; there is nothing to optimize. The time is spent in two index scans that are repeated a lot, because they are on the inner side of a nested loop: - the index scan on "messages" is repeated 53708 times - the index scan on "mailMessages" is repeated 173750 times Yours, Laurenz Albe