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 1f0sUX-0000iR-VP for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Mar 2018 17:34:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f0sUW-0008Ip-G1 for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Mar 2018 17:34:36 +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 1f0sRx-0004ny-Qp for pgsql-hackers@lists.postgresql.org; Tue, 27 Mar 2018 17:31:58 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f0sRt-0003bm-PS for pgsql-hackers@postgresql.org; Tue, 27 Mar 2018 17:31:56 +0000 Received: by mail-wm0-x235.google.com with SMTP id l9so290462wmh.2 for ; Tue, 27 Mar 2018 10:31:53 -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=aL8xgegOlmi2lrq98qyne8pFvixl/QFz0XxXmB+AFAw=; b=2IKi66gEmd9GPZcLsbk08quONDibUjYQSZgV1thtHthpV1GICmnITr2Mg/IhrDXFOY yqas/g+EwVOoIHz8j9GwztEwkW4j3MJUd9VjdoWfaOee3fsrhWAku9KSuConzImjO1HU NkEhBWzP/b1PfewKX2mqIXi06iwucgZcWAf4ve4QSSu1FW97YxXrhySqk+GpaReZ3jEJ vEAOnavy84lAKJDXHJpk041EHegw35qxihYn78oT1PBbS9ZH96WIqepU5jzfeyPmmqST 6PqCKJ1grAUEiGjkgVFnq9lDXXwlTd9/xZdQ50uaZlcfyLmIlNi7Pr/bC1V1tqoBiZGP IGaQ== 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=aL8xgegOlmi2lrq98qyne8pFvixl/QFz0XxXmB+AFAw=; b=gMSA325mv4YjRfHCeXhyXNaZ9906avhizmxAirsp7KE4X0V4CKdhTbxZbhYC5d6uei BVTShSJLiobNySSpFCsFJM66fl4peVBuGCzlMJJ7vH0hgWjslGOdDaZu0os0tQq7Hmgc 6OEpvAoHFdA/XySu/Z+MdpKLtnhbIuL2I5LdKMgA80UxaaE/ynT4ITSri/w6/gGYXnRT +iTOc1NeLyyg2BaCyJ8cnDVShH9i6bKiYnuX94bJpB3sk50W2ldTE1Qa2CGO+wyAErRW 1iMwtA+fuT+Sgx91e+x/9RqquMufpWa8JT/NW+WaiXGxVKUTNc17ZisgzQmVMV0X5SkG 3KBg== X-Gm-Message-State: AElRT7Gd1C40+iNIr2wRBnsBjVRrXjHKh8WFe7TZrahpKUtAjWFEW3WS 3rlutfCrPAR5Hz0y0zKhDBgKOV5D+/LsDaLt7W7rLSb0W/nU+qRSdrwuDfdze1GH8xL/DI6wdPs GT/MvrsoraBlmRllCdDLNs4k8Lk4KTPtPzBmbDmgzlQs9Z2GTxZiAf5uucsnfd9xO14EhOgw96x Eq+Vh6Kia0 X-Google-Smtp-Source: AIpwx4+6Q/WuJXZFQOVTvkL7eg/YBYTPeL8lUg6/SJO3aNsKHRnJbYq/w4t1jKUteu7dnOYp1YWmqQ== X-Received: by 10.28.159.68 with SMTP id i65mr136161wme.27.1522171910964; Tue, 27 Mar 2018 10:31:50 -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 p19sm2942874wrb.75.2018.03.27.10.31.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 10:31:49 -0700 (PDT) Subject: Re: Parallel Aggregates for string_agg and array_agg To: Tom Lane , David Rowley Cc: Alvaro Herrera , Stephen Frost , Andres Freund , PostgreSQL-development References: <20180327002617.fjgkgxmeojfkti7b@alvherre.pgsql> <13700.1522162694@sss.pgh.pa.us> From: Tomas Vondra Message-ID: <05f1e4ea-4c73-3ac8-6dd1-14e0a94aa005@2ndquadrant.com> Date: Tue, 27 Mar 2018 19:31:46 +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: <13700.1522162694@sss.pgh.pa.us> 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:58 PM, Tom Lane wrote: > David Rowley writes: >> On 27 March 2018 at 13:26, Alvaro Herrera wrote: >>> synchronized_seqscans is another piece of precedent in the area, FWIW. > >> This is true. I guess the order of aggregation could be made more >> certain if we remove the cost based optimiser completely, and just >> rely on a syntax based optimiser. > > None of this is responding to my point. I think the number of people > who actually don't care about aggregation order for these aggregates > is negligible, and none of you have argued against that; you've > instead selected straw men to attack. > I don't quite see what the straw men are, TBH. (And David's response was obviously meant as a tongue-in-cheek.) Let me try addressing your point, as stated in your earlier message. On 03/27/2018 12:28 AM, Tom Lane wrote: > My argument here is that only a very tiny fraction of > string_agg/array_agg users will not care about aggregation order, > and thus I don't believe that this patch can help very many people. > Against that, it's likely to hurt other people, by breaking their > queries and forcing them to insert expensive explicit sorts to fix > it. You're claiming this is a choice between "reliable aggregation order" vs. "parallel aggregation." I find that dubious. My argument is that we do not provide any reliable aggregation order, unless the user supplies ORDER BY in the aggregate, or takes care about input ordering (essentially doing a subquery with ORDER BY). Users may rely on getting the "right" plan, but unless they take special care (disabling some plans etc.) that's just pure luck. Not only is there plenty of stuff that can trigger plan change (misestimates, data growth, ...) but we also add new plans that don't produce the same ordering (e.g. parallel versions of some plans). And if they already take the extra care, they can disable parallel query to get the same plan. It's true that's all or nothing, and they might be benefiting from parallel query in different part of the query, in which case they'll need to modify the query. > Even discounting the backwards-compatibility question, we don't > normally adopt performance features for which it's unclear that the > net gain over all users is positive. We only really have anecdotal data, both of us. We can make some guesses, but that's about it. I don't know anyone who would be relying on array_agg ordering without the explicit ORDER BY somewhere (particularly not after major upgrades). But obviously those issues only surface after the change is made. I do however know people who are badly affected by array_agg() disabling parallel aggregate for other aggregates. They don't care about aggregate order (typically it's filtering + unnest or export). > Maybe what that says is that rather than giving up on this > altogether, we should shelve it till we have less stupid > planner+executor behavior for ORDER BY inside aggregates. That's > been on the to-do list for a long while, but not risen to the top > ... That would be a valid choice if there was a reliable aggregate order. But AFAIK there isn't, as explained above. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services