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 1iTuh0-0006Hp-Kp for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Nov 2019 21:24:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iTugy-0007eX-VO for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Nov 2019 21:24:16 +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 1iTugy-0007eL-Cp for pgsql-bugs@lists.postgresql.org; Sun, 10 Nov 2019 21:24:16 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iTugv-0001Ay-3R for pgsql-bugs@lists.postgresql.org; Sun, 10 Nov 2019 21:24:14 +0000 Received: by mail-wr1-x42d.google.com with SMTP id s5so1420528wrw.2 for ; Sun, 10 Nov 2019 13:24: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=1WyfF7AP9apaxW68+Lt86ONUqiVlG87B9ZshQFaFfic=; b=NZj5nGx2xr7G/a9bK81P4j6kbrOHccz1lGlt/fFFg8nHJ3uGfzbg5iz2GdX9l/JhI9 vepSFHU0Ipij20zazQHvG4B2OL6cc11xr4c5J/8PZyOcjIHzpmnRQ++0bxr4JquXUjbU HwxsdsX27acalQozfJh5PNYeXeZ5yVFEmGsgEUExDs4+KYQkDbVoYe9tIHtNl/WdqPvW mIfE9YxzcofLEJh/yH3FAJOfRBBJj2ptpXMw7KxejGEIid+qRYg8DQntbhHMs7rS+DVi xnFrAQWedhEN2fXYpPtzl7NiXQmxnSf6XiWQulPtv4JjnO9xDXc0w3ukmjUPBK/9mcF5 9cwg== 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=1WyfF7AP9apaxW68+Lt86ONUqiVlG87B9ZshQFaFfic=; b=VKYWxpg+YuV0Qbr2ZkirR8QiQNWIDF404J86GSM1DWOCBJyqW9h/0EQu+L+EkHfHJz Y6zeT8Ua70j1znv3Wnw1qhM0D+8SSPD8p83eCTcd6FsghvfXVKYw3NpEyHYbITwQ/pzp DTRlgjiIgUMiEDxABoqyHs/1nSrObljk/RAkLTuVwbG83YbyeO2mhREtYsPn4/8rYu4K AjXOA7wgQJTOn0bg7DI2v7P2/adKU+8xNBv9AD/bBUG35ueOe4yKcBc//uxw3Zj13Zha AXFPBYbaFaNIZ5Vi0eBhKyxjGNOQeZt1kB2NfJh5ZKd84/FFLdb/k2Ybg00KcE3rJbSJ 1YgA== X-Gm-Message-State: APjAAAWDqSi4Gcl+EGRimq5r1qBgUkKS+FFgwDTlIxsen+NkXjreXyDK CQ26rV38mXc+ltbWOSJo65OF/w== X-Google-Smtp-Source: APXvYqyRbuZjnd/EAeAbRe/C3RlZgkum8GskfbazJx3dFBKAtLX57Z/4r9czEErW5SXDz6bsZWrJog== X-Received: by 2002:adf:f18c:: with SMTP id h12mr2495540wro.122.1573421050929; Sun, 10 Nov 2019 13:24:10 -0800 (PST) Received: from localhost ([217.8.174.100]) by smtp.gmail.com with ESMTPSA id d11sm14450483wrn.28.2019.11.10.13.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2019 13:24:10 -0800 (PST) Date: Sun, 10 Nov 2019 22:23:52 +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: <20191110212352.5xpzddwjs6fmuv4u@development> References: <20191109182735.ewficcv2hibbyzl4@development> <20191110172925.mlkglpwzwego3wtp@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 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. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services