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 1rIi2v-00A9EC-EW for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Dec 2023 04:31:02 +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 1rIi2t-00CWpu-2w for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Dec 2023 04:30:59 +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 1rIi2s-00CWpl-M9 for pgsql-bugs@lists.postgresql.org; Thu, 28 Dec 2023 04:30:58 +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 1rIi2k-00CXrO-Th for pgsql-bugs@lists.postgresql.org; Thu, 28 Dec 2023 04:30:57 +0000 Received: from [10.10.20.53] (node-pbp.pool-101-109.dynamic.totinternet.net [101.109.128.53]) (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 A1AE9E20E22; Thu, 28 Dec 2023 07:30:45 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1703737846; bh=TiHYccwLYy4pRbB+ATgEWlLAZqQKxtPb5UUUHdg2KXs=; h=Message-ID:Date:User-Agent:Subject:To:References:From:In-Reply-To: From; b=OIC7CtSlTsDkGfee7uv1Hx2AmuaHI2Oirjj0e8HSm1Z/7fPNmqM+NVAPZZb76Q+c4 Nn0ZyBP8BSfIw9KUyXd3AJVO3uOULpSo7a8MkuL6fJxAwZzcnoKMKd9qAx+iGGhG3X PEfr9SFAsmoVh7q65yRh212HGq620b2uucoacNrqnNECGn28nRJbMldS1J7V1Bp9mS NazPoTIEeIbSBDY2qHiqhjFL0zz4XdB2yIsCfBNeX3uGASehRwkuSG/53WniOp9gLs MoZT0INSQInJ+yuQ7BPiesXbA56QmuXCoi2402Ahi5Tby3ymXHzPrHU2xsPHysEvYi 4cMyLx4PrW0hQ== Message-ID: Date: Thu, 28 Dec 2023 11:30:42 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18260: Unexpected error: "negative bitmapset member not allowed" triggered by multiple JOIN To: Richard Guo , zuming.jiang@inf.ethz.ch, pgsql-bugs@lists.postgresql.org References: <18260-1b6a0c4ae311b837@postgresql.org> Content-Language: en-US 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 28/12/2023 10:03, Richard Guo wrote: > During that time, join removal was only performed for left joins, so it > was not possible for 'ojrelid' to be negative.  However, with the > introduction of the SJE feature, inner joins can also be removed, and > 'ojrelid' is set to -1 in the inner join case.  That's how we see this > error. Agreed, I have come to the same conclusion. >         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))) It would be better to check "ojrelid >= 0" as a sign. But why do you think SJE could need to delete PlaceHolderVar at all? > > 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. > 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): explain (verbose, costs off) select 1 from t t1 left join (select 1 as x, * from t t2) s1 inner join (select * from t t3) using (a) on true where s1.x = 1; -- regards, Andrei Lepikhov Postgres Professional