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 1kl8KB-0006wn-1r for pgsql-general@arkaria.postgresql.org; Fri, 04 Dec 2020 10:28:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kl8KA-0004B1-0F for pgsql-general@arkaria.postgresql.org; Fri, 04 Dec 2020 10:28:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kl8K9-0004Au-K8 for pgsql-general@lists.postgresql.org; Fri, 04 Dec 2020 10:28:25 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kl8K6-000688-Uu for pgsql-general@postgresql.org; Fri, 04 Dec 2020 10:28:24 +0000 Received: by mail-ed1-x531.google.com with SMTP id k4so5318888edl.0 for ; Fri, 04 Dec 2020 02:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=vRJkj1V4jrxrmzPD3+Lpxiiv/nkCtld5H9AZhn99o0A=; b=2R1h8q+DovTNXC1HbYWl4jPYRH/zpHE7R8I1l72caD4ZacnBK8LUhmdGEiQUu2MLK/ gVwrGBZaW274QUpr+uovPn1GD/oB5lQOnqm/8GLZTkiBKr0dbOBCVCn6vEQ6JP9EZAxE KKdUZpb11oPE9fgfGztgr3LZ0ZUTo8ZdhMOikTrQN2zJbw6FtP/9cVO4UP+0UeBViomI jOCM9F4KU6rMvFcwh3Pfi32ItkSgDNAy6kwOo1VJNMlqQvDT7orp9fMVh+2DHOEid+ab tvSVKu/15t+Vs6Cq0t+oE1GopaQ2NE4OhuW3pRm6P4ci7yTo15ZuAatYEr/2Ft7h7704 4Jeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=vRJkj1V4jrxrmzPD3+Lpxiiv/nkCtld5H9AZhn99o0A=; b=NRI+afILLvCSmo/KD5H5NMe/kfSiac+dBs4Q8h1R24Bz8ZKuH4s9B2FeCAtN/B8oD/ Ku1QVAAHrfB5jhTwdnWgL3d48j2tU+6Vc+e1VJMVKQHjJfkFMhgjb8NLmda3Q3H9mfz/ 13RDtCjMZfoNR+cWYOq0GUh3JsG/7Z2ozPFgZf1Dw23B3XJ7sNp3NbgIbfdSY2W2qQzT uAR8DcYcvXxdcB/Y9JOWdbclX7xLH5fGXacy/exp9Lhv9iflth5wWzueqtzAhb74tqK3 rVM4Kha1KVwPDp3/c6NNwOw7TT1Nmpp5oBgnnnPji+Hea+0OZiQUb0H4RBmQxFu52Lkm R8Fg== X-Gm-Message-State: AOAM532U7xr5YpG3rT/7tdEHbese/HSvFQdfeOGpnl1PxY/lg5sXa6uA G2uE7FnlvnQ61Bh2L8tRsJFD4LEXGp1/dNY8 X-Google-Smtp-Source: ABdhPJzBMWOZhyGFIx3qklByTtq7sz37SKeGzqsrCU9vzFb59rTyWs0E/Eutets8tXWInbHQn68xSQ== X-Received: by 2002:a50:cd0a:: with SMTP id z10mr6856829edi.223.1607077700818; Fri, 04 Dec 2020 02:28:20 -0800 (PST) Received: from localhost.localdomain (91-115-149-10.adsl.highway.telekom.at. [91.115.149.10]) by smtp.gmail.com with ESMTPSA id rl7sm1543652ejb.107.2020.12.04.02.28.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 02:28:20 -0800 (PST) Message-ID: <5e1fd40aabddb1447f051c860e359cd0ec9b5301.camel@cybertec.at> Subject: Re: Number of parallel workers chosen by the optimizer for parallel append From: Laurenz Albe To: pgsql-general@postgresql.org Date: Fri, 04 Dec 2020 11:28:19 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 2020-11-25 at 17:36 +0100, Laurenz Albe wrote: > I have a partitioned table, each partition has "parallel_workers = 10" set. > > SET max_parallel_workers_per_gather = 8; > > SET enable_partitionwise_aggregate = on; > > EXPLAIN (COSTS OFF) > SELECT applicant_name, count(ipc_4) > FROM laurenz.z_flat > GROUP BY applicant_name; > > QUERY PLAN > -------------------------------------------------- > Gather > Workers Planned: 4 > -> Parallel Append > -> HashAggregate > Group Key: z_flat_3.applicant_name > -> Seq Scan on xyz_4 z_flat_3 > -> HashAggregate > Group Key: z_flat.applicant_name > -> Seq Scan on xyz_1 z_flat > [8 more such partition scans] > (33 rows) > > How does the optimizer decide to use 4 parallel workers? > > No matter what I try, I cannot influence that number. I figured it out. This is automatically calculated from the number of partitions, and the number of parallel workers is ld(#partitions) + 1 where "ld" is the logarithm of base 2 (function "fls" in the source). It might be nice to make this configurable, but since we don't have storage parameters on partitioned tables, I wonder how. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com