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 1joVve-0003Kw-NH for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 17:44:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1joVvd-0003ms-Jy for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 17:44:49 +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 1joVvd-0003lt-DK for pgsql-hackers@lists.postgresql.org; Thu, 25 Jun 2020 17:44:49 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1joVva-0000KQ-Hs for pgsql-hackers@postgresql.org; Thu, 25 Jun 2020 17:44:48 +0000 Received: by mail-pj1-x1035.google.com with SMTP id cm23so3594123pjb.5 for ; Thu, 25 Jun 2020 10:44:46 -0700 (PDT) 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=ykN3tXohdReTg0ahPudVLT9FniZBi6MFUfOrZcMnCBk=; b=NRxdGJJg+u+AOA/65yjm0vNnZM8/8EI2gl3JdM49ztcF2VXVUX5ANjY9HODS70e6L5 TnrONyxPIigBzj6FczqpyLPC40cp0LOCstLTUQV3pVE+hLw/p8vfsZbc0dJJMuplpseC 2MPPIRAs+rPV9a0cBgy2itk9qVE0iYbSIdwWBNwDfceYdJ6ri/B+LP1wQlAxPjkPxFJ7 WM+rGTFIpXAlOfPjVQYIL5vw9sBisaD2lSl9wNgrk+Pyp3g6ipG8GKm127FYYfrHTl/P qRhky8bSKIivo6fHCSdPowQAtJCXcedYpVhI0xw+ZWGpmUGSWIluAEKY8K7NoryM7l8T SPEw== 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=ykN3tXohdReTg0ahPudVLT9FniZBi6MFUfOrZcMnCBk=; b=ebPg0OYf7sRR2r/CS2PAbmDUlLqk0aN9iHNQ3DwaGsxRWA/vg9BCIqNxuXWvWLHJEV kcd1xVgwu55rh973h9UYSAWlm53EDfztUuw7vT6oELlsClcO+eEuLg49/2+aaD7cp9nE E2oDEiG/2ppHvjcCGP3sI63UZCz0ayo3X876rTYG0mfS1sAdJC00UqfMS97LK0kYbkTR hFFAavl5bJ6aXEW0Ye/ZyIqKeb6dgEvpCPJCvvd8DcbuJuz1sohPe/BMo4kiNA76Nqsp /ngCDQirV11RXP1jDC0p/n8i2pA0ya4SgbGWZU+/xhHG/JH5FMie/0XS4Cx7t5vWNgsp bIXw== X-Gm-Message-State: AOAM530SbOrV+ctvVeM36l2VZJ7Jth0rhJG4UMnG4Qu5x+h9xgldC/Db viRJrmx08KJrt38bE0WyIB/6xw== X-Google-Smtp-Source: ABdhPJwRmPRICoIXv/BjPCFy2Mcm/r6TafeZ8XDON/Oz3dWaKZLyCsqVZCc38AGio+Em/qKfIpUFSg== X-Received: by 2002:a17:90a:ca13:: with SMTP id x19mr4654401pjt.85.1593107085410; Thu, 25 Jun 2020 10:44:45 -0700 (PDT) Received: from jdavis.lan (c-73-231-146-4.hsd1.ca.comcast.net. [73.231.146.4]) by smtp.gmail.com with ESMTPSA id m3sm15669431pfk.171.2020.06.25.10.44.43 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Jun 2020 10:44:44 -0700 (PDT) Message-ID: <9dfde718f4994c14d88ab269b311b884cf5fa6bb.camel@j-davis.com> Subject: Re: Default setting for enable_hashagg_disk From: Jeff Davis To: Andres Freund Cc: David Rowley , Robert Haas , Justin Pryzby , Melanie Plageman , Tomas Vondra , "pgsql-hackers@postgresql.org" Date: Thu, 25 Jun 2020 10:44:42 -0700 In-Reply-To: <20200625163746.laoepc7esanptvxt@alap3.anarazel.de> References: <20200610021544.GA14879@telsasoft.com> <8bff2e4e8020c3caa16b61a46918d21b573eaf78.camel@j-davis.com> <129c8f1739957589584d9525e1d8782eae3f412f.camel@j-davis.com> <20200624191433.5gnqgrxfmucexldm@alap3.anarazel.de> <20200625163746.laoepc7esanptvxt@alap3.anarazel.de> 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 On Thu, 2020-06-25 at 09:37 -0700, Andres Freund wrote: > > Let's say you have work_mem=32MB and a query that's expected to use > > 16MB of memory. In reality, it uses 64MB of memory. So you are > > saying > > this query would get to use all 64MB of memory, right? > > > > But then you run ANALYZE. Now the query is (correctly) expected to > > use > > 64MB of memory. Are you saying this query, executed again with > > better > > stats, would only get to use 32MB of memory, and therefore run > > slower? > > Yes. I think that's ok, because it was taken into account from a > costing > perspective int he second case. What do you mean by "taken into account"? There are only two possible paths: HashAgg and Sort+Group, and we need to pick one. If the planner expects one to spill, it is likely to expect the other to spill. If one spills in the executor, then the other is likely to spill, too. (I'm ignoring the case with a lot of tuples and few groups because that doesn't seem relevant.) Imagine that there was only one path available to choose. Would you suggest the same thing, that unexpected spills can exceed work_mem but expected spills can't? Regards, Jeff Davis