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 1jobDK-0004Ni-MK for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 23:23:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jobDJ-00066h-Hu for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 23:23:25 +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 1jobDJ-00066a-As for pgsql-hackers@lists.postgresql.org; Thu, 25 Jun 2020 23:23:25 +0000 Received: from mail-ej1-x642.google.com ([2a00:1450:4864:20::642]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jobDH-0004Sn-5E for pgsql-hackers@postgresql.org; Thu, 25 Jun 2020 23:23:24 +0000 Received: by mail-ej1-x642.google.com with SMTP id ga4so7561061ejb.11 for ; Thu, 25 Jun 2020 16:23:22 -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=P42g4/EdqWqK4GNHyuXy0rXc3M8ZTVJwLZJAz0fXMsc=; b=mE4igP+OcjATxfRyHYlbFvTxYW4AflO6+pUXx8nmzymoA4sfHPXjJkWfw6577gqzgg m225hUnztrGO34IuASMa5Mu7zQ5pgcmL23qrcWaL8ehAfi0ZfZnT5aZeYg+FPkdunf9P 6lJ+typZCb43YM9IA79/m34u7PnWQNTi5Pok1Ko/FrioQcO8Y53qfQs79AAme4t6KiWT XY8FFss9EXRA9j73AQ2mS4tEfpRiiGT7wGUgUSQiS6AwKDY+SeY29jzd0WvqfbTIZ9ud Toz9ZzK3nx5+vGtrXhOs104L3GVb/Gc9gVbK/VmdafMSaT4OOXeaI8H3ARfWSc4xlypk mYbw== 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=P42g4/EdqWqK4GNHyuXy0rXc3M8ZTVJwLZJAz0fXMsc=; b=rwv0osSNCqcWz3NubnvaVRvv5E7OwTII+LtzBpiFZJ5Pj5htZFxXiPWM9S3HJ1t4Q7 NgnZL2q/0VwGbGL77t94jfHXFdSAJY1BHIl3bh0GNuuScFSDp7McAfDt28nHYQexBvh3 kauU/OJpqIUubolek+LdgtIKGEjG4Fdhr2WJ4jjpGk4gQPPdoQ4mNaGMecyGnSh2P26S iB6+nd/ZnpnMzn+JZ52eDwdOlXkPXfumktdqzpl4uevPxiNdtvEdy761+bTEtb8UTae3 dZKJjGQgBguIwKRqBdORzT8anaJIHELeB24LICnb1HxBg2oAgLHarjBVnuRJZNZmpEN2 0Y1g== X-Gm-Message-State: AOAM5321p/eeLb5WIyPj9BOuXdF5jdPD6eNfPM6rs34Mahk+I+tmZ7yu 08grgJHeP2XfbLLms0yXW7Fxjg== X-Google-Smtp-Source: ABdhPJwHJ5tSYdQg6g/dac//yURqGyXzS2/Y6a9GHPd/zGeYoFbhzEO9RcAfcbmUyailJP6twAEp7w== X-Received: by 2002:a17:906:c150:: with SMTP id dp16mr147617ejc.536.1593127401703; Thu, 25 Jun 2020 16:23:21 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id a1sm11790057ejk.125.2020.06.25.16.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 16:23:20 -0700 (PDT) Date: Fri, 26 Jun 2020 01:23:16 +0200 From: Tomas Vondra To: Jeff Davis Cc: Andres Freund , Tom Lane , Justin Pryzby , Bruce Momjian , David Rowley , Robert Haas , Melanie Plageman , pgsql-hackers@postgresql.org Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200625232316.cevmhw7cgra6bu6e@development> References: <129c8f1739957589584d9525e1d8782eae3f412f.camel@j-davis.com> <20200624090628.GA19640@momjian.us> <20200624123843.GX4107@telsasoft.com> <2214502.1593019796@sss.pgh.pa.us> <20200624183203.cnqcol27ruastit7@development> <2217145.1593024050@sss.pgh.pa.us> <20200624193122.cqolrvl44fh4w4s4@alap3.anarazel.de> <3e07d41d5104466cb46e3fd076c47989fe65f085.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <3e07d41d5104466cb46e3fd076c47989fe65f085.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Jun 25, 2020 at 09:42:33AM -0700, Jeff Davis wrote: >On Wed, 2020-06-24 at 12:31 -0700, Andres Freund wrote: >> nodeAgg.c already treats those separately: >> >> void >> hash_agg_set_limits(double hashentrysize, uint64 input_groups, int >> used_bits, >> Size *mem_limit, uint64 >> *ngroups_limit, >> int *num_partitions) >> { >> int npartitions; >> Size partition_mem; >> >> /* if not expected to spill, use all of work_mem */ >> if (input_groups * hashentrysize < work_mem * 1024L) >> { >> if (num_partitions != NULL) >> *num_partitions = 0; >> *mem_limit = work_mem * 1024L; >> *ngroups_limit = *mem_limit / hashentrysize; >> return; >> } > >The reason this code exists is to decide how much of work_mem to set >aside for spilling (each spill partition needs an IO buffer). > >The alternative would be to fix the number of partitions before >processing a batch, which didn't seem ideal. Or, we could just ignore >the memory required for IO buffers, like HashJoin. > I think the conclusion from the recent HashJoin discussions is that not accounting for BufFiles is an issue, and we want to fix it. So repeating that for HashAgg would be a mistake, IMHO. >Granted, this is an example where an underestimate can give an >advantage, but I don't think we want to extend the concept into other >areas. > I agree. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services