Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rCTLe-00G36m-M8 for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Dec 2023 23:36:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rCTLc-009MuZ-VK for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Dec 2023 23:36:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rCTLc-009MuR-IU for pgsql-bugs@lists.postgresql.org; Sun, 10 Dec 2023 23:36:32 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rCTLY-00BHuM-Oe for pgsql-bugs@lists.postgresql.org; Sun, 10 Dec 2023 23:36:31 +0000 Received: from [192.168.43.178] (unknown [176.59.166.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.rybakina@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 2B17FE2104B; Mon, 11 Dec 2023 02:36:27 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1702251387; bh=TBCy90pgjMFRY9M/EBpkoXo+3TEk7oRa/+p00jIgSck=; h=Message-ID:Date:User-Agent:Subject:From:To:References:Cc: In-Reply-To:From; b=GtIbsnJQoXJmfnWNvQWZg6/cqm2Z1F4K4GlU+OUQS3XYaEwKcKXrHMhYPJ7GW3+tX cLo8I0vBgPBIQ/zDbIz9MAkrpTiZwtLMvOeXNFEUhoj5lw3wg+a+isexdp6WrrMidC WgSDx+gIsJchoVFcnSWA2wDJV3oCiyTLGFmlI9ogiJA8OoOxCfWsPB46RsRwA4BLfG Gq50As5qErkxuGjVa6nqzOAi/yX57gVrhmwjqFl/pOpUC0zam8WL+A+cg0yZsyeWnH mTCBU10A3S5ww3SnSP83mEQ3begXTnXhN+4ds+iHlDZcymc0W/umNeN0NCTnRVhFMe kNArS02r9CQ0w== Content-Type: multipart/mixed; boundary="------------yXdJVjqoEhk44hW97Lr0H20l" Message-ID: Date: Mon, 11 Dec 2023 02:36:26 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #16925: ERROR: invalid DSA memory alloc request size 1073741824 CONTEXT: parallel worker Content-Language: en-US From: Alena Rybakina To: Andrei Lepikhov References: <16925-ec96d83529d0d629@postgresql.org> <9277414b-dbce-4a32-8aff-642e399e23e5@postgrespro.ru> <412f9d60-9229-43d8-b6ed-4f55fb5ed6bd@postgrespro.ru> Cc: PostgreSQL mailing lists , Thomas Munro In-Reply-To: <412f9d60-9229-43d8-b6ed-4f55fb5ed6bd@postgrespro.ru> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------yXdJVjqoEhk44hW97Lr0H20l Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi! Thank you for your work on the subject. On 11.12.2023 02:30, Alena Rybakina wrote: > > On 06.12.2023 07:46, Andrei Lepikhov wrote: >> On 18/3/2021 16:21, Thomas Munro wrote: >>> ===8<=== >>> shared_buffers=2GB >>> fsync=off >>> max_wal_size=10GB >>> min_dynamic_shared_memory=2GB >>> ===8<=== >>> create table bigger_than_it_looks as >>>    select generate_series(1, 256000000) as id; >>> alter table bigger_than_it_looks set (autovacuum_enabled = 'false'); >>> alter table bigger_than_it_looks set (parallel_workers = 1); >>> analyze bigger_than_it_looks; >>> update pg_class set reltuples = 5000000 where relname = >>> 'bigger_than_it_looks'; >>> ===8<=== >>> postgres=# set work_mem = '4.5GB'; >>> SET >>> postgres=# explain analyze select count(*) from bigger_than_it_looks >>> t1 join bigger_than_it_looks t2 using (id); >>> ERROR:  invalid DSA memory alloc request size 1073741824 >>> CONTEXT:  parallel worker >>> ===8<=== >> >> This bug still annoyingly interrupts the queries of some clients. >> Maybe complete this work? >> It is stable and reproduces on all PG versions. The case: >> work_mem = '2GB' >> >> test table: >> ----------- >> CREATE TABLE bigger_than_it_looks AS >>   SELECT generate_series(1, 512E6) AS id; >> ALTER TABLE bigger_than_it_looks SET (autovacuum_enabled = 'false'); >> ALTER TABLE bigger_than_it_looks SET (parallel_workers = 1); >> ANALYZE bigger_than_it_looks; >> UPDATE pg_class SET reltuples = 5000000 >> WHERE relname = 'bigger_than_it_looks'; >> >> The parallel workers number impacts size of the allowed memory under >> the hash table and in that sense correlates with the work_mem value, >> needed for the bug reproduction (keep in mind also that >> hash_mem_multiplier has been changed recently). >> >> Query: >> SELECT sum(a.id) >> FROM bigger_than_it_looks a >> JOIN bigger_than_it_looks b ON a.id =b.id >> LEFT JOIN bigger_than_it_looks c ON b.id = c.id; >> >> Any query that needs Parallel Hash Join can be found here. The case >> here is as follows. >> The first batch contains a lot of tuples (on increment, it has about >> 67mln tuples.). We calculate the number of buckets needed, >> approximately 134 mln (134217728). Remember, the size of >> dsa_pointer_atomic is 8 in my case, and it ends up with an overflow >> of the max number of DSA, which can be allocated (1073741823 bytes). >> See the new patch in the attachment. I've looked through your code and haven't seen any errors yet, but I think we could rewrite these lines of code as follows: -                    dbuckets = ceil(dtuples / NTUP_PER_BUCKET); -                    dbuckets = Min(dbuckets, max_buckets); -                    new_nbuckets = (int) dbuckets; -                    new_nbuckets = Max(new_nbuckets, 1024); +                    dbuckets = Min(ceil(dtuples / NTUP_PER_BUCKET), max_buckets); +                    new_nbuckets = Max((int) dbuckets, 1024); I have attached a diff file with the proposed changes to this email. -- Regards, Alena Rybakina Postgres Professional: http://www.postgrespro.com The Russian Postgres Company --------------yXdJVjqoEhk44hW97Lr0H20l Content-Type: text/plain; charset=UTF-8; name="code_refactoring.diff.txt" Content-Disposition: attachment; filename="code_refactoring.diff.txt" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2V4ZWN1dG9yL25vZGVIYXNoLmMgYi9zcmMvYmFj a2VuZC9leGVjdXRvci9ub2RlSGFzaC5jCmluZGV4IDljMWFkN2Q3YjQ1Li43NmE5M2JlMjBk MiAxMDA2NDQKLS0tIGEvc3JjL2JhY2tlbmQvZXhlY3V0b3Ivbm9kZUhhc2guYworKysgYi9z cmMvYmFja2VuZC9leGVjdXRvci9ub2RlSGFzaC5jCkBAIC0xMTc3LDEwICsxMTc3LDggQEAg RXhlY1BhcmFsbGVsSGFzaEluY3JlYXNlTnVtQmF0Y2hlcyhIYXNoSm9pblRhYmxlIGhhc2h0 YWJsZSkKIAkJCQkJICogYXJyYXkuCiAJCQkJCSAqLwogCQkJCQlkdHVwbGVzID0gKG9sZF9i YXRjaDAtPm50dXBsZXMgKiAyLjApIC8gbmV3X25iYXRjaDsKLQkJCQkJZGJ1Y2tldHMgPSBj ZWlsKGR0dXBsZXMgLyBOVFVQX1BFUl9CVUNLRVQpOwotCQkJCQlkYnVja2V0cyA9IE1pbihk YnVja2V0cywgbWF4X2J1Y2tldHMpOwotCQkJCQluZXdfbmJ1Y2tldHMgPSAoaW50KSBkYnVj a2V0czsKLQkJCQkJbmV3X25idWNrZXRzID0gTWF4KG5ld19uYnVja2V0cywgMTAyNCk7CisJ CQkJCWRidWNrZXRzID0gTWluKGNlaWwoZHR1cGxlcyAvIE5UVVBfUEVSX0JVQ0tFVCksIG1h eF9idWNrZXRzKTsKKwkJCQkJbmV3X25idWNrZXRzID0gTWF4KChpbnQpIGRidWNrZXRzLCAx MDI0KTsKIAkJCQkJbmV3X25idWNrZXRzID0gcGdfbmV4dHBvd2VyMl8zMihuZXdfbmJ1Y2tl dHMpOwogCQkJCQlkc2FfZnJlZShoYXNodGFibGUtPmFyZWEsIG9sZF9iYXRjaDAtPmJ1Y2tl dHMpOwogCQkJCQloYXNodGFibGUtPmJhdGNoZXNbMF0uc2hhcmVkLT5idWNrZXRzID0KCg== --------------yXdJVjqoEhk44hW97Lr0H20l--