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 1fKikp-0003md-IP for pgsql-performance@arkaria.postgresql.org; Mon, 21 May 2018 11:13:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fKiko-00017Z-37 for pgsql-performance@arkaria.postgresql.org; Mon, 21 May 2018 11:13:26 +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 1fKikn-00017P-SE for pgsql-performance@lists.postgresql.org; Mon, 21 May 2018 11:13:25 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fKikl-0003uc-9m for pgsql-performance@postgresql.org; Mon, 21 May 2018 11:13:25 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 92E60D0DC59B for ; Mon, 21 May 2018 04:13:20 -0700 (MST) Date: Mon, 21 May 2018 04:13:20 -0700 (MST) From: pavan95 To: pgsql-performance@postgresql.org Message-ID: <1526901200599-0.post@n3.nabble.com> In-Reply-To: <1526889830358-0.post@n3.nabble.com> References: <1526883356469-0.post@n3.nabble.com> <1526889830358-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 mlunon, A great thanks for your timely response. And yes it worked when I rewritten the query. The query got enhanced with approximate of 1000 planner seeks. You can find it from the explain plan below: amp_test=# explain select sum ( CASE MOD(cast(effort_hours as decimal),1) WHEN 0.45 THEN cast(effort_hours as int)+0.75 WHEN 0.15 THEN cast(effort_hours as int)+0.25 WHEN 0.30 THEN cast(effort_hours as int)+0.5 WHEN 0 THEN cast(effort_hours as int) END ) from tms_timesheet_details detail , tms_wsr_header header where wsr_header_id=header.id and work_order_no != 'CORPORATE'; QUERY PLAN ------------------------------------------------------------------------------------------------ Aggregate (cost=8813.60..8813.61 rows=1 width=8) -> Hash Join (cost=608.27..5647.67 rows=70354 width=8) Hash Cond: (detail.wsr_header_id = header.id) -> Seq Scan on tms_timesheet_details detail (cost=0.00..3431.14 rows=72378 width=12) Filter: ((work_order_no)::text <> 'CORPORATE'::text) -> Hash (cost=399.23..399.23 rows=16723 width=4) -> Seq Scan on tms_wsr_header header (cost=0.00..399.23 rows=16723 width=4) (7 rows) But is this the optimum, can we reduce the cost more at least to around 5000 planner seeks. As it is only a subpart of the query which is called multiple number of times in the main query. And to send the main query along with tables description and explain plan it will be a vast message so send you a sub-part. Please help me to tune it more. Thanks in Advance. Regards, Pavan -- Sent from: http://www.postgresql-archive.org/PostgreSQL-performance-f2050081.html