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 1fKlY1-0006u9-1a for pgsql-performance@arkaria.postgresql.org; Mon, 21 May 2018 14:12:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fKlY0-00055R-1X for pgsql-performance@arkaria.postgresql.org; Mon, 21 May 2018 14:12:24 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fKlXz-00055H-GO for pgsql-performance@lists.postgresql.org; Mon, 21 May 2018 14:12:23 +0000 Received: from homie.mail.dreamhost.com ([208.97.132.208] helo=homiemail-a60.g.dreamhost.com) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fKlXu-0004Rt-4a for pgsql-performance@postgresql.org; Mon, 21 May 2018 14:12:20 +0000 Received: from homiemail-a60.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a60.g.dreamhost.com (Postfix) with ESMTP id 3741B282075; Mon, 21 May 2018 07:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=rechat.com; h=date:from :subject:to:cc:message-id:in-reply-to:references:mime-version: content-type; s=rechat.com; bh=kWJCdgxieJ2Tcyvx7JwH8bhlQN0=; b=e TJ2+OO2VLA64ndxwpEPseNEHh1c08kAAHArQau360nHrwZX699bEiazCdeoEaldi Gc1O3pj87vLZXvDCdkfklVkQ8tot5QYAyYhSbwgttqhIK+L7sz7LXCVm7yVJ7saw 8h/FIKuOYWiP0pHqBTTwIXUze+uN7VaWXTzndhv2tQ= Received: from [192.168.99.217] (ip167.ip-142-44-206.net [142.44.206.167]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: abbas@rechat.com) by homiemail-a60.g.dreamhost.com (Postfix) with ESMTPSA id 85581282068; Mon, 21 May 2018 07:12:11 -0700 (PDT) Date: Mon, 21 May 2018 18:12:06 +0400 From: Abbas Subject: Re: Help me in reducing the CPU cost for the high cost query below, as it is hitting production seriously!! To: pavan95 Cc: pgsql-performance@postgresql.org Message-Id: <1526911926.12183.1@homie.mail.dreamhost.com> In-Reply-To: <1526909995520-0.post@n3.nabble.com> References: <1526883356469-0.post@n3.nabble.com> <1526889830358-0.post@n3.nabble.com> <1526901200599-0.post@n3.nabble.com> <1526902087.12183.0@homie.mail.dreamhost.com> <1526909995520-0.post@n3.nabble.com> X-Mailer: pantheon-mail/1.0.6 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=-TazvxT9iNmL4bEhS1132" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=-TazvxT9iNmL4bEhS1132 Content-Type: text/plain; charset=us-ascii; format=flowed Sure thing. Base 60 or Sexagesimal is the numerical system used for measuring time (1 hour equals to 60 minutes and so on). But this case is even simpler, so without going into much detail about bases, you're mapping between two sets of numbers: 0 -> 0 .15 -> .25 .30 -> .50 .45 -> .75 From working with clocks, we know that 15 minutes is .25 hours, 30 minutes is .5 hours and so on. So you only need to divide the fractional part ( effort_hours - floor(effort_hours) ) by .6 to get what you want. For example, let's say effort_hours = 1.15; then floor(1.15) is 1; so: floor(1.15) + ( (1.15 - floor(1.15)) / 0.6 ) = 1 + ( (1.15 - 1) / 0.6 ) = 1 + ( 0.15 / 0.60 ) = 1.25 Hope it helps. Feel free to ask a question if it's still unclear. :) On Mon, May 21, 2018 at 6:09 PM, pavan95 wrote: > Hi Abbas, > > Thanks for your valuable suggestions. To my surprise I got the same > output > as what I have executed before. > > But unfortunately I'm unable to understand the logic of the code, in > specific what is base 60 number? The used data type for "effort_hours" > column is 'double precision'. > > Kindly help me in understanding the logic. Thanks in advance. > > Regards, > Pavan > > > > -- > Sent from: > http://www.postgresql-archive.org/PostgreSQL-performance-f2050081.html > --=-TazvxT9iNmL4bEhS1132 Content-Type: text/html; charset=us-ascii
Sure thing. Base 60 or Sexagesimal is the numerical system used for measuring time (1 hour equals to 60 minutes and so on). But this case is even simpler, so without going into much detail about bases, you're mapping between two sets of numbers:

0 -> 0
.15 -> .25
.30 -> .50
.45 -> .75

From working with clocks, we know that 15 minutes is .25 hours, 30 minutes is .5 hours and so on. So you only need to divide the fractional part ( effort_hours - floor(effort_hours) ) by .6 to get what you want.

For example, let's say effort_hours = 1.15; then floor(1.15) is 1; so:

floor(1.15) + ( (1.15 - floor(1.15)) / 0.6 ) = 1 + ( (1.15 - 1) / 0.6 ) = 1 + ( 0.15 / 0.60 ) = 1.25

Hope it helps. Feel free to ask a question if it's still unclear. :)


On Mon, May 21, 2018 at 6:09 PM, pavan95 <pavan.postgresdba@gmail.com> wrote:
Hi Abbas, Thanks for your valuable suggestions. To my surprise I got the same output as what I have executed before. But unfortunately I'm unable to understand the logic of the code, in specific what is base 60 number? The used data type for "effort_hours" column is 'double precision'. Kindly help me in understanding the logic. Thanks in advance. Regards, Pavan -- Sent from: http://www.postgresql-archive.org/PostgreSQL-performance-f2050081.html


--=-TazvxT9iNmL4bEhS1132--