Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1if3z3-0003aR-Ll for pgsql-admin@arkaria.postgresql.org; Wed, 11 Dec 2019 15:33:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1if3z1-0001s5-6Q for pgsql-admin@arkaria.postgresql.org; Wed, 11 Dec 2019 15:32:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1if3z0-0001ry-Sk for pgsql-admin@lists.postgresql.org; Wed, 11 Dec 2019 15:32:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1if3yx-0003al-EB for pgsql-admin@lists.postgresql.org; Wed, 11 Dec 2019 15:32:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xBBFWn6Z014518; Wed, 11 Dec 2019 10:32:49 -0500 From: Tom Lane To: Shrikant Bhende cc: pgsql-admin@lists.postgresql.org Subject: Re: Slow running query In-reply-to: References: Comments: In-reply-to Shrikant Bhende message dated "Wed, 11 Dec 2019 12:39:35 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14516.1576078369.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 11 Dec 2019 10:32:49 -0500 Message-ID: <14517.1576078369@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Shrikant Bhende writes: > Below is the query which is running very slow, can anyone suggest any > improvement for the same to make it faster. Not when you haven't given us any supporting data :-(. There's some advice about how to ask useful performance questions here: https://wiki.postgresql.org/wiki/Slow_Query_Questions However, just scanning your EXPLAIN output, it seems that the bulk of the time is being spent inside two user-defined functions: > -> Function Scan on get_nu= m_connections f (cost=3D0.25..10.25 rows=3D1000 width=3D24) (actual time=3D= 22331.461..22331.479 rows=3D263 loops=3D1) ... > -> Function Scan on get_nu= m_proprietary f_1 (cost=3D0.25..10.25 rows=3D1000 width=3D24) (actual tim= e=3D4052.081..4052.085 rows=3D26 loops=3D1) ... > Planning time: 18.362 ms > Execution time: 33944.679 ms ie, 26 of the 34 seconds are being spent there. You're not going to be able to move the needle very far unless you can make those a lot cheaper. I notice that the first thing the plan does with these is FULL JOIN them to each other, which seems suspiciously like a performance anti-pattern. regards, tom lane