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 1t0HBf-00ASSg-8c for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Oct 2024 09:16:23 +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 1t0HBc-00Bt6B-Ve for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Oct 2024 09:16:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0HBc-00Bt63-IY for pgsql-bugs@lists.postgresql.org; Mon, 14 Oct 2024 09:16:21 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t0HBa-000oK0-30 for pgsql-bugs@lists.postgresql.org; Mon, 14 Oct 2024 09:16:19 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-20cb7139d9dso15709965ad.1 for ; Mon, 14 Oct 2024 02:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728897377; x=1729502177; darn=lists.postgresql.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=TXp6LI+QFIZP9Hh8ZG1q3/Uyyswmn4nB6iXlT5LoNas=; b=cKnpzCVFPX+iDVkrKROCFTt2hGGhpag+Jf+J+8WM5aEYIAzXDknGkE6OscLnTI5Fm0 WE8wqLGiGwGHAWgqS1mOeZmQIPYm5gymP7yewGVMTilohKOUfLv+eQIuiuK0X+TBZDAO kRU0cje+22Zm8iS34+H86m2PCYK3VproDbp9VQeyWhyRHWjvsYBGoZ8R6DdWPkXnqZf8 wIE/h0js/vl9RO1okc+Zn+YWcC3bvdz31xX44FFtvkwLNMpLb3QewXpcjae/sZY6Qw6V krHRDczARu430bx9O4sKVRL+6wdc+UWTi8c1e9AYoXeZZIZzvv94GsHACo8y5Mum8gBj gWtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728897377; x=1729502177; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=TXp6LI+QFIZP9Hh8ZG1q3/Uyyswmn4nB6iXlT5LoNas=; b=nUPrTrN2aHecfqI1qQtwujbeJycKPTT7tlcNABW4IAajcgJDN0c+tBHT96JlaotkJ1 K0DqLnYcYm0BHCzurPpmvr09OqrhaGW0qFrgOyHpRDtm/Xwmi/6QxIi5NxrrozXQIU6e HgasXw65nThx27n+wTcVz/eIYFOFsYd7gc0LpeIKx8+Rv5999L3jPeMHJZIqzqsbLGz7 PMVs/AedCL4PEuFCZDKTL+2htn3z94lKqlUQ4LWFsSJJz5qXry7lUiin6LJ4iHkuz01o uKyay5lKxsLZ7kE9+Jm1tH9cEfkGhGYeHn7BzVHW/Q1hPvFceYZh+/oSP0SxPpwyCpMB 1pgg== X-Forwarded-Encrypted: i=1; AJvYcCXBjiu0u1nyTMu21zqRfyrr6zIY+G443tl4HBSTX8DEiDY+DC+7nuUtCM7N96izduhHuum7TUlvfFHJ@lists.postgresql.org X-Gm-Message-State: AOJu0Yz8oZCg25n0wx4qVJPcit4XhRZmsGbR8dtv3wVhd+SPAfG8MN9v NCI64R6vZgyszawOSLkfW+jxmi97axUs9nvNFWQ22YfJmfZkIAIo X-Google-Smtp-Source: AGHT+IHCkdRqb2XoUuvSRxtkelUtvtkg3AeWj0QYkd058P8uk/CV1CrzUltc18zFzVIb8ocg2YDSjA== X-Received: by 2002:a17:902:fd4f:b0:20c:8839:c517 with SMTP id d9443c01a7336-20ca16de7cemr132213115ad.53.1728897376628; Mon, 14 Oct 2024 02:16:16 -0700 (PDT) Received: from [10.10.20.104] (node-i9a.pool-125-27.dynamic.totinternet.net. [125.27.92.110]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8bc1c692sm62466645ad.110.2024.10.14.02.16.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Oct 2024 02:16:15 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------kkMPt50Z74hU0nJDHIuOZsYi" Message-ID: <3a1ac6f1-ac30-4ed4-8d0d-beb8a5aca7e5@gmail.com> Date: Mon, 14 Oct 2024 16:16:11 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Reference to - BUG #18349: ERROR: invalid DSA memory alloc request size 1811939328, CONTEXT: parallel worker To: Tom Lane Cc: Thomas Munro , Craig Milhiser , pgsql-bugs@lists.postgresql.org References: <6785e9e8-4c64-41b0-9e72-c13d1822b599@gmail.com> <0c3b0e1b-55d1-42b6-8c3c-4392479187db@gmail.com> <9! 6a328e9-4fbf-433b-a8d7-071da18e12c4@gmail.com> <3581840.1728887169@sss.pgh.pa.us> Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: <3581840.1728887169@sss.pgh.pa.us> 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. --------------kkMPt50Z74hU0nJDHIuOZsYi Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 10/14/24 13:26, Tom Lane wrote: > Andrei Lepikhov writes: >> My explanation (correct if I'm wrong): >> OUTER JOINs allow NULLs to be in a hash table. At the same time, a hash >> value for NULL is 0, and it goes to the batch==0. >> If batch number 0 gets overfilled, the >> ExecParallelHashIncreaseNumBatches routine attempts to increase the >> number of batches - but nothing happens. The initial batch is still too >> big, and the number of batches doubles up to the limit. > > Interesting point. If memory serves (I'm too tired to actually look) > the planner considers the statistical most-common-value when > estimating whether an unsplittable hash bucket is likely to be too > big. It does *not* think about null values ... but it ought to. As I see it, it is just an oversight in the resizing logic: batch 0 doesn't change the estimated_size value at all - I think because it doesn't matter for this batch - it can't be treated as exhausted by definition. Because of that, parallel HashJoin doesn't detect extreme skew, caused by duplicates in this batch. NULLS is just our luck - they correspond to hash value 0 and fall into this batch. See the attachment for a sketch of the solution. > > However, this does not explain why PHJ would be more subject to > the problem than non-parallel HJ. Good question! I rarely touch this part of the code and maybe don't see whole picture. But as I see it, HJ is designed differently: repartitioning machinery is based on overall hash table size and number of tuples and has nothing similar to 'batch 0' or parallel batches. Hash table size is calculated for each batch and can't cause this bug. BTW, Can we also resolve here the long-living corner case with "invalid DSA memory alloc request size" [1]? Just because we have clear reproduction ... [1] https://www.postgresql.org/message-id/7d763a6d-fad7-49b6-beb0-86f99ce4a6eb%40postgrespro.ru -- regards, Andrei Lepikhov --------------kkMPt50Z74hU0nJDHIuOZsYi Content-Type: text/x-patch; charset=UTF-8; name="0001-Consider-extreme-skew-in-batch-0-during-Parallel-Has.patch" Content-Disposition: attachment; filename*0="0001-Consider-extreme-skew-in-batch-0-during-Parallel-Has.pa"; filename*1="tch" Content-Transfer-Encoding: base64 RnJvbSA4N2I4MjM4MjFhYmQ0ZWY1MzIxNGJhNTk1NGQ4ZTgwNjlhMWM0MGZjIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiAiQW5kcmVpIFYuIExlcGlraG92IiA8bGVwaWhvdkBn bWFpbC5jb20+CkRhdGU6IE1vbiwgMTQgT2N0IDIwMjQgMTU6NDg6MDEgKzA3MDAKU3ViamVj dDogW1BBVENIXSBDb25zaWRlciBleHRyZW1lIHNrZXcgaW4gYmF0Y2ggMCBkdXJpbmcgUGFy YWxsZWwgSGFzaCBKb2luCiBleGVjdXRpb24uCgpCYXRjaCAwIGRvZXNuJ3QgbWFpbnRha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