Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLRgu-0001LK-Rn for pgsql-performance@arkaria.postgresql.org; Wed, 23 May 2018 11:12:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLRgt-00042p-C8 for pgsql-performance@arkaria.postgresql.org; Wed, 23 May 2018 11:12:23 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLRgt-00042f-4e for pgsql-performance@lists.postgresql.org; Wed, 23 May 2018 11:12:23 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLRgk-0004Rv-70 for pgsql-performance@postgresql.org; Wed, 23 May 2018 11:12:21 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 8DDCBD176648 for ; Wed, 23 May 2018 04:12:10 -0700 (MST) Date: Wed, 23 May 2018 04:12:10 -0700 (MST) From: mlunnon To: pgsql-performance@postgresql.org Message-ID: <1527073930538-0.post@n3.nabble.com> In-Reply-To: <1526985179479-0.post@n3.nabble.com> References: <1526883356469-0.post@n3.nabble.com> <1526917693149-0.post@n3.nabble.com> <1526985179479-0.post@n3.nabble.com> Subject: Re: Help me in reducing the CPU cost for the high cost query below, as it is hitting production seriously!! MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Pavan, that's quite a big query. I can see that the generate_series function is getting repeatedly called and the planner estimates for this sub query are out by a factor of 66. You might try to re-write using a WITH query. I am assuming that you have already analyzed all the tables and also added appropriate indexes on join/query columns. Regards Matthew -- Sent from: http://www.postgresql-archive.org/PostgreSQL-performance-f2050081.html