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 1josPo-00021g-7H for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jun 2020 17:45:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1josPl-0008GU-IX for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jun 2020 17:45:25 +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 1josPl-0008GN-7G for pgsql-hackers@lists.postgresql.org; Fri, 26 Jun 2020 17:45:25 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1josPg-0005gD-OU for pgsql-hackers@postgresql.org; Fri, 26 Jun 2020 17:45:23 +0000 Received: by mail-ed1-x543.google.com with SMTP id b15so7551449edy.7 for ; Fri, 26 Jun 2020 10:45:20 -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=wAOUlvzW9gHtSxBHcXZCyJMMkU1jBHdKIdrb/RVXGwg=; b=Wxdc3lMVwLV1ecylbJwEyqkTTNpq9TXEsBHK7pu+rr3w+ISbunbD3BzTNwKAe4baJ2 saDBiYUQitqYqi9VbEBK4vMSfOwczAJRlHgh1JUtxRNYwFif3d6ZUDAIklTXXOzPrB02 tLKtF7KtmDFartKJIfXyg22zkXvpF56xuYVMrrX5hzzE0opr4VGjZst/VlsOXgthzRB/ mOa9vP0ZBJWPztzXijOY51MCZHIQoJKGiuqsLfdqJWPndWZqp5fVvMSLao3xe6IKixzM Z4ZbgBPl9b6rmYL6oo7+KOqKy/PyaZF/OJ3LPdJIx6COHQVDYW8QyNs/Chyre2QvDdT4 RoPg== 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=wAOUlvzW9gHtSxBHcXZCyJMMkU1jBHdKIdrb/RVXGwg=; b=oGvR7UbM3B+jMjDx742BmqCNwTpRSV0VvAznKHYvnu60zcjad5/k9Vk0N5OySBFjBL fh47R2p0YLxlF4beAECmGCvKW52dUg/VC4inRq1o1VkdIzzxvRXzAMh79JDa+liQUeeO f3qBTSjHsXAU1AmIfQPRagnSaEwX4CYOI0u6dCxV4MVOrN6BklP+6Sy2lzbjOSLbLBQx PtqtLkE5O9QMaXpH2xQbEvlHLolW57x+BVmFrwgEE6Zwq8x7C0y1840skO6tPWv7G4du G/eYoaWlaxgH/TOylMpHIOC4gPYXrcUsZCpPhyhBFtkzc00lB9mP0IuPp5bedxvCuI6H 1xGQ== X-Gm-Message-State: AOAM533PkXUqj9F38eepGc4YyBnOoGtAzt2qPGVS4ZKQDo2LOt7O+JcF WrUql7af8v3NyEwFNZ03WlmdlQ== X-Google-Smtp-Source: ABdhPJzADhuNH6RwlPu4oowtY9PDpVnbHdGdMPsMQyqkIEX6EsynWcHNNwrzyIuTyWa+hwn3X/s5BA== X-Received: by 2002:aa7:da46:: with SMTP id w6mr4413570eds.31.1593193518462; Fri, 26 Jun 2020 10:45:18 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id v23sm20884382edr.94.2020.06.26.10.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 10:45:17 -0700 (PDT) Date: Fri, 26 Jun 2020 19:45:13 +0200 From: Tomas Vondra To: Bruce Momjian Cc: 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: <20200626174513.tmnkic7q5duugvhh@development> References: <20200624171203.GB17842@momjian.us> <20200624191900.t4sbfk236gndwoa3@alap3.anarazel.de> <20200624231810.GB13627@momjian.us> <20200624233837.GA21436@momjian.us> <20200625171756.GB12486@momjian.us> <20200625235357.udlest4k6i2uekui@development> <20200626040210.GA13963@momjian.us> <20200626144414.rftlidu34rigiulv@development> <20200626163726.GA3337@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200626163726.GA3337@momjian.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jun 26, 2020 at 12:37:26PM -0400, Bruce Momjian wrote: >On Fri, Jun 26, 2020 at 04:44:14PM +0200, Tomas Vondra wrote: >> On Fri, Jun 26, 2020 at 12:02:10AM -0400, Bruce Momjian wrote: >> > On Fri, Jun 26, 2020 at 01:53:57AM +0200, Tomas Vondra wrote: >> > > I'm not saying it's not beneficial to use different limits for different >> > > nodes. Some nodes are less sensitive to the size (e.g. sorting often >> > > gets faster with smaller work_mem). But I think we should instead have a >> > > per-session limit, and the planner should "distribute" the memory to >> > > different nodes. It's a hard problem, of course. >> > >> > Yeah, I am actually confused why we haven't developed a global memory >> > allocation strategy and continue to use per-session work_mem. >> > >> >> I think it's pretty hard problem, actually. One of the reasons is that > >Yes, it is a hard problem, because it is balancing memory for shared >buffers, work_mem, and kernel buffers: > > https://momjian.us/main/blogs/pgblog/2018.html#December_7_2018 > >I think the big problem is that the work_mem value is not one value but >a floating value that is different per query and session, and concurrent >session activity. > >> the costing of a node depends on the amount of memory available to the >> node, but as we're building the plan bottom-up, we have no information >> about the nodes above us. So we don't know if there are operations that >> will need memory, how sensitive they are, etc. >> >> And so far the per-node limit served us pretty well, I think. So I'm not >> very confused we don't have the per-session limit yet, TBH. > >I was thinking more of being able to allocate a single value to be >shared by all active sesions. > Not sure I understand. What "single value" do you mean? Wasn't the idea was to replace work_mem with something like query_mem? That'd be nice, but I think it's inherently circular - we don't know how to distribute this to different nodes until we know which nodes will need a buffer, but the buffer size is important for costing (so we need it when constructing the paths). Plus then there's the question whether all nodes should get the same fraction, or less sensitive nodes should get smaller chunks, etc. Ultimately this would be based on costing too, I think, but it makes it soe much complex ... >Also, doesn't this blog entry also show that spiling to disk for ORDER >BY is similarly slow compared to hash aggs? > > https://momjian.us/main/blogs/pgblog/2012.html#February_2_2012 > The post does not mention hashagg at all, so I'm not sure how could it show that? But I think you're right the spilling itself is not that far away, in most cases (thanks to the recent fixes made by Jeff). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services