Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0NAW-00062e-AY for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Nov 2022 13:30:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p0NAV-0000uo-6F for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Nov 2022 13:30:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0NAU-0000uX-Mi for pgsql-hackers@lists.postgresql.org; Wed, 30 Nov 2022 13:30:30 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p0NAQ-0008Ja-9b for pgsql-hackers@postgresql.org; Wed, 30 Nov 2022 13:30:30 +0000 Received: from mail.postgrespro.ru (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id A967221C3FB0; Wed, 30 Nov 2022 16:30:24 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1669815024; bh=i6AVmLan4lGkoz1pdQdldpD0JifCqsX85T8PwQpV1a8=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=aYqNA/CPAmHR3bTnPI/c9jIpC8USMaJRgfWrm3iopvjofAFcjf77bzy+Fhzn15n/u 5GITNemLWU68MD4IhI4WR2zmMz5PPmUMsa/Tps6lf9jeJecJcjojDopJyvTv5jfnfJ 8zSpJ1AOg1X1kLSwla+uZen5T5pXnjszHd9+3tFQ= MIME-Version: 1.0 Date: Wed, 30 Nov 2022 16:30:24 +0300 From: Alexander Pyhalov To: "Fujii.Yuki@df.MitsubishiElectric.co.jp" Cc: Tomas Vondra , PostgreSQL-development , Andres Freund , Julien Rouhaud , Daniel Gustafsson , Ilya Gladyshev Subject: Re: Partial aggregates pushdown In-Reply-To: References: <05d98f67a4f44b31d90dfb977db4ad71@postgrespro.ru> <317f8de58ce9889e056f2944e200a44d@postgrespro.ru> <2ed9ad03bc17cfb86da900d541a270b0@postgrespro.ru> <20220114121653.mjzqelwgnzwqhkoa@jrouhaud> <0cc653ad90dbfc5ca0fd8bb1ca57e1a7@postgrespro.ru> <2ad047732a8b8a9aaaad06fef59fb283@postgrespro.ru> <925e2d3f11283d8b2707fc5d827fc3e9@postgrespro.ru> <20220322004914.opkwl3beedl4uhks@alap3.anarazel.de> <57db913f-02c6-66af-2928-513e2b1c65f7@enterprisedb.com> <8dc86e502fbd9d04da0dc6cdd4156f84@postgrespro.ru> <313df801f860f653ebb8c6422794a5b5@postgrespro.ru> User-Agent: Roundcube Webmail/1.4.11 Message-ID: <4c02341e5e1b10f35c7b3dfbc73084f0@postgrespro.ru> X-Sender: a.pyhalov@postgrespro.ru Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Fujii.Yuki@df.MitsubishiElectric.co.jp писал 2022-11-30 13:01: > Hi Mr.Pyhalov. > >> 1) In previous version of the patch aggregates, which had >> partialaggfn, were ok >> to push down. And it was a definite sign that aggregate can be pushed >> down. >> Now we allow pushing down an aggregate, which prorettype is not >> internal and >> aggfinalfn is not defined. Is it safe for all user-defined (or >> builtin) aggregates, >> even if they are generally shippable? Aggcombinefn is executed locally >> and we >> check that aggregate function itself is shippable. Is it enough? >> Perhaps, we >> could use partialagg_minversion (like aggregates with >> partialagg_minversion >> == -1 should not be pushed down) or introduce separate explicit flag? > In what case partial aggregate pushdown is unsafe for aggregate which > has not internal aggtranstype > and has no aggfinalfn? > By reading [1], I believe that if aggcombinefn of such aggregate > recieves return values of original > aggregate functions in each remote then it must produce same value > that would have resulted > from scanning all the input in a single operation. > One more issue I started to think about - now we don't check partialagg_minversion for "simple" aggregates at all. Is it correct? It seems that , for example, we could try to pushdown bit_or(int8) to old servers, but it didn't exist, for example, in 8.4. I think it's a broader issue (it would be also the case already if we push down aggregates) and shouldn't be fixed here. But there is an issue - is_shippable() is too optimistic. -- Best regards, Alexander Pyhalov, Postgres Professional