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 1jz3Bh-0001ny-P2 for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Jul 2020 19:16:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jz3Bg-00019w-K4 for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Jul 2020 19:16:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jz3Bg-00019o-8J for pgsql-hackers@lists.postgresql.org; Fri, 24 Jul 2020 19:16:56 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jz3Bc-0005Yf-8v for pgsql-hackers@postgresql.org; Fri, 24 Jul 2020 19:16:55 +0000 Received: by mail-ed1-x544.google.com with SMTP id a8so7770985edy.1 for ; Fri, 24 Jul 2020 12:16:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=a0Kz9nzYo+rvlAQB1G+yJeSefa8EWeumxFIVn1imC88=; b=ufXPbv3bj3D1dvfdo883bJi1igXKr1MfS1UgAywKpLO0t5YEI+m0sBF/uMENc9hEnA IOxIP7eqWdX7us1euCOJTinrLOgfeZGKa9udW1Yfs9rn1oCZ4MwhlLSCiaUCijcn21E1 xbkkmWlxatihxKbt1RCCKnMY5MKvFJn2Fw6kbAGosh0vYPQO/Jev17lPwUtNy3PDFf76 cCD9VOZzrKDJ4cYDftYr3eGm6lxuFt/hTngStXuye6tsoomgUYLmBGEgCGavlqPoa97F 0GLWewPJmPa7/iHj9vgfanxXVK2rFF5eoE2z5L9lpS6j6W/Gt25AobK8ag7sXVwcQFhr R9yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=a0Kz9nzYo+rvlAQB1G+yJeSefa8EWeumxFIVn1imC88=; b=P6ymuzZBbRd4235mgeBCRA6dwuuw997hlyfoQCQAZDXO0HaQBi0GqJoNA+9uYe7Qvt +CuWl7jWJ/98joij1ZFGFvbVRDfFK+P4eDJIN2EpwvY6Ha2M8mJCu3wEGvh0DhHjQ7zf 0P52LkW0PbROoLuaWTxw/jmOPh8j3jqpKKq7d4eNrfJ0i24DMcmHZvHxJYjC/RKzaFLf DWgyBLdeymyezAlzOcggFnKse4Ntw3GFh9vntTippGrWN+0KFrXOjZizpPGHZ/iB1r49 7/nzptoVUgLbHOhoNymvN2QdALQ8Ye7geuays+cjuyuTmmw1y5+KFLdqwKtMqOMR9xq0 R+vw== X-Gm-Message-State: AOAM5338Dks5/B3ijJXyTTFjWs0dBMqnYUF9k7vcWPtuKkVDomgkVCcJ 0JwgKlVfr2UTTzH13XY1T7CYKA== X-Google-Smtp-Source: ABdhPJw9dRW1cwU7rhmB3F38I0LSW8nBL3IXpmdOQflyfuRPDQmCKMAD99c5vpPICEJzS+e2quPWdA== X-Received: by 2002:a50:f413:: with SMTP id r19mr10598577edm.17.1595618211334; Fri, 24 Jul 2020 12:16:51 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id o9sm1291137edz.81.2020.07.24.12.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 12:16:50 -0700 (PDT) Date: Fri, 24 Jul 2020 21:16:48 +0200 From: Tomas Vondra To: Peter Geoghegan Cc: Robert Haas , Tom Lane , Jeff Davis , Alvaro Herrera , David Rowley , Stephen Frost , Andres Freund , Bruce Momjian , Justin Pryzby , Melanie Plageman , "pgsql-hackers@postgresql.org" Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200724191648.zmdaofoqayi4al23@development> References: <4118680.1595097043@sss.pgh.pa.us> <571473265c5d5309f4012855ebd2131c136073ab.camel@j-davis.com> <32871.1595121333@sss.pgh.pa.us> <88c0af01ad9ac105e424768808a214d855e29a77.camel@j-davis.com> <20200720004827.4c46ikcdrfum6xyu@development> <400617.1595251041@sss.pgh.pa.us> <20200720172539.6jov6ynljly4wj6i@development> <20200724012248.y77rpqc73agrsvb3@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jul 24, 2020 at 11:03:54AM -0700, Peter Geoghegan wrote: >On Fri, Jul 24, 2020 at 8:19 AM Robert Haas wrote: >> This is all really good analysis, I think, but this seems like the key >> finding. It seems like we don't really understand what's actually >> getting written. Whether we use hash or sort doesn't seem like it >> should have this kind of impact on how much data gets written, and >> whether we use CP_SMALL_TLIST or project when needed doesn't seem like >> it should matter like this either. > >Isn't this more or less the expected behavior in the event of >partitions that are spilled recursively? The case that Tomas tested >were mostly cases where work_mem was tiny relative to the data being >aggregated. > >The following is an extract from commit 1f39bce0215 showing some stuff >added to the beginning of nodeAgg.c: > >+ * We also specify a min and max number of partitions per spill. Too few might >+ * mean a lot of wasted I/O from repeated spilling of the same tuples. Too >+ * many will result in lots of memory wasted buffering the spill files (which >+ * could instead be spent on a larger hash table). >+ */ >+#define HASHAGG_PARTITION_FACTOR 1.50 >+#define HASHAGG_MIN_PARTITIONS 4 >+#define HASHAGG_MAX_PARTITIONS 1024 > Maybe, but we're nowhere close to these limits. See this table which I posted earlier: 2MB Planned Partitions: 64 HashAgg Batches: 4160 4MB Planned Partitions: 128 HashAgg Batches: 16512 8MB Planned Partitions: 256 HashAgg Batches: 21488 64MB Planned Partitions: 32 HashAgg Batches: 2720 256MB Planned Partitions: 8 HashAgg Batches: 8 This is from the non-parallel runs on the i5 machine with 32GB data set, the first column is work_mem. We're nowhere near the 1024 limit, and the cardinality estimates are pretty good. OTOH the number o batches is much higher, so clearly there was some recursive spilling happening. What I find strange is that this grows with work_mem and only starts dropping after 64MB. Also, how could the amount of I/O be almost constant in all these cases? Surely more recursive spilling should do more I/O, but the Disk Usage reported by explain analyze does not show anything like ... regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services