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 1job8m-0004FV-KZ for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 23:18:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1job8l-00036c-Fl for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 23:18:43 +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 1job8l-0002zq-89 for pgsql-hackers@lists.postgresql.org; Thu, 25 Jun 2020 23:18:43 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1job8f-0008C3-K1 for pgsql-hackers@postgresql.org; Thu, 25 Jun 2020 23:18:40 +0000 Received: by mail-ej1-x629.google.com with SMTP id a1so7555940ejg.12 for ; Thu, 25 Jun 2020 16:18:37 -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=8Sc8DybK8nYFtBCybe6o0/VCcZrDFp03AzJZdmLw6nI=; b=nwPs2z8cpYrirngUJ+C47bNammYD9Mq0gxqs7TcqNW1ZtEyR/s4TTCGuP+U3UqOqXM 5C3z+su3rwofj13sc/f5ixihlKAsH54whxKzzYyGcVnh7z+8zPZZx9NQ/Mhg1C8DSJLa ISk+Gz39HQq1/WmTZd/1htmTKljs+aSdRl4+uSn/rT+3BLKArtocCj8741qwjH/vBrxZ ww/A6fH9YG8pdkx6dlDFFpkB+HDgMWu/pNcPJ919G/YtP+4oOuljzeyq46WpnES0bGNU 0rjTJZ0kotq1NtjirybjYs+4XM994iCO+lb9v8cLGUNgcZHpTtLCOPuHtRRPB+PRI4fl GlxQ== 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=8Sc8DybK8nYFtBCybe6o0/VCcZrDFp03AzJZdmLw6nI=; b=gAYLoXkigsakdfOlDjGBZI3NDJjdTyDUEsMlHb8f+7wAF6aJ8exLtV+telaOjIPDsf OhJRFgpdHH15f+tuYAXw/VgCbd7ze+rQ3cFm0WeyEWzi5t7sDNumBM1S93I5Yd7i1Iwx iADlwxIDwMV4YAJS4VHsXl6Ab8p+ykICYlafzasioa+0oSmdO4ihvve6AIZiiv+h7kRH F9jD1IH7QnfUHYXl968ze2B8XJVluvTzpfGr8P6ys8hKBXTnJjCl8IJp6YbfFg7FHFaA MaeYhc4lvNEG+9Xbf4s6Wf/BHrlvLuJRLi5Hr58cxqkVgeg7pKPDkTk/0gLJQsAzDN7A GbYw== X-Gm-Message-State: AOAM530azUIHPTu7rFg+fsrl4w9qIrReCXq7CfZbxClJ68QsoerPGJae 2mpV/OAb0f6ZIFl7bjVKUk3prA== X-Google-Smtp-Source: ABdhPJzwhzlW0+QKgq3p+0w5ZOZmYq7/Y8Q16TexJeXnPUa7xAjpAKlscb+2BGCKa3rUxmMqNHBbYQ== X-Received: by 2002:a17:906:d92e:: with SMTP id rn14mr160798ejb.314.1593127115849; Thu, 25 Jun 2020 16:18:35 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id o17sm9659622ejb.105.2020.06.25.16.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 16:18:34 -0700 (PDT) Date: Fri, 26 Jun 2020 01:18:31 +0200 From: Tomas Vondra To: Andres Freund Cc: Jeff Davis , David Rowley , Robert Haas , Justin Pryzby , Melanie Plageman , "pgsql-hackers@postgresql.org" Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200625231831.weorpgrjrlbtcv6d@development> References: <129c8f1739957589584d9525e1d8782eae3f412f.camel@j-davis.com> <20200624191433.5gnqgrxfmucexldm@alap3.anarazel.de> <20200625163746.laoepc7esanptvxt@alap3.anarazel.de> <9dfde718f4994c14d88ab269b311b884cf5fa6bb.camel@j-davis.com> <20200625181623.b6g4goulga5fcabg@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200625181623.b6g4goulga5fcabg@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Jun 25, 2020 at 11:16:23AM -0700, Andres Freund wrote: >Hi, > >On 2020-06-25 10:44:42 -0700, Jeff Davis wrote: >> 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.) > >There's also ordered index scan + Group. Which will often be vastly >better than Sort+Group, but still slower than HashAgg. > > >> 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? > >I'm not saying what I propose is perfect, but I've yet to hear a better >proposal. Given that there *are* different ways to implement >aggregation, and that we use expected costs to choose, I think the >assumed costs are relevant. > I share Jeff's opinion that this is quite counter-intuitive and we'll have a hard time explaining it to users. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services