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 1ktLD5-0004tQ-8X for pgsql-bugs@arkaria.postgresql.org; Sun, 27 Dec 2020 01:51:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ktLD2-0007Hm-UD for pgsql-bugs@arkaria.postgresql.org; Sun, 27 Dec 2020 01:51:00 +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 1ktLD2-0007Hf-Jz for pgsql-bugs@lists.postgresql.org; Sun, 27 Dec 2020 01:51:00 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ktLD0-0002pl-Ah for pgsql-bugs@lists.postgresql.org; Sun, 27 Dec 2020 01:50:59 +0000 Received: by mail-pl1-x62c.google.com with SMTP id s15so3940605plr.9 for ; Sat, 26 Dec 2020 17:50:57 -0800 (PST) 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=OsSjLzSY7533UD0MATplINxi3cO8vEb073UqZAfG2yI=; b=BGFKHUZU5Vn/4/y29lJq3NxSm+/cryu4V+PfFM7pZTnrqQioyOWN+WnIlRNpjTMyZg /kOfPWuFCb9b3heXhhpy5lSA2wixv58Hjr3MtX48wtyiubQzSVLPvZGQzhdWpqk34QOz 9qeqFb2PNL+tlosQfh3p02Ep/Qq5J2Y9ZWOUvozp/lM2dClMjAiNYn79LzJtb62owY0E DKGA5BAgmG56cUU3g/KZZ3eh5itbqD5oB0WSGk7JV8HHKBRTjChd1odD2WrMfgMjBTk2 3d70R9bHvh5gYTHyx7A9AD1+7YYbDT05DrYgGStnh1ZKCw8J/hwKy8/2BEZargwHtl46 bhfg== 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=OsSjLzSY7533UD0MATplINxi3cO8vEb073UqZAfG2yI=; b=V66Wn+Epr4SvttdLHhhPO+sRJR0e0HqHKYEogHNPbPShat+E028uErbPLZl9N5Gm6h YF9SXTJGMeyQI2PMs+clQ+Km904/TdIQoaHkU8rPopN6UxIqbKVRigPAioR+VPRIzXns I0GaC+DJsuAG95snkNi+weK2KKNSs9xMhtau7os6SoBdY7sMlyI9p76iLAx76adIfNRb OOoWJRjtTxwf3a1i95AKCusVl4H9iovcwJguDccXampwA0ASWVI670ICpRsYXu4z1Jgc KMMkPJ8gltgpkSqYxBo0hEhV6RuhtQReL2e102PWTJZKh2qFRJCa9x5HvAqxmsty06nl 5LIQ== X-Gm-Message-State: AOAM53104hI3KpjzjxDWrySiPmMN5FD2q+gLvWADw7toen6wdYfyWgMJ 6FFCmTP1JYVPnNYkf9vGd1Qt9Q== X-Google-Smtp-Source: ABdhPJyqxY6YZEzl5lOWtDMAjqb2q52i2o5LPItyySDbgHQ8lWd3T9ZU2KmNfNNQVwkPKSk7j4GDLA== X-Received: by 2002:a17:902:b206:b029:dc:1f41:962d with SMTP id t6-20020a170902b206b02900dc1f41962dmr39834986plr.28.1609033856033; Sat, 26 Dec 2020 17:50:56 -0800 (PST) Received: from jdavis.lan (c-73-231-146-4.hsd1.ca.comcast.net. [73.231.146.4]) by smtp.gmail.com with ESMTPSA id w6sm16577724pfq.208.2020.12.26.17.50.54 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Dec 2020 17:50:55 -0800 (PST) Message-ID: Subject: Re: BUG #16784: Server crash in ExecReScanAgg() From: Jeff Davis To: Tom Lane , exclusion@gmail.com Cc: pgsql-bugs@lists.postgresql.org Date: Sat, 26 Dec 2020 17:50:53 -0800 In-Reply-To: <553495.1608578766@sss.pgh.pa.us> References: <16784-7ff169bf2c3d1588@postgresql.org> <553495.1608578766@sss.pgh.pa.us> 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 Thank you for the report, Alexander! On Mon, 2020-12-21 at 14:26 -0500, Tom Lane wrote: > /* there could be residual pergroup pointers; clear them */ > for (int setoff = 0; > setoff < aggstate->maxsets + aggstate->num_hashes; > setoff++) > aggstate->all_pergroups[setoff] = NULL; > > I suspect this is clearing the wrong subset of the all_pergroups > pointers, but the code is so underdocumented that I'm not very > sure. That's correct, but there was a (bad) reason it was done that way that I had to fix first. A null pergroup was used as a signal not to advance a group that has spilled, but that's only a good solution for the hashed grouping sets, not the sorted grouping sets (which is what caused this bug). Instead, I solved it by simply not compiling the expressions for the sorted grouping sets, so that agg_refill_hash_table() can leave those pergroups alone. Regards, Jeff Davis