Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j5fLv-0002Uw-0j for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Feb 2020 00:42:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j5fLr-0007WZ-Pe for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Feb 2020 00:42:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j5fLr-0007WS-Af for pgsql-hackers@lists.postgresql.org; Sun, 23 Feb 2020 00:42:31 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j5fLj-0008UI-2V for pgsql-hackers@postgresql.org; Sun, 23 Feb 2020 00:42:30 +0000 Received: by mail-wr1-x429.google.com with SMTP id r11so6171635wrq.10 for ; Sat, 22 Feb 2020 16:42:22 -0800 (PST) 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=rcj2j4YciDTQarZwqoM1cEVw8IL+HSxHDU67Gduk83I=; b=Qi/smGx9U2ykLYBwzCBSqsRZJoRZLIuivjsNLvzz2TMYdGlv3RxXeSJNGSPVW1jgKk 3xXZpkrHGa1RKXijC4pumwDNP8NIJdAGgsUQtR7BuqfUBdZnT5b3KAjnQTibKLsMZfF6 OvIYPCGelYxGTKHV8K2gMgHTlKnDqQh0MMleDTv0ZZ/3gR130Ys5EkduZM9yG+nHkGV5 sOHWffvO6Gw1bMKfyUQuMwPLUiqtqHu0xwIEdFsjXZZYY6PIvCkgQC0cjafUKc8Y9oW8 EH6h3iAj3WNSRBQAeO4cA36GFKTLQNG/nGSXWo3uWkkLa+okmjpVMZfYo8AYP4iFAgUr hZfg== 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=rcj2j4YciDTQarZwqoM1cEVw8IL+HSxHDU67Gduk83I=; b=UAu1+oe3EJJzwl9NWj+6H8oDNyjzK9Ub3ZwAMEm24X3lBIerVISLgKIKNm0xf+SVbL mMyZfpmDj16xRlumR2nAmN+qg3Gt5SPVLPUIuTSJI/89N8i18zXmXbMpBMekvvL05dsj q63lbYypOi85fmFUsz5aMEJOPf5lAWztaYs5CMKm67gP+6wFOzHIE8rIfzfspLlORtbi /uG7y+hyNCxO5pLgv8vK8ryeON7QzYitzm0Bj/CORyTvVWKyq28iXEfU7SA+asYfTWou XVTxNXXWODDXtCLMqc8Mapxkcgs1YVzQIrxoMcXB6q1DCjZb8gBEbKmAq5GOgYRe9Mwz 1R4g== X-Gm-Message-State: APjAAAXsw86hmZC8cN2z+i3TmWR5ypUYTptpirnmX+BQws8vMSKalEW8 xklBNXLh4sPI4AlRC+oH2Je5MQ== X-Google-Smtp-Source: APXvYqwEfDpzz668ZtW8oecbc/f/SRhTa0RJiTGL3pyjqXvqB1AvqtdJXp6JEeYUaDdVYSnVWeDx4g== X-Received: by 2002:a5d:4f0f:: with SMTP id c15mr59971642wru.251.1582418539539; Sat, 22 Feb 2020 16:42:19 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id l8sm11205202wmj.2.2020.02.22.16.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Feb 2020 16:42:18 -0800 (PST) Date: Sun, 23 Feb 2020 01:42:16 +0100 From: Tomas Vondra To: Jeff Davis Cc: Melanie Plageman , Heikki Linnakangas , Taylor Vesely , Adam Lee , Melanie Plageman , Pg Hackers Subject: Re: Memory-Bounded Hash Aggregation Message-ID: <20200223004216.obvgyvmusnsscnsk@development> References: <20191214173225.3kzsbncr6brpxdll@development> <775d754c-9a61-5363-6998-f87d15f1b592@iki.fi> <20200218185749.srk733n4z57lzxf2@development> <7612ea4d636b6341d0606f4e852d584798e04901.camel@j-davis.com> <20200219191636.gvdywx32kwbix6kd@development> <732b17848c2333e50f146e656a9c4f75ff818f05.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <732b17848c2333e50f146e656a9c4f75ff818f05.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Feb 20, 2020 at 04:56:38PM -0800, Jeff Davis wrote: >On Wed, 2020-02-19 at 20:16 +0100, Tomas Vondra wrote: >> 1) explain.c currently does this: >> >> I wonder if we could show something for plain explain (without >> analyze). >> At least the initial estimate of partitions, etc. I know not showing >> those details until after execution is what e.g. sort does, but I >> find >> it a bit annoying. > >Looks like you meant to include some example explain output, but I >think I understand what you mean. I'll look into it. > Oh, right. What I wanted to include is this code snippet: if (es->analyze) show_hashagg_info((AggState *) planstate, es); but I forgot to do the copy-paste. >> 2) The ExecBuildAggTrans comment should probably explain "spilled". > >Done. > >> 3) I wonder if we need to invent new opcodes? Wouldn't it be simpler >> to >> just add a new flag to the agg_* structs instead? I haven't tried >> hacking >> this, so maybe it's a silly idea. > >There was a reason I didn't do it this way, but I'm trying to remember >why. I'll look into this, also. > >> 4) lookup_hash_entries says >> >> /* check to see if we need to spill the tuple for this grouping >> set */ >> >> But that seems bogus, because AFAIK we can't spill tuples for >> grouping >> sets. So maybe this should say just "grouping"? > >Yes, we can spill tuples for grouping sets. Unfortunately, I think my >tests (which covered this case previously) don't seem to be exercising >that path well now. I am going to improve my tests, too. > >> 5) Assert(nbuckets > 0); > >I did not repro this issue, but I did set a floor of 256 buckets. > Hmmm. I can reproduce it reliably (on the patch from 2020/02/18) but it seems to only happen when the table is large enough. For me, doing insert into t select * from t; until the table has ~7.8M rows does the trick. I can't reproduce it on the current patch, so ensuring there are at least 256 buckets seems to have helped. If I add an elog() to print nbuckets at the beginning of hash_choose_num_buckets, I see it starts as 0 from time to time (and then gets tweaked to 256). I suppose this is due to how the input data is generated, i.e. all hash values should fall to the first batch, so all other batches should be empty. But in agg_refill_hash_table we use the number of input tuples as a starting point for, which is how we get nbuckets = 0. I think enforcing nbuckets to be at least 256 is OK. >> which fails with segfault at execution time: > >Fixed. I was resetting the hash table context without setting the >pointers to NULL. > Yep, can confirm it's no longer crashing for me. >Thanks! I attached a new, rebased version. The fixes are quick fixes >for now and I will revisit them after I improve my test cases (which >might find more issues). > OK, sounds good. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services