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 1joYc6-00088a-V7 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 20: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 1joYc5-0006pT-MB for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 20:36:49 +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 1joYc3-0006pM-Oi for pgsql-hackers@lists.postgresql.org; Thu, 25 Jun 2020 20:36:49 +0000 Received: from [66.111.4.29] (helo=out5-smtp.messagingengine.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1joYbz-0006rw-N5 for pgsql-hackers@postgresql.org; Thu, 25 Jun 2020 20:36:46 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id C4CF05C005D; Thu, 25 Jun 2020 16:36:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 25 Jun 2020 16:36:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=vyGFTOdcclpxjPDAcaN6uvG6bEr EkAZoDoZCZ+9gJwQ=; b=VoOei6IVPYTjB9qKymmPqsm0dJlVWFJlD/j24px9sdl t92r9MUea0mh+weUVrztopcLZi4bjcTBMNV26V0X5Rs3wGilk8/8e6gm55bNPwUD R+cKg60JgEQcVoIzpyRE/O2Ibwne5lfH8e0gkpy8sQjA+XadBMPWrAhaheHIVOTp u4EVL1I1cz6VCt9u9RpPJg9VqgsmzzKFteXRz1aIqV9pqQBA5h7XLCpGEykzrXtX qaL0WFc9NBEiXKMsI9IpfbQwXXiC5pBqZ43q6vxzHpmzI0lePGYThVS7Ng5LtVWV hfMSvwAPhURLJnh/wbTmzF67w/BAt9dwhYUhbqoMlUw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=vyGFTO dcclpxjPDAcaN6uvG6bErEkAZoDoZCZ+9gJwQ=; b=cUDsOKisXpYiU3duOfASus x0Ok1wy8fSNkPQ/kiFojsDVRx1dgbLCqbxhndpCsw4RYTYpBIJMpwlgK1fPM26th C0EX9ci+w1GfQqO0t5j3DIPDFOCSFK41ZwONoa1dbxrxIzZqlxBcERvXZLmqRNx/ AJvDoEIpaE9RJbSyDeRMxCsi9IHuMlFo36+AQdgOx8UpHwsitHcU57LJJUfacoVA e+Hvd5JG/nbBW+bhluSQAhEm8TEQ4En2MiAMOYFFvJcZMFbfWmTIDEUIfjocbRn0 YGdFxMuF4gtOIHg4KOFmQHZ4/JKi/mTkpxpW1x+L5Fq7MO+ZNRyX3eLQ95phXN3Q == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudekledgudehfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepudekhfekleeugeevteehleffffejgeelueduleeffeeutdelffeujeff hfeuffdunecukfhppeeijedrudeitddrvddujedrvdehtdenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghl rdguvg X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-217-250.hsd1.ca.comcast.net [67.160.217.250]) by mail.messagingengine.com (Postfix) with ESMTPA id C254E3280064; Thu, 25 Jun 2020 16:36:30 -0400 (EDT) Date: Thu, 25 Jun 2020 13:36:29 -0700 From: Andres Freund To: Bruce Momjian Cc: Jeff Davis , Robert Haas , David Rowley , Justin Pryzby , Melanie Plageman , Tomas Vondra , "pgsql-hackers@postgresql.org" Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200625203629.7m6yvut7eqblgmfo@alap3.anarazel.de> References: <20200624090628.GA19640@momjian.us> <20200624171203.GB17842@momjian.us> <20200624191900.t4sbfk236gndwoa3@alap3.anarazel.de> <20200624231810.GB13627@momjian.us> <20200624233837.GA21436@momjian.us> <20200625171756.GB12486@momjian.us> <8fd82a9e6c00b73191d18940b2da6a94a30477af.camel@j-davis.com> <20200625182512.GC12486@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200625182512.GC12486@momjian.us> X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.29 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2020-06-25 14:25:12 -0400, Bruce Momjian wrote: > I am still trying to get my head around why the spill is going to be so > much work to adjust for hash agg than our other spillable nodes. Aggregates are the classical case used to process large amounts of data. For larger amounts of data sorted input (be it via explicit sort or ordered index scan) isn't an attractive option. IOW hash-agg is the common case. There's also fewer stats for halfway accurately estimating the number of groups and the size of the transition state - a sort / hash join doesn't have an equivalent to the variably sized transition value. > What are people doing for those cases already? Do we have an > real-world queries that are a problem in PG 13 for this? I don't know about real world, but it's pretty easy to come up with examples. query: SELECT a, array_agg(b) FROM (SELECT generate_series(1, 10000)) a(a), (SELECT generate_series(1, 10000)) b(b) GROUP BY a HAVING array_length(array_agg(b), 1) = 0; work_mem = 4MB 12 18470.012 ms HEAD 44635.210 ms HEAD causes ~2.8GB of file IO, 12 doesn't cause any. If you're IO bandwidth constrained, this could be quite bad. Obviously this is contrived, and a pretty extreme case. But if you imagine this happening on a system where disk IO isn't super fast (e.g. just about any cloud provider). An even more extreme version of the above is this: query: SELECT a, array_agg(b) FROM (SELECT generate_series(1, 50000)) a(a), (SELECT generate_series(1, 10000)) b(b) GROUP BY a HAVING array_length(array_agg(b), 1) = 0; work_mem = 16MB 12 81598.965 ms HEAD 210772.360 ms temporary tablespace on magnetic disk (raid 0 of two 7.2k server spinning disks) 12 81136.530 ms HEAD 225182.560 ms The disks are busy in some periods, but still keep up. If I however make the transition state a bit bigger: query: SELECT a, array_agg(b), count(c), max(d),max(e) FROM (SELECT generate_series(1, 10000)) a(a), (SELECT generate_series(1, 5000)::text, repeat(random()::text, 10), repeat(random()::text, 10), repeat(random()::text, 10)) b(b,c,d,e) GROUP BY a HAVING array_length(array_agg(b), 1) = 0; 12 28164.865 ms fast ssd: HEAD 92520.680 ms magnetic: HEAD 183968.538 ms (no reads, there's plenty enough memory. Just writes because the age / amount thresholds for dirty data are reached) In the magnetic case we're IO bottlenecked nearly the whole time. Just to be clear: I think this is a completely over-the-top example. But I do think it shows the problem to some degree at least. Greetings, Andres Freund