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 1rPAig-009iWf-5H for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Jan 2024 00:20:51 +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 1rPAif-00CvRq-8z for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Jan 2024 00:20:49 +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 1rPAie-00CvRi-TB for pgsql-bugs@lists.postgresql.org; Mon, 15 Jan 2024 00:20:49 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rPAib-001Z3A-Ia for pgsql-bugs@lists.postgresql.org; Mon, 15 Jan 2024 00:20:47 +0000 Received: from [192.168.1.35] (cm-27-145-161-7.revip12.asianet.co.th [27.145.161.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id BF697E21016; Mon, 15 Jan 2024 03:20:40 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1705278042; bh=4uuFkftWGwpBEwb8SIUp+t3mIufzxGh2Q8wIRyjhTPw=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=kNV8cX/tEwpW3dOI/7tJOadyMiceW2SOJWQ3JTQJ411xV4nyPlUcwqx2vk9YhmJbV pDeJ2V3ZblF+tbFaMG8IbcTupSRVGKkaE+qvGz812JH97J7vvt515C5jV5rDCWhCS1 tOhFRDOhsTfj0TMSL6pAOYakEZSSG6aaEymjoEg9Ou/7NntJkt9uXQQsDEbaJXtgic Q0ybzZhp6McMA7ouVi3gJN+veltArZ6RfZi/1Y2bkgvV0pSYVm+avIKTcS3y/tGe0c R/VzkoH5r7lstp7hkZzjk5AzkWvSi/4BKBx4Z3KEAPLz0FdB9aK5PYgpkL2V+VgSzj DXTJLgVy/n50g== Message-ID: <72b0913e-a2b1-444d-a2fa-fa154ae91034@postgrespro.ru> Date: Mon, 15 Jan 2024 07:20:37 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18260: Unexpected error: "negative bitmapset member not allowed" triggered by multiple JOIN Content-Language: en-US To: Richard Guo , Alexander Korotkov Cc: zuming.jiang@inf.ethz.ch, pgsql-bugs@lists.postgresql.org References: <18260-1b6a0c4ae311b837@postgresql.org> From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/1/2024 16:08, Richard Guo wrote: > > On Thu, Dec 28, 2023 at 12:30 PM Andrei Lepikhov > > wrote: > > On 28/12/2023 10:03, Richard Guo wrote: > >          if (bms_is_subset(phinfo->ph_needed, joinrelids) && > >              bms_is_member(relid, phinfo->ph_eval_at) && > > -           !bms_is_member(ojrelid, phinfo->ph_eval_at)) > > +           (sjinfo == NULL || !bms_is_member(ojrelid, > phinfo->ph_eval_at))) > > > Alternatively, we can modify bms_is_member() to return false for > > negative numbers instead of emitting an error, as suggested by the > > comment there. > > -   /* XXX better to just return false for x<0 ? */ > > +   /* negative number cannot be a member of the bitmapset */ > >      if (x < 0) > > -       elog(ERROR, "negative bitmapset member not allowed"); > > +       return false; > > > > I prefer the second option, but I'm open to other thoughts. > I don't like this option. It could mask some blunders somewhere like a > current one. > > > After a second thought, I agree that the first option is better.  It > maintains consistency with the Assert a few lines ahead, and also > minimizes the potential impact of code changes compared to the second > option. > > > FWIW, here is a simplified repro for this error. > > > > create table t (a int primary key, b int); > > > > explain (verbose, costs off) > > select 1 from t t1 left join > >      (lateral (select 1 as x, * from t t2) s1 inner join > >          (select * from t t3) s2 on s1.a = s2.a) > >      on true > > where s1.x = 1; > > ERROR:  negative bitmapset member not allowed > It can be simplified even more (without LATERAL): > > > Indeed.  I realized this shortly after v1 patch was sent out, and was > thinking that it wasn't worth the effort to update the patch with a new > version just for this issue. I like it, thanks for your efforts. -- regards, Andrei Lepikhov Postgres Professional