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 1iejNB-0002EF-Ef for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Dec 2019 17:32:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iejNA-0001zg-78 for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Dec 2019 17:32:32 +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 1iejN9-0001zY-Qv for pgsql-bugs@lists.postgresql.org; Tue, 10 Dec 2019 17:32:31 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iejN6-0000qb-M9 for pgsql-bugs@lists.postgresql.org; Tue, 10 Dec 2019 17:32:31 +0000 Received: by mail-wr1-x444.google.com with SMTP id a15so21030480wrf.9 for ; Tue, 10 Dec 2019 09:32:28 -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=f6ewBPV/1So9htWUjuB12FmKLQQflhnvn+v88YcNgTY=; b=Tn/OsZHQzu27rpCO3dYnpmjIbjYp3Nj4lTaTQSyiZQ8NnmYb1neO/FWOWu5srLIO5/ +/c7YLkFJuMhDH3wclkcrTbUlt9c47EfYEUOCA1D8+sLtFdtnnuvKVIM5L1Han0Q6m7E 3cI0Bt6GCZ6niVlvirVM2sCixy3Hr4dn4obduJfJIZShTMpBY+zZQZkhJcVW/Wqb5dbn 6OAHuy1Oe9PijP3VkSQg928VSWNN7wHes178Qbf3ZLujpNZ2Rxm4XAsuHEQuK9mjnp5H eWBCOEUVNmOCR9mS9O7+i98oJoJbahMzglT4FwylPCbnXXa+H4vsI7gMAnVY/y4EoFFG nKUw== 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=f6ewBPV/1So9htWUjuB12FmKLQQflhnvn+v88YcNgTY=; b=qLdPHhBK1EpNcb6PN3PjUeIhDBiJlY56kBAyOxyRLOkaioqRWEx/GxaVyLW8ZL0zly jkTmON1n5FDJYUEEVOOv+JqX0fK7USei1K0EtV0TmxBZLNtlnz3apY7VLSZbLXm2C1NT 3h6qlD2FZxL19C2Bf9xm+Rnx5eGtkDbPpz1qUrZ4axwYZ+EuRTXStGjtzl+N5dagl4Sk cA9QOinUVNjCufk4932lmSTdpLywTcMAQIBHoo5gyEKpUSeXS4a9HmSojnXdPYzQZ35K Y/ALTyzzH3d9vr5/iYxIuH8FSIfDsDlhESH0oUMsa60I2LqyOxyDc3pnjPRxbtnHlIfK +M1w== X-Gm-Message-State: APjAAAX5U0/ddg85++cwNT+w0sE7ImFM6ASFu9jGbuNG8X545HM6y3UQ uBeV0j6wKko54LOEYfYjTUryQg== X-Google-Smtp-Source: APXvYqwkl4r/W4CBcY/aSnodPZOVja2K+bYEvKkTWRe0KuIFP9QVpRcmpiu9Q0QgZgdycMC8G/pVpA== X-Received: by 2002:adf:e609:: with SMTP id p9mr4376625wrm.397.1575999147404; Tue, 10 Dec 2019 09:32:27 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id v22sm3822789wml.11.2019.12.10.09.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 09:32:25 -0800 (PST) Date: Tue, 10 Dec 2019 18:32:24 +0100 From: Tomas Vondra To: Alvaro Herrera Cc: Thomas Munro , Andres Freund , James Coleman , PostgreSQL mailing lists Subject: Re: BUG #16104: Invalid DSA Memory Alloc Request in Parallel Hash Message-ID: <20191210173224.y5vaam6ep7pjmddt@development> References: <20191203170704.GA28076@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20191203170704.GA28076@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Dec 03, 2019 at 02:07:04PM -0300, Alvaro Herrera wrote: >Hello > >I can make no useful comment on the correctness of the new bit >distribution. But I can make two comments on this part: > >On 2019-Nov-21, Thomas Munro wrote: > >> So here's a draft steal-the-bucket-bits patch. Yeah, >> reverse_bits_u32() may be in the wrong header. > >I think pg_bitutils.h is the right place in master, but that file didn't >exist earlier. I think access/hash.h is the right place in older >branches, which is where hash_any() used to be. > >> But is it too slow? >> On my desktop I can call ExecGetBucketAndBatch() 353 million times per >> second (~2.8ns), and unpatched gets me 656 million/sec (~1.5ns) >> (though that includes a function call, and when Hash does it it's >> inlined), but it's only slower when nbatch > 1 due to the condition. > >If the whole query takes hours (or even minutes) to run, then adding one >second of runtime is not going to change things in any noticeable way. >I'd rather have the extreme cases working and take additional 1.3ns per >output row, than not work at all. > >> To put that number into persepective, I can hash 10 million single-int >> tuples from a prewarmed seq scan in 2.5s without batching or >> parallelism, so that's 250ns per tuple. This'd be +0.4% of that, and >> I do see it in a few more samples with my profiler, but it's still >> basically nothing, and lost in the noise with other noisy partitioning >> overheads like IO. Thoughts? > >That summarizes it well for me: yes, it's a slowdown, yes it's barely >measurable. > OK, I did a bit of testing with this patch today, and I can confirm it does indeed help quite a bit. I only used a smaller data set with 4.5B rows, but it was enough to trigger the issue - it allocated ~1TB of temp space, and then crashed. The annoying thing is that it's the workers that crash, and the leader failed to notice that, so it was waiting in WaitForParallelWorkersToExit forever. Not sure what the issue is. Anyway, with the patch applied, the query completed in ~2.2 hours, after allocating ~235GB of temp files. So that's good, the patch clearly improves the situation quite a bit. As for the performance impact, I did this: create table dim (id int, val text); insert into dim select i, md5(i::text) from generate_series(1,1000000) s(i); create table fact (id int, val text); insert into fact select mod(i,1000000)+1, md5(i::text) from generate_series(1,25000000) s(i); set max_parallel_workers_per_gather = 0; select count(*) from fact join dim using (id); So a perfectly regular join between 1M and 25M table. On my machine, this takes ~8851ms on master and 8979ms with the patch (average of about 20 runs with minimal variability). That's ~1.4% regression, so a bit more than the 0.4% mentioned before. Not a huge difference though, and some of it might be due to different binary layout etc. It's probably still a good idea to do this, although I wonder if we might start doing this only when actually running out of bits (and use the current algorithm by default). But I have no idea if that would be any cheaper, and it would add complexity. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services