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 1jdHxz-0004HE-8V for pgsql-hackers@arkaria.postgresql.org; Mon, 25 May 2020 18:36:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jdHxy-0001dV-7e for pgsql-hackers@arkaria.postgresql.org; Mon, 25 May 2020 18:36:50 +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 1jdHxx-0001dO-TX for pgsql-hackers@lists.postgresql.org; Mon, 25 May 2020 18:36:50 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jdHxu-0002IQ-3O for pgsql-hackers@postgresql.org; Mon, 25 May 2020 18:36:48 +0000 Received: by mail-pj1-x1044.google.com with SMTP id q24so250420pjd.1 for ; Mon, 25 May 2020 11:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=7b3fRKr53Ciu+ogGsncDSBrI3Vo727tMjdjhvYIUTk8=; b=zur5+piXWAqiux0cbaY2tA81jmSSNJR4QSc4LD0c2O794HQsiXv4Vb69ocfTVPxx1o FOHAgIUGETfMHNgXUBuHAtzqbDwGRKpWTnOgm7Fh3Rq+0ybx/C7s2jQOEa8HTL/AoBYC LO8znmZSi8KHe7+lcK6ytJ1TU0qANd4agCzXpgBOR/31wPg6eK5ght38f8G9xT3moI1e /FImWOIQL8Ekfi1S6PWQo1Rgx/bwHzs6dhcdDt03eTJvVj6exYw9ZIzlgGLOM+MmDlVx A18VBlw9MM5KvS6zbZdlaD45pleMhxAmNxhgwARPU9mhsTwQVBvTZVcz6sj0NwWHkdD8 L8Gw== 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:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=7b3fRKr53Ciu+ogGsncDSBrI3Vo727tMjdjhvYIUTk8=; b=oabM23ahYycJoD6ZuKwnKEy5SMrMpnWz8dRHp3WGtzJADhxZCi8Y5uC9ZLvM7qusSO HfdaI1oZOA62knhqA65SwX4CVB8f5PfzRlI6TIZZOFG8TxxWWERS5u+TUZa2qLkV1JDf GQ9BD3Rbm7hYFKZr4Pq/yHDZNgVhygJ4ZMuntjU4aBiFfaXOrd1s5ERxHAJSjwyjAb+U GD5/mlaqJmXDEKhwQOrSDyEgU5KkZmV07BTpsn3j5gnBA2cag2X6vO/bhilOwJfrugVH eK2TcA73YpDk0VosGqrcEUM+7pF8Rwv+l9Ma8hxgVCOpYtpJN6QlrdB2qp9CLB2gk2ne GB4w== X-Gm-Message-State: AOAM530w+hXlqaSaKwTYkSZCQARTHjz0cHWvKHT+72PmbHrdASXMaABS kHW4qujdeVGy7SNAinzmnMO31g== X-Google-Smtp-Source: ABdhPJwFKeXL4EiB2XXb2d3u0lP/K0vSBB0Kscx+3yGpS1MyiXEdovhO8XCtbBZ89Ny+kA1tVeRtfA== X-Received: by 2002:a17:90a:7bcb:: with SMTP id d11mr21823523pjl.209.1590431804977; Mon, 25 May 2020 11:36:44 -0700 (PDT) Received: from jdavis.lan (c-73-231-146-4.hsd1.ca.comcast.net. [73.231.146.4]) by smtp.gmail.com with ESMTPSA id x9sm13189195pfi.13.2020.05.25.11.36.43 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 May 2020 11:36:43 -0700 (PDT) Message-ID: <978a6fa0bc00071d59ebcddf15ca72ae5aa7a15d.camel@j-davis.com> Subject: Re: Trouble with hashagg spill I/O pattern and costing From: Jeff Davis To: Tomas Vondra Cc: pgsql-hackers@postgresql.org Date: Mon, 25 May 2020 11:36:42 -0700 In-Reply-To: <20200525021045.dilgcsmgiu4l5jpa@development> References: <20200519151202.u2p2gpiawoaznsv2@development> <88dd39d782178539d7ee46f98b98579940e2a12e.camel@j-davis.com> <20200519175320.tl4qm6le5dbg2pcf@development> <20200521191318.gw3xjivrxracvzmg@development> <8619437df796903e64c8479e299d13ebacb5fbe0.camel@j-davis.com> <20200521214122.6opovye4mnbqczlc@development> <20200525021045.dilgcsmgiu4l5jpa@development> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 2020-05-25 at 04:10 +0200, Tomas Vondra wrote: > algorithm master prealloc tlist prealloc-tlist > -------------------------------------------------- > hash 1365 437 368 213 > sort 226 214 224 215 > > The sort row simply means "enable_hashagg = off" and AFAIK the > patches > should not have a lot of influence here - the prealloc does, but it's > fairly negligible. I also say a small speedup from the prealloc patch for Sort. I wrote if off initially, but I'm wondering if there's something going on there. Perhaps drawing K elements from the minheap at once is better for caching? If so, that's good news, because it means the prealloc list is a win-win. > -> Finalize HashAggregate > Group Key: lineitem_1.l_partkey > -> Gather > Workers Planned: 2 > -> Partial HashAggregate > Group Key: > lineitem_1.l_partkey > -> Parallel Seq Scan on > lineitem lineitem_1 > (20 rows) Although each worker here only gets half the tuples, it will get (approximately) all of the *groups*. This may partly explain why the planner moves away from this plan when there are more workers: the number of hashagg batches doesn't go down much with more workers. It also might be interesting to know the estimate for the number of groups relative to the size of the table. If those two are close, it might look to the planner like processing the whole input in each worker isn't much worse than processing all of the groups in each worker. Regards, Jeff Davis