Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0ycB-0008Kn-AD for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Mar 2018 00:06:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f0yc9-00063c-Gr for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Mar 2018 00:06:53 +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 1f0yc9-00063S-5m for pgsql-hackers@lists.postgresql.org; Wed, 28 Mar 2018 00:06:53 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f0yc1-0004UN-OM for pgsql-hackers@postgresql.org; Wed, 28 Mar 2018 00:06:51 +0000 Received: by mail-wm0-x236.google.com with SMTP id f125so1861067wme.4 for ; Tue, 27 Mar 2018 17:06:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=oOn6lYwnecZomzuvnctPP3f4yRI5uBUIQoF8rL+FCec=; b=V6EDvIoxeXMvPTCtPKXB5C+ofFM1KALZMikVcegM9ZH1ZKASmnDITgUPiA+fLMjXmn 9wWmTrAzjs8eQ+izQsooh0zrtKKVuaDQAdam5ZC5qbTjIy4qLWw1jVZ25a7S/p7Qm/O0 3Q4RkneayN/ZoNXlYMp71RqVe0HCr4CfIeBR3K1Gx8Df7byi5ks/8hw8ffS7QL0FAtY/ 1zmgtlRTK5gibrzpFcCDIWVk5mgSgLu8OJyv4HJki2/8pHjpCPsmmehvGu4i8bcgVpWV VIaiTmzDaWd0LZBWQjkfnWVUOjyECSE9GcwCWbj2FeauCCGJ5v5fsV2atINgWbVRRALN sHog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=oOn6lYwnecZomzuvnctPP3f4yRI5uBUIQoF8rL+FCec=; b=JiPqTFmuEClCiRHURssghUbIwGBD01Fm52I4cZ90mVT6/C4e9PkY2jKvK3jjSLTd8g elbKEXU+E/tX0LPedP/Puvn9CrAGLE/y9+gLnoo53JG0wiBykbKuNxK2lslPou7NQAAV BYu8O3/yoK19xiAA1F4rNOLgHYVR1A/90VRLExxBkB2UHfj42GQQvU2v00wbX1kr1kDs hgDd0CNbQ1tsWtRNTcciFr2QVAiCzxj01sxPJ0czdNQQt07mv2hq89B9zpQS7l6tD3Nh tLU/PP5gJsXBCS58rorryKwFm63RQyVKs92ka/2LS+j3xE9nwTst6d+D3e6nG9ho51pd cqdw== X-Gm-Message-State: AElRT7EZHEp0loD9J8bNjVJEj+LJ6GGWFCSb4062U5r3ePUz0VD6OLF0 /u6G6dcU5AovL9C37kb9WfQE3qyk7p18ZWMNGOIeC0EQXkSo9+/C9E0fmET4OmJtw9wv/tvmDLM RDRieoCcS0gd5sisi2BMbmnNEp/3QmW8r+/GCVMJqtup+J/T8j9NnVAeAHQdj+PEwLiMUUqYgsZ +L44NvW5X9 X-Google-Smtp-Source: AIpwx48BPXfZv35J2DncIOt4zW1xEQ0dKUgdpka04Y/gY3RnNXtZ49aR/NebhJuu8k11NJ9p2EMgHA== X-Received: by 10.28.94.131 with SMTP id s125mr831056wmb.83.1522195601802; Tue, 27 Mar 2018 17:06:41 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id h190sm3326007wmd.22.2018.03.27.17.06.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 17:06:40 -0700 (PDT) Subject: Re: Parallel Aggregates for string_agg and array_agg To: David Rowley , Tom Lane Cc: Stephen Frost , Andres Freund , PostgreSQL-development References: <24abe018-b3c6-2117-b5b9-39e660db00bd@2ndquadrant.com> <1b6ee15c-c218-761e-0120-c1ed438e2db2@2ndquadrant.com> <657be73a-a21d-0ae1-5c62-870afbdfddd4@2ndquadrant.com> <20180326022647.GL24540@tamriel.snowman.net> <20180326132009.GN24540@tamriel.snowman.net> <6538.1522096067@sss.pgh.pa.us> <25812.1522108164@sss.pgh.pa.us> From: Tomas Vondra Message-ID: <452e8b7f-418b-4e61-c212-c0e4410b94ad@2ndquadrant.com> Date: Wed, 28 Mar 2018 02:06:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/27/2018 04:51 AM, David Rowley wrote: > On 27 March 2018 at 13:45, David Rowley wrote: >> On 27 March 2018 at 12:49, Tom Lane wrote: >>> Oh, I thought of another thing that would need to get done, if we decide >>> to commit this. array_agg_serialize/deserialize only work if the array >>> element type has send/receive functions. The planner's logic to decide >>> whether partial aggregation is possible doesn't look any deeper than >>> whether the aggregate has serialize/deserialize, but I think we have to >>> teach it that if it's these particular serialize/deserialize functions, >>> it needs to check the array element type. Otherwise we'll get runtime >>> failures if partial aggregation is attempted on array_agg(). >>> >>> This would not matter for any core datatypes, since they all have >>> send/receive functions, but I imagine it's still pretty common for >>> extension types not to. >>> >>> For my money it'd be sufficient to hard-code the test like >>> >>> if ((aggserialfn == F_ARRAY_AGG_SERIALIZE || >>> aggdeserialfn == F_ARRAY_AGG_DESERIALIZE) && >>> !array_element_type_has_send_and_recv(exprType(aggregate input))) >> >> I'd failed to consider this. >> >> Would it not be cleaner to just reject trans types without a >> send/receive function? Or do you think that would exclude other valid >> cases? > > Seems I didn't mean "trans types". I should have said aggregate > function argument types. > > The attached I adds this check. > I'm not sure that's better than the check proposed by Tom. An argument type without send/receive function does not necessarily mean we can't serialize/deserialize the trans value. Because who says the argument value will be embedded in the trans value? For example, I might create an aggregate to build a bloom filter, accepting anyelement. That will hash the argument value, and obviously has no issues with serializing/deserializing the trans value. This check would effectively disable parallelism for all aggregates with anyarray, anyelement, anynonarray, anyenum (and a few more) arguments. That for example includes jsonb_agg, which some people already mentioned as another candidate for enabling parallelism. Not great, I guess. Tom's solution is much more focused - it recognizes that array_agg is a fairly rare case where the (actual) argument type gets stored in the trans type, and detects that. PS: The function is misnamed - you're talking about argument types, yet the function name refers to transtypes. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services