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 1hOMic-0008OU-Lo for pgsql-hackers@arkaria.postgresql.org; Wed, 08 May 2019 13:34:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hOMib-0002MA-9k for pgsql-hackers@arkaria.postgresql.org; Wed, 08 May 2019 13:34:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hOMia-0002Hb-Ur for pgsql-hackers@lists.postgresql.org; Wed, 08 May 2019 13:34:44 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hOMiY-0007QY-9l for pgsql-hackers@postgresql.org; Wed, 08 May 2019 13:34:44 +0000 Received: by mail-wr1-x441.google.com with SMTP id l2so27272301wrb.9 for ; Wed, 08 May 2019 06:34:41 -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:content-transfer-encoding:in-reply-to :user-agent; bh=EdqkVfX6G8gh31Q5vK8mmFQ9gZMGMA0rjqrI8HgPY2k=; b=mNz3UowMo7DhlhODxcO2lPdqFxXK6A9HzXT/nKjm1AWyNFdx9FEht9hSsTCpdSyuZz Z1+nM9QIFzRANdAKZ+u3PjbXP0sVn42pJ1IscnuiFkR9bCnkza2M6FIqh6ktsdruyVLt QdkXHBT8L6lDn9Gw26OyZOQIUUaHRD5kMHgESBwWJg2X1CP6Y3RYcmcgvONQO8sx1LNA AE5/CxXmf2ev+rXQoiXAEpwq6yFr8MmV3ZabH+h7d398oE7fEhZkU4LPVoFwlCedTqxd Zco8Om2cajVeGb5k04XHsoP3809vfOj/foZF3kAIN625IqdId/xYq7bGf+BPehb61X1r IH/g== 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:content-transfer-encoding :in-reply-to:user-agent; bh=EdqkVfX6G8gh31Q5vK8mmFQ9gZMGMA0rjqrI8HgPY2k=; b=lx5g/AfEuvM/DMi1syEUiInPZ1LhdmvXMy50BsXjVtMRuMyw+iKt+YM04VNa0EiADM EVhmnI5VvWAaFLcPAmiywXBMi4xcMpqy83Oeu3/4R3ekDyeLTUziQfnvU5yr4kr7vUKK 9P/EAHGYKkaa3G8gXNCuQjQr4GMv3Co5sxYlaYztGK5Tlz0q9oUTQU1MH1+og19s/Hut bBshM/XV9zUftk+xOmxV9IvFXK4pdxN/r7XgG7/4EXQlB93zS8o0A+iJNObKfd7vSb6M SJ25J3Cw+mM7sCfvD2KFsxqElGyUpkpnG0MkdcYTuc0oHFbxDSGCQIcNMOxxiqzuxf5R Um3Q== X-Gm-Message-State: APjAAAV4fQ6rzwi7nmdi131S87k9R/rIegn3D/+dbjTlh9GCvjgB8zxV KH3q7BJzJl9gHgIi6Z+GVpePzA== X-Google-Smtp-Source: APXvYqye8yj7ocUjicf0Pt7sHD0JOG+nOXhQIXc9455hPxNpy5K8j1ruIWLbB3DcNzlbyq5Fe8DX3w== X-Received: by 2002:adf:c6c3:: with SMTP id c3mr28022696wrh.267.1557322481100; Wed, 08 May 2019 06:34:41 -0700 (PDT) Received: from localhost (ip-86-49-243-43.net.upcbroadband.cz. [86.49.243.43]) by smtp.gmail.com with ESMTPSA id j46sm6050461wre.54.2019.05.08.06.34.39 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 08 May 2019 06:34:39 -0700 (PDT) Date: Wed, 8 May 2019 15:34:38 +0200 From: Tomas Vondra To: Melanie Plageman Cc: Thomas Munro , hackers Subject: Re: accounting for memory used for BufFile during hash joins Message-ID: <20190508133438.7nfzyioihjcvkjwi@development> References: <20190504003414.bulcbnge3rhwhcsh@development> <20190507031511.lvp6bqn2e5dpsnga@development> <20190507135912.qakpj74sv3ngrypz@development> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, May 07, 2019 at 05:43:56PM -0700, Melanie Plageman wrote: > On Tue, May 7, 2019 at 6:59 AM Tomas Vondra > wrote: > > On Tue, May 07, 2019 at 04:28:36PM +1200, Thomas Munro wrote: > >On Tue, May 7, 2019 at 3:15 PM Tomas Vondra > > wrote: > >> On Tue, May 07, 2019 at 01:48:40PM +1200, Thomas Munro wrote: > >> Switching to some other algorithm during execution moves the goal > posts > >> to the next galaxy, I'm afraid. > > > >The main problem I'm aware of with sort-merge join is: not all that is > >hashable is sortable.  So BNL is actually the only solution I'm aware > >of for problem B that doesn't involve changing a fundamental thing > >about PostgreSQL's data type requirements. > > > > Sure, each of those algorithms has limitations. But I think that's > mostly > irrelevant to the main issue - switching between algorithms > mid-execution. > At that point some of the tuples might have been already sent sent to > the > other nodes, and I have no idea how to "resume" the tuple stream short > of > buffering everything locally until the join completes. And that would be > rather terrible, I guess. > > What if you switched to NLJ on a batch-by-batch basis and did it before > starting > execution of the join but after building the inner side of the hash > table.  That > way, no tuples will have been sent to other nodes yet. > Interesting idea! I think you're right doing it on a per-batch basis would solve that problem. Essentially, if all (or >95%) of the tuples has the same hash value, we could switch to a special "degraded" mode doing something like a NL. At that point the hash table benefits are lost anyway, because all the tuples are in a single chain, so it's not going to be much slower. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services