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 1jq1P8-0008LT-KJ for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2020 21:33:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jq1P6-0002gA-E6 for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2020 21:33:28 +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 1jq1P5-0002g3-LD for pgsql-hackers@lists.postgresql.org; Mon, 29 Jun 2020 21:33:27 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jq1P2-0005qR-Ns for pgsql-hackers@postgresql.org; Mon, 29 Jun 2020 21:33:26 +0000 Received: by mail-ed1-x52c.google.com with SMTP id d18so8633032edv.6 for ; Mon, 29 Jun 2020 14:33:24 -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=Tt6UjFi6GsSDmbv8vsnxeoJEsp2tVkvGQg7POwuzbcY=; b=PUUJmCkEKGeXrOduBDGRMjcLMqi5BcPqbRdmML5AcmAZ0g1PpiKDSJ357JIukQe/0K 0qdLwO95ietSbk1ohF0MHOtNgF8o529HWQuVyADOr/k1GCftAj3/R2pFePpPZpu46ldW QUX0YAbkkNY4VGWaQWwkvwYvJ/FaDITei9sSFlr3gmnhDLaepaKJsAcDHKYM4Eg31Gu9 4yZNNFqlX/OkEQnWskJUJYyUJx4mSllkRGQxkJYurXc+pLuw8vtzoY2NO7pyZBX0srrO i18tM7uvzlidy8ovorW/oMbB0YuuId3bmFOqeNGZNpC9bCEkE0u3RDcVVzPO8tQzHw2b Ik7w== 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=Tt6UjFi6GsSDmbv8vsnxeoJEsp2tVkvGQg7POwuzbcY=; b=Dhu/+gAQLID+AWrMo0rJTSPqLWeopGMXajaf4w+8Gt4eBe0tse/YxwlcjdKNl2xNK+ JScEmdxKNwru/bsscbrLP3W1enaq5T+ywbHRCCAP8cLykclg3bcVTtYuWu2dRhOphS3C g0M4bNfuJcyHYXR/HRsViQMVrXuMiP6ANHpJgKwLxP1SPcGtusQy8JeMUstvGR08koTw MkijLCqMZhYhP3k8ey6XO8c93AJj4zbozXOjTn4n+wgRuwDmZqLx12Ernr0JEzIghuGp mmtsh22ZjYUBv9IuMzmiJPDU7SuXPkdxCxo5YJGcBm6iXZ5lSCgvby8MJY+UxwUeeKP6 z4Jg== X-Gm-Message-State: AOAM531CxxzFi6v5usmaEFhO9vM/jjZSlHqk6qxRZLW0/aZDuaaZAwfR WafLu+ZKXKEpBNFYF1UQAQxe2g== X-Google-Smtp-Source: ABdhPJzNSGwJh4rX83k/sC8HTJPBCTXr84o181dME/BRltdwgr/Vto7p2NXufjMEHwu4TFBla0Ydkw== X-Received: by 2002:a05:6402:134e:: with SMTP id y14mr19950731edw.4.1593466403163; Mon, 29 Jun 2020 14:33:23 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id d2sm841446edk.4.2020.06.29.14.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 14:33:22 -0700 (PDT) Date: Mon, 29 Jun 2020 23:33:19 +0200 From: Tomas Vondra To: Bruce Momjian Cc: Peter Geoghegan , Robert Haas , Andres Freund , David Rowley , Jeff Davis , Justin Pryzby , Melanie Plageman , "pgsql-hackers@postgresql.org" Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200629213319.ldfbi6wiyh6idf6e@development> References: <20200626163726.GA3337@momjian.us> <20200626174513.tmnkic7q5duugvhh@development> <20200626230020.GD3337@momjian.us> <20200626235850.gvl3lpfyeobu4evi@development> <20200627104141.gq7d3hm2tvoqgjjs@development> <20200629150655.ethstxkf3bkqoown@development> <20200629173140.GE17529@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200629173140.GE17529@momjian.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Jun 29, 2020 at 01:31:40PM -0400, Bruce Momjian wrote: >On Mon, Jun 29, 2020 at 10:20:14AM -0700, Peter Geoghegan wrote: >> I have no reason to believe that the planner is any more or any less >> likely to conclude that the hash table will fit in memory in v13 as >> things stand (I don't know if the BufFile issue matters). >> >> In general, grouping estimates probably aren't very good compared to >> join estimates. I imagine that in either v12 or v13 the planner is >> likely to incorrectly believe that it'll all fit in memory fairly >> often. v12 was much too permissive about what could happen. But v13 is >> too conservative. > >FYI, we have improved planner statistics estimates for years, which must >have affected node spill behavior on many node types (except hash_agg), >and don't remember any complaints about it. > I think misestimates for GROUP BY are quite common and very hard to fix. Firstly, our ndistinct estimator may give pretty bad results depending e.g. on how is the table correlated. I've been running some TPC-H benchmarks, and for partsupp.ps_partkey our estimate was 4338776, when the actual value is 15000000, i.e. ~3.5x higher. This was with statistics target increased to 1000. I can easily imagine even worse estimates with lower values. This ndistinct estimator is used even for extended statistics, so that can't quite save us. Moreover, the grouping may be on top of a join, in which case using ndistinct coefficients may not be possible :-( So I think this is a quite real problem ... regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services