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 1iU7DE-0007de-0Y for pgsql-bugs@arkaria.postgresql.org; Mon, 11 Nov 2019 10:46:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iU7DA-0002R9-Tn for pgsql-bugs@arkaria.postgresql.org; Mon, 11 Nov 2019 10:46:20 +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 1iU7DA-0002R2-EV for pgsql-bugs@lists.postgresql.org; Mon, 11 Nov 2019 10:46:20 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iU7D2-0007SS-KQ for pgsql-bugs@lists.postgresql.org; Mon, 11 Nov 2019 10:46:18 +0000 Received: by mail-lj1-x241.google.com with SMTP id v8so13231590ljh.5 for ; Mon, 11 Nov 2019 02:46:12 -0800 (PST) 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=wWMZdSBzSRJKC4iRFcJ7dFfnNrKUdPZGOxMv1Qma0gI=; b=CZ4NCyRQNWAI3YZJZW3+XWYrs3FzkimCNUhdbaqxf+bOoFYaYLOKhpufXScRGi1gdn GxWX12XZ/0D0TWz1wHDGmdjgxOHC/CRhLe0VXTPCNNYv6Jmk2anQwgXo0Gy3dl9RMBWR Wbn4mzalrxxNAZtWvoxMWCkADSiUqCY6xReD8cYr3o9+UykSev++P/9cxNZC1d2eRUZk EJT68zFpVhZzMSkbjCquGrcg0PbveRvpRuxEqx+E/gAG5lXIt6K16EeFAJrYgfO143S+ BOINpvLvlXRINBt2woxgkYAAGsfOH5UuFA9rR2zAr5BCg0BNRiMKi02JNlqpKTRZ4ufm LX6A== 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=wWMZdSBzSRJKC4iRFcJ7dFfnNrKUdPZGOxMv1Qma0gI=; b=LZZ2QTsTadn2CTsEUt5R/HRbHnv1DjAJwKMed76wWmRrXSncy2PWZNSTTURzO136Fp Lc1xyZp4acIASaL6Y5/EaAnmpxJ93EqObsBETwRoBGqHn61ySdJfGPEKCmP4VyG+EABl yi0SPPOUYEflqMcnG1g4kkLKLZJ58YLJOQV/Qg1cYQQxyXA6m5oT5JmXtoafb48gWqhL FDXrhwGZiaedNcbr3JUNju3BGMBtc9T9FPYvdKPUabF8SJLLxBzKEH5OMVUnMqxeAHoE u5Fyb/BYMIS9MUFRUdlJ4/RoSYzLYA/rcE5yI4ZVmwQD8qJLL87IoQM71OfpH7oaYVHR BDyA== X-Gm-Message-State: APjAAAUmu4PEuaxKClvnYSeeB9rHwPtp9JGdIMt34DFWhjPDdxfYmcmr SQN1/CNfJ2cfo4MNNWrX7IZwYA== X-Google-Smtp-Source: APXvYqxNB7mTqY5ewqaDFyBfiA5wP48VDtRH+H7Mv9ZSFGmYQL5jmokZ3DIAzGmWq0mRBBA3FAXBZw== X-Received: by 2002:a2e:9e4c:: with SMTP id g12mr16231959ljk.62.1573469170800; Mon, 11 Nov 2019 02:46:10 -0800 (PST) Received: from localhost ([217.8.174.100]) by smtp.gmail.com with ESMTPSA id k6sm11650775lfc.72.2019.11.11.02.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2019 02:46:07 -0800 (PST) Date: Mon, 11 Nov 2019 11:46:05 +0100 From: Tomas Vondra To: Thomas Munro Cc: Andres Freund , James Coleman , PostgreSQL mailing lists Subject: Re: BUG #16104: Invalid DSA Memory Alloc Request in Parallel Hash Message-ID: <20191111104605.c4w27as5sq7nm3x4@development> References: <20191110172925.mlkglpwzwego3wtp@development> <20191110212352.5xpzddwjs6fmuv4u@development> <20191110215017.prjisnntwhhppnru@development> <20191110224631.uxpfccnql6pxllv2@alap3.anarazel.de> <20191110234438.qwdcur3aodd7yj6d@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 Mon, Nov 11, 2019 at 01:33:41PM +1300, Thomas Munro wrote: >On Mon, Nov 11, 2019 at 12:44 PM Tomas Vondra > wrote: >> On Sun, Nov 10, 2019 at 02:46:31PM -0800, Andres Freund wrote: >> >On 2019-11-10 22:50:17 +0100, Tomas Vondra wrote: >> >> On Sun, Nov 10, 2019 at 10:23:52PM +0100, Tomas Vondra wrote: >> >> > On Mon, Nov 11, 2019 at 10:08:58AM +1300, Thomas Munro wrote: >> >> > Can't we simply compute two hash values, using different seeds - one for >> >> > bucket and the other for batch? Of course, that'll be more expensive. >> >> >> >> Meh, I realized that's pretty much just a different way to get 64-bit >> >> hashes (which is what you mentioned). >> > >> >I'm not sure it's really the same, given practical realities in >> >postgres. Right now the "extended" hash function supporting 64 bit hash >> >functions is optional. So we couldn't unconditionally rely on it being >> >present, even in master, unless we're prepared to declare it as >> >required from now on. >> > >> >So computing two different hash values at the same time, by using a >> >different IV and a different combine function, doesn't seem like an >> >unreasonable approach. >> >> True. I was commenting on the theoretical fact that computing two 32-bit >> hashes is close to computing a 64-bit hash, but you're right there are >> implementation details that may make it more usable in our case. > >Here is a quick sketch of something like that, for discussion only. I >figured that simply mixing the hash value we have with some arbitrary >bits afterwards would be just as good as having started with a >different IV, which leads to a very simple change without refactoring. From quick experiments with unique keys (generate_series) I seem to >get approximately even sized partitions, and correct answers, but I >make no claim to strong hash-math-fu and haven't tested on very large >inputs. Thoughts? Hmmm, iteresting. Using a hard-coded constant seems a bit weird, although I don't have any precise argument why it's wrong yet. Essentially, the patch does this: batchno = hash_combine(0x9e3779b9, hashvalue) & (nbatch - 1); bucketno = hashvalue & (nbuckets - 1); but adding a constant does not 'propagate' any bits from the original value to the hash. So it seems pretty much equivalent to batchno = hashvalue & (nbatch - 1); bucketno = hashvalue & (nbuckets - 1); so we still operate with the same number of bits. It might solve this particular case, but I doubt it's a good idea in general ... I think we will have to actually compute two hashes, to get more than 32 bits. But yes, that'll be more invasive, and unlikely backpatchable. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services