pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: mlunnon <mlunnon@rwa-net.co.uk>
To: pgsql-performance@postgresql.org
Subject: Re: Help me in reducing the CPU cost for the high cost query below, as it is hitting production seriously!!
Date: Mon, 21 May 2018 01:03:50 -0700 (MST)
Message-ID: <1526889830358-0.post@n3.nabble.com> (raw)
In-Reply-To: <1526883356469-0.post@n3.nabble.com>
References: <1526883356469-0.post@n3.nabble.com>

pavan95 wrote
> Hi all,
> 
> Hope my mail finds you in good time. I had a problem with a query which is
> hitting the production seriously.
> The below is the sub part of the query for which I cannot reduce the CPU
> cost. 
> 
> Please check and verify whether I'm doing wrong or whether that type index
> type suits it or not. 
> 
> Kindly help me resolve this issue.
> 
> *Query*:
> 
> explain select sum(CASE
>                              WHEN MOD(cast(effort_hours as decimal),1) =
> 0.45 THEN
>                              cast(effort_hours as int)+0.75
>                              ELSE
>                                  CASE
>                                  WHEN MOD(cast(effort_hours as decimal),1)
> =
> 0.15 THEN
>                                  cast(effort_hours as int) + 0.25
>                                 
>                               ELSE
>                                  CASE
>                                  WHEN MOD(cast(effort_hours as decimal),1)
> =
> 0.30 THEN
>                                  cast(effort_hours as int) + 0.5
>                                 
>                               ELSE
>                                  CASE
>                                  WHEN MOD(cast(effort_hours as decimal),1)
> =
> 0 THEN
>                                  cast(effort_hours as int) 
>                                  end
>                                  END
>                                  END
>                              END) from tms_timesheet_details,
> tms_wsr_header
> header  where wsr_header_id=header.id and work_order_no != 'CORPORATE';
> 
> 
> 
> --
> Sent from:
> http://www.postgresql-archive.org/PostgreSQL-performance-f2050081.html

To start with you can try re-writing this so that it only does the mod cast
once. e.g:
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
)




--
Sent from: http://www.postgresql-archive.org/PostgreSQL-performance-f2050081.html




view thread (25+ messages)  latest in thread

Message-ID: <1526889830358-0.post@n3.nabble.com>
Permalink:  ../1526889830358-0.post@n3.nabble.com/
Also on:    postgresql.org/message-id/1526889830358-0.post@n3.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: mlunnon@rwa-net.co.uk
  Subject: Re: Help me in reducing the CPU cost for the high cost query below, as it is hitting production seriously!!
  In-Reply-To: <1526889830358-0.post@n3.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox