Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1px7wr-0007OY-Uy for pgsql-admin@arkaria.postgresql.org; Thu, 11 May 2023 15:11:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1px7wq-0006bg-TR for pgsql-admin@arkaria.postgresql.org; Thu, 11 May 2023 15:11:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1px7wq-0006ar-ID for pgsql-admin@lists.postgresql.org; Thu, 11 May 2023 15:11:16 +0000 Received: from jakobs.com ([85.214.83.89] helo=rs.plausibolo.de) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1px7wk-001lbN-P2 for pgsql-admin@lists.postgresql.org; Thu, 11 May 2023 15:11:15 +0000 Received: from localhost (localhost [127.0.0.1]) by rs.plausibolo.de (Postfix) with ESMTP id 65FB9380456; Thu, 11 May 2023 17:11:08 +0200 (CEST) Received: from rs.plausibolo.de ([127.0.0.1]) by localhost (h2367442.stratoserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YdjhsdPnjd0t; Thu, 11 May 2023 17:11:08 +0200 (CEST) Received: from [192.168.43.225] (ip-109-42-176-93.web.vodafone.de [109.42.176.93]) by rs.plausibolo.de (Postfix) with ESMTPSA id 1A7BF3802BB; Thu, 11 May 2023 17:11:08 +0200 (CEST) Message-ID: <3c797d81-49e6-e8a2-b1b0-b63cb25901e5@jakobs.com> Date: Thu, 11 May 2023 17:11:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: Related To Query Optimization Content-Language: de-DE To: pgsql-admin@lists.postgresql.org References: From: Holger Jakobs In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------gty27WW9BPqnCFVEAE7P96Ha" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------------gty27WW9BPqnCFVEAE7P96Ha Content-Type: multipart/mixed; boundary="------------GN5mjXvpRSW008gQeEBNgpTK"; protected-headers="v1" From: Holger Jakobs To: pgsql-admin@lists.postgresql.org Message-ID: <3c797d81-49e6-e8a2-b1b0-b63cb25901e5@jakobs.com> Subject: Re: Related To Query Optimization References: In-Reply-To: --------------GN5mjXvpRSW008gQeEBNgpTK Content-Type: multipart/alternative; boundary="------------aFX9ymWuDlnsGiwWSaWlvCid" --------------aFX9ymWuDlnsGiwWSaWlvCid Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: base64 QW0gMTEuMDUuMjMgdW0gMTY6NTAgc2NocmllYiBST0hJVCBTQUNIREVWQToNCj4NCj4gSGkg VGVhbSwNCj4NCj4gwqBJIGFtIGZhY2luZyBhbiBpc3N1ZSB3aGVyZSBvbmUgb2YgdGhlIHF1 ZXJpZXMgaXMgdGFraW5nIHRpbWUgaW4gDQo+IHByb2R1Y3Rpb24uDQo+IFdoZW4gSSBwdXQg dGhhdCBxdWVyeSBpbiBleHBsYWluLCBJIGZvdW5kIG1hbnkgbmVzdGVkIGxvb3AgY29uZGl0 aW9ucyANCj4gd2VyZSBiZWluZyB1c2VkLCBzbyBqdXN0IGZvciB0ZXN0aW5nLCBJIGRpc2Fi bGVkIHRoZSBlbmFibGVfbmVzdGxvb3AgDQo+IGZsYWcgZm9yIGEgc2Vzc2lvbiwgYW5kIG5v dyB0aGUgcXVlcnkgaXMgcnVubmluZyBmYXN0Lg0KPiBJIGFsc28gcmFuIGFuIGFuYWx5emUg b24gZXZlcnkgdGFibGUgb2YgdGhhdCBxdWVyeSBhbmQgYWxzbyBpbmRleGluZyANCj4gaXMg dGhlcmUgb24gcmVxdWlyZWQgY29sdW1ucy4NCj4NCj4gwqBUZWxsIG1lIHdoZXJlIGkgYW0g d3JvbmcgYW5kIHdoYXQgY2FuIGJlIGRvbmUsIGFzIGkgZG9uJ3Qgd2FudCB0byANCj4gZGlz YWJsZSBpdCBiZWNhdXNlLCBhY2NvcmRpbmcgdG8gbWUsIGl0J3Mgbm90IGEgZ29vZCBwcmFj dGlzZS4NCj4NCj4NCj4gLS0NCj4gSGF2ZSBhIEdvb2QgZGF5ICEhIQ0KPg0KPiBSZWdhcmRz DQo+IFJvaGl0IFNhY2hkZXZhDQoNCkkgdGhpbmsgaXQncyB0b3RhbGx5IGltcG9zc2libGUg dG8gdGVsbCB3aXRob3V0IGtub3dpbmcgbW9yZSBkZXRhaWxzLg0KDQpQbGVhc2UgcG9zdCB0 aGUgQ1JFQVRFIFRBQkxFIGNvbW1hbmRzLCB0aGUgbnVtYmVyIG9mIHJvd3MgaW4gdGhlIHRh YmxlcywgDQp0aGUgU0VMRUNUIGNvbW1hbmQgYW5kIHRoZSBvdXRwdXQgb2YgRVhQTEFJTi4N Cg0KS2luZCBSZWdhcmRzLA0KDQpIb2xnZXINCg0KDQo+IC0tIA0KDQpIb2xnZXIgSmFrb2Jz LCBCZXJnaXNjaCBHbGFkYmFjaCwgVGVsLiArNDktMTc4LTk3NTkwMTINCg0K --------------aFX9ymWuDlnsGiwWSaWlvCid Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Am 11.05.23 um 16:50 schrieb ROHIT SACHDEVA:

Hi Team,

=C2=A0I am facing an issue where one of the queries is tak= ing time in production.
When I put that query in explain, I found many nested loop conditions were being used, so just for testing, I disabled the enable_nestloop flag for a session, and now the query is running fast.
I also ran an analyze on every table of that query and also indexing is there on required columns.

=C2=A0Tell me where i am wrong and what can be done, as i don't want to disable it because, according to me, it's not a good practise.=C2=A0=C2=A0


--
Have a Good day !!!

Regards
Rohit Sachdeva

I think it's totally impossible to tell without knowing more details.

Please post the CREATE TABLE commands, the number of rows in the tables, the SELECT command and the output of EXPLAIN.

Kind Regards,

Holger


--
Holger Jakobs, Bergisch Glad=
bach, Tel. +49-178-9759012
--------------aFX9ymWuDlnsGiwWSaWlvCid-- --------------GN5mjXvpRSW008gQeEBNgpTK-- --------------gty27WW9BPqnCFVEAE7P96Ha Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wmMEABEIACMWIQScuJCxWJK1p5BOebGKV5yTsxlhugUCZF0FiwUDAAAAAAAKCRCKV5yTsxlhuq4y AJ9pzTsrXfuzAp1rjAm9n0HgvqNJEgCgvily5PpjOLId7ldi4FbwJ8YGhVk= =2xnB -----END PGP SIGNATURE----- --------------gty27WW9BPqnCFVEAE7P96Ha--