Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bfkEv-00024k-L4 for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Sep 2016 08:54:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bfkEv-0003sV-7D for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Sep 2016 08:54:21 +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.84_2) (envelope-from ) id 1bfkDX-0002M7-Ef for pgsql-hackers@postgresql.org; Fri, 02 Sep 2016 08:52:55 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bfkDV-0003vG-Di for pgsql-hackers@postgresql.org; Fri, 02 Sep 2016 08:52:54 +0000 Received: by mail-wm0-x22d.google.com with SMTP id w2so19117702wmd.0 for ; Fri, 02 Sep 2016 01:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=/uNiL4+09lj/zX8ifCruuyw0lu/fThHroM9zv7EvEgM=; b=Dbyi00OUdRJs5gV7bbAxm6zm2F9OVBvxk4tBzI2u+mNdaLC16kLCZanVmvJHouwPoy vRl9Y3W7l3ULq+wvFxcoiIJ3HkESsTbY+52e+wHLst4G4AfhlRAV2t/wvmd+RaKQkUrT AfKlSpP/mzNyv/qxlmHO+iOwvmcPr4d2uSvizD6gqetmg1LCm7t8vckCgvDyIjMI1/aP y+qKLIvGjbMiBAzEVqiuxYhtuXSXempGpxtI75qNeeoSnovNSkUti23ZrUmU59lAvChT HRiqApS7AR4izcp3ADJMdMVNNPKOvWtXmHkTZNamwpSWEH0wWrd+hiBqzYJlnT0NuzWC 8aFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=/uNiL4+09lj/zX8ifCruuyw0lu/fThHroM9zv7EvEgM=; b=XmcOjjxcB+ZOeK/hlE5STLDSW2dZehbLd2QyIT4JxsPb/2qezq6rB5eNnLTnOHOnxz WDL0poo3tlvPsB7e9c8LZfEyJzL+MbyvHxDie4wCVA4SUHHLnPEWOVlJgm66Ixl9GdzL jq/jE9TC24YOs+XQaEMvbgJUL9/rUG7HT9sRVic6FKWtSGCAp/pitjs3I1CPQSAQWZuR /+OaM7Ytot1tq7faORBZoq8hw2vJ1bLt1ZVlVAd88ux5VqUC6250WaGX+yWeCQNVSJ8/ Wtql/39V5y2kW0Kw/joT6HDLAXeekWfLjRmE9dA396GC1ernH+7ef76SCWoyX0Btaqxs uvbg== X-Gm-Message-State: AE9vXwMtZdizNh7siZRJWxlfF9IbpScTx9KwHLQp/we2tzrieJPlBYFhLcYwBsI73bz9lA== X-Received: by 10.194.127.37 with SMTP id nd5mr17999071wjb.156.1472806372100; Fri, 02 Sep 2016 01:52:52 -0700 (PDT) Received: from [192.168.1.111] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by smtp.gmail.com with ESMTPSA id o2sm9432443wjo.3.2016.09.02.01.52.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Sep 2016 01:52:51 -0700 (PDT) Subject: Re: Optimizing numeric SUM() aggregate To: Andrey Borodin , pgsql-hackers@postgresql.org References: <20160803174720.1314.6360.pgcf@coridan.postgresql.org> From: Heikki Linnakangas Message-ID: Date: Fri, 2 Sep 2016 11:52:49 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160803174720.1314.6360.pgcf@coridan.postgresql.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 08/03/2016 08:47 PM, Andrey Borodin wrote: > 1. Currenlty overflow is carried every 9999 addition. I suggest that > it is possibe to do it only every (INT32_MAX - INT32_MAX / NBASE) / > (NBASE - 1) addition. Please note that with this overflow count it > will be neccesary to check whether two finishing carrings are > required. I left it at (NBASE -1), but added a comment on that. I couldn't measure any performance difference between that and a larger interval, so it didn't seem worthwhile. The code wouldn't be much more complicated, but the math required to explain what the safe maximum is, would be :-). > 2. Aggregates and numeric regression tests do not containt > any test case covering overflows. I recommend adding sum with numer 1 > 000 000 of 99 999 999 values. May be you will come up with more > clever overflow testing. Hmm. Added a couple of simple SUM() queries to the regression tests, so that we have at least some test coverage of the overflows. But nothing very clever. Looking closer, I don't think this implementation is actually dependent on NBASE being 10000. So I removed the comment changes that suggested so. I did some more minor comment fixes, and committed. Thanks for the review! - Heikki -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers