Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfF58-0007w3-C8 for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Jun 2019 02:51:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfF55-0001Iv-Nf for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Jun 2019 02:51:43 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfF55-0001Io-BG for pgsql-bugs@lists.postgresql.org; Mon, 24 Jun 2019 02:51:43 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfF4w-0005oO-0r for pgsql-bugs@lists.postgresql.org; Mon, 24 Jun 2019 02:51:41 +0000 Received: by mail-ed1-x544.google.com with SMTP id w13so19424630eds.4 for ; Sun, 23 Jun 2019 19:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=E6ZHKGZod8rt6g4ftI/yWEFctY1omwJNUNPLRpaYyMY=; b=ooXY5eSwJtlnH6DipuL4Pgj4P8hxNUl9MdmI0ahuTcEOlu+/wcEXND8jwN1PM+m4nn 07ktS8I4flNfb2g19Fk7jjqasRsKgA4vSRVucu8VS3I2T/pBqhWBgAw7fkcX4NN/85gb vN2UA7XOIPo6/lpfhnmen7VyP1rHHztB5PafB9VBnsP2rCmPIZICI17Tna2gemxdvxmf rhPDnHEtq2QPtvRYaNqr/F1q+PyYigWKsuvWpqg/+NQiM9qVXzJHEwnDHpDnWQ23k4C8 kNopcefCaWuICdTAppUfDEvMY3TzJyKLiv4J3RVoB8x04/IJCwZ8L27ibKrRgaermkR+ s6HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=E6ZHKGZod8rt6g4ftI/yWEFctY1omwJNUNPLRpaYyMY=; b=aj0u/rWVj/7ZEf63ysXmQM7QWJqJqalhW+imENr5imdebWljkHvsJMfo/syUsCszSM 3rRraYz5aKcSBf2h0G6rm9motwVeD3OGIX1ZMoFFbCzKEoJuuRmU9/4hfwniQjyuDmrD f1q4UV/8G2YLlg6fKMxmRoDjQe2CsyN9vKJ77GylcoJHYYiQwz69evWUMmuZljZ36X6y hwcFq4qBY/ds+yYLYa1Z1Xf5lkEXKjycnYCaGmkHyBIYFz2kOwUFl31B+O+oK/PO6ADB MGTLlt3szc/wLDX3vUbVYDnf7pBhlO/9/sXEREH77gDUQTWi8WY4DU4zJRSGHsZGQbei jTXw== X-Gm-Message-State: APjAAAVGuLHFMNpEv8WFcoSplDLHzz5U/yqXIXjXkA5Whb8ikJY1u8Cq 4RenbXtOM/VK+zQAtKYoGXVLex6L1D7JOSBbowqMhA== X-Google-Smtp-Source: APXvYqyzQtnCIVksMdT/CdN4vTulTVIiw2rK7fXT5Fa8hqc0rFGpQXhpopwbmdQVEn9EVKnC+59OtYHsjdFRKU7c7BM= X-Received: by 2002:a17:906:db:: with SMTP id 27mr70644432eji.153.1561344692682; Sun, 23 Jun 2019 19:51:32 -0700 (PDT) MIME-Version: 1.0 References: <15869-32aa02312ddc6be7@postgresql.org> In-Reply-To: <15869-32aa02312ddc6be7@postgresql.org> From: David Rowley Date: Mon, 24 Jun 2019 14:51:19 +1200 Message-ID: Subject: Re: BUG #15869: Custom aggregation returns null when parallelized To: kdorsel@gmail.com, PostgreSQL mailing lists Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 24 Jun 2019 at 03:32, PG Bug reporting form wrote: > Here's the setup code: > --CREATE TABLE temp (val double precision); > --insert into temp (val) select i from generate_series(0, 150000) as t(i); > --set force_parallel_mode = on; > select (stats_agg(val)).* from temp; I don't think force_parallel_mode does what you think it does. It just adds a Gather node to the top of the plan, if the plan is deemed parallel safe. It's not going to force your aggregate to be parallelised. You might coax the planner into generating a parallel aggregate plan by setting parallel_tuple_cost and parallel_setup_cost both to 0. > Expected results: > 150001, 37500, 75000, 112500 > > Results when run in parallel: > 150001, null, null, null Are you actually getting a partial and finalize aggregate node with that? Can you show the EXPLAIN output of each? You might also want to double check your combine function. It does not look like it's very well coded to handle NULL values for arrays that have yet to receive their fill of 5 elements. -- David Rowley http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services