Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hW0FP-0000yg-DG for pgsql-hackers@arkaria.postgresql.org; Wed, 29 May 2019 15:12:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hW0FN-0002wi-Jq for pgsql-hackers@arkaria.postgresql.org; Wed, 29 May 2019 15:12:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hW0FN-0002wa-3f for pgsql-hackers@lists.postgresql.org; Wed, 29 May 2019 15:12:09 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hW0FJ-0002ar-9B for pgsql-hackers@postgresql.org; Wed, 29 May 2019 15:12:07 +0000 Received: by mail-wr1-x444.google.com with SMTP id h1so2070693wro.4 for ; Wed, 29 May 2019 08:12:05 -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:user-agent; bh=lOUCwcmzhszLJp6WJJ66/hIbQddXLfnUTrddSaEhDeg=; b=FMikZVqNMMLZFbbeeliMBF8wIJKm+L0I386NBuvMnD51b/JVf+E5ZmjRbn3mQ3b2+P 70l2CpbcrhLw2x+BVjczgahVYrWsbsaoifqFRmxKzASnrjaaxKE2wwuiCXLYONp2Q2yD mwZP3TlmNeFIHu+rQSPjXbyYjIGCnIEW94cWp9dFodJde55Z2Pya+JEEp6DTZHtO0Ven 75QRhYD/HKTgcVJrsH2RJ0pNDgXeWU9kzjZ0kHD8S5U7jECWO8lhQwBR3H/S9ucnN+Az 83/gPv8Qh80ZaVGSgIT5sqZRxkQwkIKs97g4t22SzoJD5jt+Ximo/NA/Mk/Pd13y+tzT 0bzg== 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:user-agent; bh=lOUCwcmzhszLJp6WJJ66/hIbQddXLfnUTrddSaEhDeg=; b=QpnopMTZxJFZgJh9uYHF07bJZEoSHornSDPV+Gg49wBEVl3AG1VkSrlcpAkVHSLDgs jLypje+zk3y7rvV28W/ejhlpcyAJQ3aPeA3fjCix29e7pCUsiphWIMbpc08ZEhFD23mD Qg5mU53+1BGMU/pxyr2KWpIYxCO26yg+ADI4cZTHfjSy31+jPGuFSdjms4LL7ZY7tOxc mJksEWCWg67gQcn5k0Ahdk5wurSSceSVizpqOccYTyhypFkCWkMpPL1JkV94uTxjcncp vsGWfo/VLZHxtO4jWGbmRx5XdNm75P5onJGzv/Ya8QOlZBsGlcaoY7au+MtuWtCFsf8D Rn9g== X-Gm-Message-State: APjAAAVOu6N0lIrnSmd8At3SDsopKnCiLrlxt1seGAIS2lU2mYAVhh+Y wYHAal2O/sJl0McX8bZjur8cdQ== X-Google-Smtp-Source: APXvYqz70V/2ZMD4O8heOy6lD/4yJjslgkb1U6oS0OjWu08TBVA/IoddPzhDWAzQohbfW8zWh/DtQQ== X-Received: by 2002:adf:cd0d:: with SMTP id w13mr80759962wrm.38.1559142718484; Wed, 29 May 2019 08:11:58 -0700 (PDT) Received: from localhost (cst-prg-68-63.cust.vodafone.cz. [46.135.68.63]) by smtp.gmail.com with ESMTPSA id p14sm12678417wrt.53.2019.05.29.08.11.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 29 May 2019 08:11:57 -0700 (PDT) Date: Wed, 29 May 2019 17:11:53 +0200 From: Tomas Vondra To: Hubert Zhang Cc: hackers Subject: Re: accounting for memory used for BufFile during hash joins Message-ID: <20190529145517.sj2poqmb3cr4cg6w@development> References: <20190504003414.bulcbnge3rhwhcsh@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-1444-295967-dirty List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, May 28, 2019 at 03:40:01PM +0800, Hubert Zhang wrote: >On Sat, May 4, 2019 at 8:34 AM Tomas Vondra >wrote: > >Hi Tomas > >I read your second patch which uses overflow buf files to reduce the total >number of batches. >It would solve the hash join OOM problem what you discussed above: 8K per >batch leads to batch bloating problem. > >I mentioned in another thread: > >https://www.postgresql.org/message-id/flat/CAB0yrekv%3D6_T_eUe2kOEvWUMwufcvfd15SFmCABtYFOkxCFdfA%40mail.gmail.com >There is another hashjoin OOM problem which disables splitting batches too >early. PG uses a flag hashtable->growEnable to determine whether to split >batches. Once one splitting failed(all the tuples are assigned to only one >batch of two split ones) The growEnable flag would be turned off forever. > >The is an opposite side of batch bloating problem. It only contains too few >batches and makes the in-memory hash table too large to fit into memory. > Yes. There are deffinitely multiple separate issues in the hashjoin code, and the various improvements discussed in this (and other) thread usually address just a subset of them. We need to figure out how to combine them or maybe devise some more generic solution. So I think we need to take a step back, and figure out how to combine these improvements - otherwise we might commit a fix for one issue, making it much harder/impossible to improve the other issues. The other important question is whether we see these cases as outliers (and the solutions as last-resort-attempt-to-survive kind of fix) or more widely applicable optimizations. I've seen some interesting speedups with the overflow-batches patch, but my feeling is we should really treat it as a last-resort to survive. I had a chat about this with Thomas Munro yesterday. Unfortunately, some beer was involved but I do vaguely remember he more or less convinced me the BNL (block nested loop join) might be the right approach here. We don't have any patch for that yet, though :-( >Here is the tradeoff: one batch takes more than 8KB(8KB makes sense, due to >performance), in-memory hash table takes memory as well and splitting >batched may(not must) reduce the in-memory hash table size but introduce >more batches(and thus more memory usage 8KB*#batch). >Can we conclude that it would be worth to splitting if satisfy: >(The reduced memory of in-memory hash table) - (8KB * number of new >batches) > 0 > Something like that, yes. >So I'm considering to combine our patch with your patch to fix join OOM >problem. No matter the OOM is introduced by (the memory usage of in-memory >hash table) or (8KB * number of batches). > >nbatch_inmemory in your patch could also use the upper rule to redefine. > >What's your opinion? > One of the issues with my "overflow batches" patch, pointed out to me by Thomas yesterday, is that it only works with non-parallel hash join. And we don't know how to make it work in the parallel mode :-( regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services