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 1tmFNb-005ED2-NM for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Feb 2025 17:03:00 +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 1tmFNa-00BhF5-3Z for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Feb 2025 17:02:58 +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 1tmFNZ-00BhEt-Q7 for pgsql-hackers@lists.postgresql.org; Sun, 23 Feb 2025 17:02:57 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tmFNW-000Lj6-38 for pgsql-hackers@lists.postgresql.org; Sun, 23 Feb 2025 17:02:57 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 51NH2nNU914331; Sun, 23 Feb 2025 12:02:49 -0500 From: Tom Lane To: Alexander Korotkov cc: Alena Rybakina , PostgreSQL Hackers , Andrei Lepikhov , Robert Haas , Richard Guo , Alexander Lakhin , "Gregory Stark (as CFM)" , =?UTF-8?B?TWljaGHFgiBLxYJlY3plaw==?= , Dean Rasheed Subject: Re: Removing unneeded self joins In-reply-to: References: <64486b0b-0404-e39e-322d-0801154901f3@postgrespro.ru> <2422119.1714691974@sss.pgh.pa.us> <24e93efd-eeac-43a6-a75a-ad68eacb32ee@postgrespro.ru> <3622801.1715010885@sss.pgh.pa.us> <5934ce1e-be02-4640-904c-f7fec3962784@gmail.com> Comments: In-reply-to Alexander Korotkov message dated "Sat, 15 Feb 2025 11:19:42 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <914329.1740330169.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 23 Feb 2025 12:02:49 -0500 Message-ID: <914330.1740330169@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alexander Korotkov writes: > I've corrected some spelling error reported by Alexander Lakhin > privately to me. Also, I've revised comments around ChangeVarNodes() > and ChangeVarNodesExtended(). I'm going to continue nitpicking this > patch during next couple days then push it if no objections. Coverity has another nit-pick: /srv/coverity/git/pgsql-git/postgresql/src/backend/optimizer/plan/analyzej= oins.c: 327 in remove_rel_from_query() 321 static void 322 remove_rel_from_query(PlannerInfo *root, RelOptInfo *rel, 323 int subst, SpecialJoinInfo *sjinfo, 324 Relids joinrelids) 325 { 326 int relid =3D rel->relid; >>> CID 1643155: Integer handling issues (INTEGER_OVERFLOW) >>> Expression "ojrelid", which is equal to 4294967295, where "(sjinfo= !=3D NULL) ? sjinfo->ojrelid : 4294967295U" is known to be equal to 42949= 67295, overflows the type that receives it, a signed integer 32 bits wide. 327 int ojrelid =3D (sjinfo !=3D NULL) ? sjinfo->ojrelid : -1; 328 Index rti; 329 ListCell *l; 330 = 331 /* 332 * Update all_baserels and related relid sets. This is unhappy because sjinfo->ojrelid, which is declared Index (that is, unsigned int) is being converted to int. Admittedly there are plenty of other places that do likewise, but the additional load of assuming that -1 isn't a possible value of sjinfo->ojrelid seems to be enough to draw its ire. I suggest finding another way to code this function that doesn't depend on that type pun. I think it's fairly accidental that adjust_relid_set doesn't misbehave on -1 anyway, so personally I'd get rid of that local variable entirely in favor of something like if (sjinfo !=3D NULL) { root->outer_join_rels =3D adjust_relid_set(root->outer_join_rels, sjinfo->ojrelid, subst); root->all_query_rels =3D adjust_relid_set(root->all_query_rels, sjinfo->ojrelid, subst); } regards, tom lane