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 1iTv6O-000746-3d for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Nov 2019 21:50:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iTv6M-0001iE-Fe for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Nov 2019 21:50:30 +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 1iTv6M-0001i5-4R for pgsql-bugs@lists.postgresql.org; Sun, 10 Nov 2019 21:50:30 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iTv6F-0001T4-6r for pgsql-bugs@lists.postgresql.org; Sun, 10 Nov 2019 21:50:28 +0000 Received: by mail-lj1-x243.google.com with SMTP id d5so2138086ljl.4 for ; Sun, 10 Nov 2019 13:50:22 -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=zhjO6VarYUwHzCqzW/jat7MS5msKm4zaNaUXa+CuIJo=; b=NeEiDRW12gMlo/U8pE/keb/otNXA4YaX0w67Zzyf9DWKN34xJJ8iV/z0kOPW6Z0I9g sMF2UxqQT70lmqNTDo9H+qTFtlujCis8k6G1k4Ojl87u2+OJRp5z10CaH+75/I0o4SxJ Lb2w0dYLOwLUxRpAAZx8P6MYBp44Pc/emtlz/5hwW4BjVD3inPufNZ4ErKJzBLUmn8S+ CMJdkOQxEQbY+zHIMQRtIRNToucN+iBt63Q23iAlt/MdA7QclWCiELxcJRWuTyOpWliT 3+ufXv+yVYTbejXvcUP/iubddLbe237iyJ0t/gqWydprfcvM91m0rzbVBfx3BzsOmA8g fghw== 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=zhjO6VarYUwHzCqzW/jat7MS5msKm4zaNaUXa+CuIJo=; b=kzHDWSQp4AyFn8fDGMiU+zYDjmJ6teDf7wW3f/AIj3pWgZuW/Grj/mPUoVIaUD2z7A vNpB8CK19Hw7Edfvm2OYl0eR88dOqul/ayR6QErHaaeDrPTu95wggu3fcAQ9hOYq0eLU Aq1cJfxXpqfX9nukvhkiRXYEKWA4fq/8UqODkQ5vNDV15V1du6Lp3f+ALQ1dsRLx2uI/ Axqp+lKVvnlq+giGaoC1FEz0k2zl4aIVz6xzoQfGCWDFz9YAXoa89eKzuvX5SSekg973 H+YpSu8PKG2U+5LZEvpkHkQE+IF8h4eEJT+VtgDA1xwaTdXkNy4fdKGzy0/sn4YYs7OE t13Q== X-Gm-Message-State: APjAAAX/mMAzqpNiX93jxf105At4ekT9zjLf3aLboxA7pz6Uf09B+H/P i431Q4kngT2cHlJkde+54BT6+w== X-Google-Smtp-Source: APXvYqwiOgboxuCugqrJBpeoIJPIj4y07UhVdKxpDs4pqJD5eFDnfivYqP6uF8GXrfLy2aIM14RLig== X-Received: by 2002:a2e:8595:: with SMTP id b21mr8579038lji.155.1573422621512; Sun, 10 Nov 2019 13:50:21 -0800 (PST) Received: from localhost ([217.8.174.100]) by smtp.gmail.com with ESMTPSA id b23sm7186318lfj.49.2019.11.10.13.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2019 13:50:19 -0800 (PST) Date: Sun, 10 Nov 2019 22:50:17 +0100 From: Tomas Vondra To: Thomas Munro Cc: James Coleman , PostgreSQL mailing lists Subject: Re: BUG #16104: Invalid DSA Memory Alloc Request in Parallel Hash Message-ID: <20191110215017.prjisnntwhhppnru@development> References: <20191109182735.ewficcv2hibbyzl4@development> <20191110172925.mlkglpwzwego3wtp@development> <20191110212352.5xpzddwjs6fmuv4u@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20191110212352.5xpzddwjs6fmuv4u@development> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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: >>I think I see what's happening: we're running out of hash bits. >> >>>Buckets: 4194304 (originally 4194304) Batches: 32768 (originally 4096) Memory Usage: 344448kB >> >>Here it's using the lower 22 bits for the bucket number, and started >>out using 12 bits for the batch (!), and increased that until it got >>to 15 (!!). After using 22 bits for the bucket, there are only 10 >>bits left, so all the tuples go into the lower 1024 batches. >> > >Ouch! > >>I'm not sure how exactly this leads to wildly varying numbers of >>repartioning cycles (the above-quoted example did it 3 times, the >>version that crashed into MaxAllocSize did it ~10 times). >> >>Besides switching to 64 bit hashes so that we don't run out of >>information (clearly a good idea), what other options do we have? (1) >>We could disable repartitioning (give up on work_mem) after we've run >>out of bits; this will eat more memory than it should. (2) You could >>start stealing bucket bits; this will eat more CPU than it should, >>because you'd effectively have fewer active buckets (tuples will >>concentrated on the bits you didn't steal). > >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). An I think you're right we should detect cases when we use all the bits, and stop making it worse. Stealing bucket bits seems reasonable - we can't stop adding batches, because that would mean we stop enforcing work_mem. The question is how far that gets us - we enforce nbuckets to be at least 1024 (i.e. 10 bits), which leaves 32 bits for nbatch. And in one of the explains we've seen nbatch=2097152 (i.e. 21 bits). Of course, this is bound to be (extremely) slow. The hashjoin changes in 9.5 which reduced th hash table load factor from 10 to 1 resulted in speedups close to 3x. And if you go from 4194304 to 1024 buckets, those will be loooooooong chains in each bucket :-( regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services