Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svaHh-00GAqS-9Y for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2024 10:39:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1svaHg-00EhUl-1k for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2024 10:39:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svaHf-00EhUO-Lk for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2024 10:39:11 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1svaHY-001wU2-VY for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2024 10:39:10 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-42cbbb1727eso47425305e9.2 for ; Tue, 01 Oct 2024 03:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=cybertec.at; t=1727779143; x=1728383943; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=rXdH9GKPbGrHgx/OznS5AvAk2RA91ejM0MqW4jA3AOw=; b=gb1cFp5SCniIn6BgBwNqp5BwQg9S9E1qebbHGZBM63DyceW6bOi9AHwpfnyzZOB0Nb O1cuxvjwm3Zbhs99uHsmNuvVMsRL7u/e3lsXtNzkiiEm179B8ro5jM1NBTQexduGhkqO P+pz/VSECDMywyWY+dAFkdjtK31E+ejO8o648= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727779143; x=1728383943; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rXdH9GKPbGrHgx/OznS5AvAk2RA91ejM0MqW4jA3AOw=; b=PuNkTj3OTEXFunKpVKoVAYSOjwKZ8cuMXoF+cV3HOPc3VFaev5qjrgkJdy3sNz4NUA +lhBu29VWPegrfcqClfM+6nqGhQ5Co3HS9aCUiZ9+nxyuraiG1jdHVRmjUdA5JH0fU0r vmv4Qs/5H2ynf+qMjYXHumoo+QFVwB3SOdmGHEsnTYIIIgxTZ7aOLjBCtPxTqsUWRUb0 hwiUcbZKLMepPD8UNygetKpvJ0lpAdQzYNe1ZueACkYnPeQk9E5p789hpD1FU/IxDNT3 /FZNVdT1HdrwGloNt3h4H0jOkffqIT4UqJKeG3CcMR4nCEg0f7MqTiNLZsgbGmiBbTLw 8SeA== X-Gm-Message-State: AOJu0Yw7YkntPpOrpnGPowyKAhdy3WNmTXnEMj3hf3xTlJn+7WG+hkgk QljniDcgt0gAQSCYS18Es6qprk/ffss+uXR0qxT8g86jFI2QOg1UsIt51Q9vUdU= X-Google-Smtp-Source: AGHT+IFXe/572YEJfXHHzWtCLgq++R4xYCftLpZnvjYmE54X1vHtQKGUvu8EmhJ+7DO2pmTylaH/Iw== X-Received: by 2002:a5d:4582:0:b0:374:c5e9:623e with SMTP id ffacd0b85a97d-37cd5aec754mr7194495f8f.43.1727779143312; Tue, 01 Oct 2024 03:39:03 -0700 (PDT) Received: from dynamic-pd01.res.v6.highway.a1.net ([2001:871:5e:1fcf:a04d:3862:f91c:eaac]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd5730ecasm11502428f8f.81.2024.10.01.03.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 03:39:02 -0700 (PDT) Message-ID: <3d4bf841b153bb63910ed2835dc3683e6129c422.camel@cybertec.at> Subject: Re: Help with query optimizer From: Laurenz Albe To: David Mullineux , Siraj G Cc: pgsql-general@lists.postgresql.org Date: Tue, 01 Oct 2024 12:39:02 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.4 (3.52.4-1.fc40) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2024-10-01 at 09:36 +0100, David Mullineux wrote: > > On Tue, 1 Oct 2024, 08:53 Siraj G, 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 de= fine 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 th= ey 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 : conver= sations 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