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 1jzlTT-000313-JD for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Jul 2020 18:34:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jzlTS-00080B-GD for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Jul 2020 18:34:14 +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 1jzlTS-0007wY-3N for pgsql-hackers@lists.postgresql.org; Sun, 26 Jul 2020 18:34:14 +0000 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jzlTP-0002he-FA for pgsql-hackers@postgresql.org; Sun, 26 Jul 2020 18:34:12 +0000 Received: by mail-ej1-x643.google.com with SMTP id o18so14822870eje.7 for ; Sun, 26 Jul 2020 11:34:11 -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=I0yO6vvzTtV10sXMv5qP6+xR1CjsFJsUS+c7ZOEyKe4=; b=S3WwFBcaoWIbAzogxboZXSnGMLifrhAxqntHGSGzLoHVjGkNyyFl/RdCATXhTXjtDP WVYqtmN8agCw7DgHU0aHTy3zFOwzBEKp9zqMsHU+EDiF1lSS26yvdT8tYgUwqIvXezak Hp2kVUPPqW6eKod1EH6YlwLaccdlGsSJYYBc1/qedgo2440Nqe1ur9sKWbOF4z1X5lnw kjcvEZd+e1/AP5szeCohKKJ1mFC5iiriKwoeHa5b34bdl1wI3lfetvcGpYV8mMUSEOE3 S9sv96+rWSd3XAgHoJSlnCiO36n6OYQK69uTWFOd1hP0BquJFoTqlk+MlJnOnlnmFb8+ Tucg== 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=I0yO6vvzTtV10sXMv5qP6+xR1CjsFJsUS+c7ZOEyKe4=; b=lYYNQqtRey9JZhQu6WddY3rkJu2wCEy5kCdHXz74bkDiRIflphSBPCxeAl8uUV/NjN NKqo2gmqmbwjMs7YVIy4mJ38aJ8LezJ1DFr1Qa0XbP9NIfsYgc9D7xtoCQXTp6AS0gzf 5GdIWS/eWCsmc25EBLVIRST772Hy1BE2kA15J1j0+TZFNpzmD5C2WskIqpTJ2a7MG4J7 vYyUCvKBrZJERxHPzweGgFftiUn6MwoVObLHCajLN5kuH2CO00bxGVa+39latSzQhGm/ VMPEGa9+KclXFsJs6/Zbu1tiwBcj+qZVwk2mW44kH5ciNMDq+SHyJjhGfKuE6cSB/q8M 3lZA== X-Gm-Message-State: AOAM531eaCejEbDX6VGL1Uy2iVYUCKEWLE2mKDYdlG/gvwSjQFL68kuD qe3b4OsFUJPfKqUS3gU6KQUDbQ== X-Google-Smtp-Source: ABdhPJxlbEKj79htB1fx9+1XFx550pYjtnWqJ9huHKnjDhkd3V0ol6l8YTq/A8a+SMt1+IewFVoRag== X-Received: by 2002:a17:906:6d56:: with SMTP id a22mr9691252ejt.440.1595788449311; Sun, 26 Jul 2020 11:34:09 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id c15sm5821410edm.47.2020.07.26.11.34.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2020 11:34:08 -0700 (PDT) Date: Sun, 26 Jul 2020 20:34:06 +0200 From: Tomas Vondra To: Peter Geoghegan Cc: Robert Haas , Tom Lane , Jeff Davis , Alvaro Herrera , David Rowley , Stephen Frost , Andres Freund , Bruce Momjian , Justin Pryzby , Melanie Plageman , "pgsql-hackers@postgresql.org" Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200726183406.qlpunydmex4rxspl@development> References: <20200720172539.6jov6ynljly4wj6i@development> <20200724012248.y77rpqc73agrsvb3@development> <20200724191648.zmdaofoqayi4al23@development> <20200726000509.vtl4p7vzazdr2dif@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Jul 25, 2020 at 05:13:00PM -0700, Peter Geoghegan wrote: >On Sat, Jul 25, 2020 at 5:05 PM Tomas Vondra > wrote: >> I'm not sure what you mean by "reported memory usage doesn't reflect the >> space used for transition state"? Surely it does include that, we've >> built the memory accounting stuff pretty much exactly to do that. >> >> I think it's pretty clear what's happening - in the sorted case there's >> only a single group getting new values at any moment, so when we decide >> to spill we'll only add rows to that group and everything else will be >> spilled to disk. > >Right. > >> In the unsorted case however we manage to initialize all groups in the >> hash table, but at that point the groups are tiny an fit into work_mem. >> As we process more and more data the groups grow, but we can't evict >> them - at the moment we don't have that capability. So we end up >> processing everything in memory, but significantly exceeding work_mem. > >work_mem was set to 200MB, which is more than the reported "Peak >Memory Usage: 1605334kB". So either the random case significantly That's 1.6GB, if I read it right. Which is more than 200MB ;-) >exceeds work_mem and the "Peak Memory Usage" accounting is wrong >(because it doesn't report this excess), or the random case really >doesn't exceed work_mem but has a surprising advantage over the sorted >case. > >-- >Peter Geoghegan -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services