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 1j4egZ-0007qY-PS for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Feb 2020 05:47:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j4egX-0006dG-Bf for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Feb 2020 05:47:41 +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 1j4egX-0006d7-2I for pgsql-hackers@lists.postgresql.org; Thu, 20 Feb 2020 05:47:41 +0000 Received: from mx0a-00296801.pphosted.com ([148.163.150.38]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j4egO-0005o3-Hk for pgsql-hackers@postgresql.org; Thu, 20 Feb 2020 05:47:40 +0000 Received: from pps.filterd (m0114582.ppops.net [127.0.0.1]) by mx0a-00296801.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01K5cVhj005272 for ; Thu, 20 Feb 2020 05:47:27 GMT Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by mx0a-00296801.pphosted.com with ESMTP id 2y8ud69ak6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Feb 2020 05:47:27 +0000 Received: by mail-pf1-f198.google.com with SMTP id d127so1776069pfa.7 for ; Wed, 19 Feb 2020 21:47:27 -0800 (PST) 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=+TNnFuPIj5r8GyTGmwcZzXWJvrAIpNhtHV9NqFZz0Z4=; b=MYGbf7Klc4vzaCHpOKNh/jpvFLlAnosb5tM2NJstR6x7nylvOvA0uva0W0K+t6j41j sqeIcy/x+BdRj7EJbfwhg646KORBr5MnumgV7zYPm7rJ36SIugfxkVvx1fOhiffcZznx 5EU+c9EI/yJaN40DSHxCg6vHvMIwp+BbLF3DP92NSX2S7J1UyWAQ9YUkV6oshbuX9X+1 8skTXPtWEfQWYohz9jLDaKXRpDL9+Mk3NkttgOVmPm1fabKXMixHs25yC4OXsiZzY8we 6Con3wUl/jIkH/W1WTsIF7qN1DT3vhzvhDWBpa/iiq4znxydUktRFZcuLp6zc1hJY7f6 Mdiw== X-Gm-Message-State: APjAAAVcWayg0vo26uoJcjJJ3mk8Ead2MNERrz39yUvDk5ZRfeTHZETr dZWpdyqCbIe61DYTaSF45zVK672Y8eFYcjrVpWZctTqjTVmYjwlmoM9JOHqyzn2L/OvajVPu0o/ DlXRE7T8ZAILz5lrRDWUkoFF5ZW+F0tjUgtFIJnQQMiq9owh4uA== X-Received: by 2002:a63:e65:: with SMTP id 37mr31017550pgo.171.1582177647048; Wed, 19 Feb 2020 21:47:27 -0800 (PST) X-Google-Smtp-Source: APXvYqwXxvErdKUpSz7hsuG0usFkB9IGevvTbovyv8rUeCEfJnDAwMsg0Fzp4SCntZUrMYxVmklmwg== X-Received: by 2002:a63:e65:: with SMTP id 37mr31017525pgo.171.1582177646624; Wed, 19 Feb 2020 21:47:26 -0800 (PST) Received: from localhost (li1619-9.members.linode.com. [172.104.39.9]) by smtp.gmail.com with ESMTPSA id 13sm1557246pfi.78.2020.02.19.21.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 21:47:25 -0800 (PST) Date: Thu, 20 Feb 2020 13:47:19 +0800 From: Adam Lee To: Tomas Vondra Cc: Jeff Davis , Melanie Plageman , Heikki Linnakangas , Taylor Vesely , Melanie Plageman , Pg Hackers Subject: Re: Memory-Bounded Hash Aggregation Message-ID: <20200220054719.GB4389@earth.local> References: <20190802152123.ichmacgx3y3x7dc3@development> <20191214173225.3kzsbncr6brpxdll@development> <775d754c-9a61-5363-6998-f87d15f1b592@iki.fi> <20200218185749.srk733n4z57lzxf2@development> <7612ea4d636b6341d0606f4e852d584798e04901.camel@j-davis.com> <20200219191636.gvdywx32kwbix6kd@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200219191636.gvdywx32kwbix6kd@development> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_01:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=407 clxscore=1015 phishscore=0 suspectscore=1 mlxscore=0 impostorscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200039 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Feb 19, 2020 at 08:16:36PM +0100, Tomas Vondra wrote: > 5) Assert(nbuckets > 0); > ... > This however quickly fails on this assert in BuildTupleHashTableExt (see > backtrace1.txt): > > Assert(nbuckets > 0); > > The value is computed in hash_choose_num_buckets, and there seem to be > no protections against returning bogus values like 0. So maybe we should > return > > Min(nbuckets, 1024) > > or something like that, similarly to hash join. OTOH maybe it's simply > due to agg_refill_hash_table() passing bogus values to the function? > > > 6) Another thing that occurred to me was what happens to grouping sets, > which we can't spill to disk. So I did this: > > create table t2 (a int, b int, c int); > > -- run repeatedly, until there are about 20M rows in t2 (1GB) > with tx as (select array_agg(a) as a, array_agg(b) as b > from (select a, b from t order by random()) foo), > ty as (select array_agg(a) AS a > from (select a from t order by random()) foo) > insert into t2 select unnest(tx.a), unnest(ty.a), unnest(tx.b) > from tx, ty; > > analyze t2; > ... > > which fails with segfault at execution time: > > tuplehash_start_iterate (tb=0x18, iter=iter@entry=0x2349340) > 870 for (i = 0; i < tb->size; i++) > (gdb) bt > #0 tuplehash_start_iterate (tb=0x18, iter=iter@entry=0x2349340) > #1 0x0000000000654e49 in agg_retrieve_hash_table_in_memory ... > > That's not surprising, because 0x18 pointer is obviously bogus. I guess > this is simply an offset 18B added to a NULL pointer? I did some investigation, have you disabled the assert when this panic happens? If so, it's the same issue as "5) nbucket == 0", which passes a zero size to allocator when creates that endup-with-0x18 hashtable. Sorry my testing env goes weird right now, haven't reproduced it yet. -- Adam Lee