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.96) (envelope-from ) id 1wciYZ-003ZKP-38 for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jun 2026 11:47:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wciYY-005Fg0-31 for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jun 2026 11:47:42 +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.96) (envelope-from ) id 1wciYY-005Ffs-1n for pgsql-bugs@lists.postgresql.org; Thu, 25 Jun 2026 11:47:42 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wciYW-00000000BAd-1dq9 for pgsql-bugs@lists.postgresql.org; Thu, 25 Jun 2026 11:47:41 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-845a3c05df9so1959469b3a.3 for ; Thu, 25 Jun 2026 04:47:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782388059; cv=none; d=google.com; s=arc-20260327; b=N0UiEPFfss9QmIdgs7cww4UxwVRdO+M1xVq3uK0m0uaqdunTiZsFOi6E3+pDDYbzP+ iTpNISWg/jjmSb/aznstFcesrRTIrgMGFvQ5kyl0TUWHOIO+qs3YfnlOMLLVTSeR9Eu/ LbDIOBOkxVZmvbsZ8aDw6Pt9z0m6SucJ/mwq9RvK+fu3STMVUTPmve6NNoBVNlgrC7bT P3IweL+GpLih9IJzX+YdqbFpYjKfBO6rHUNJhBZWRTwcG2pOCiDrOm6EIkvdluSp250z XUiycUO6UmiOfZLlZ9BPNwjaXOs+sNVeTjkC3f2CYPkr7WnrlD/NbFj1hxywKHIb0J3J NSvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=M6tNOa1Yny4EtSazng4/E7ne6JW1eyJFr1mO21hHMu4=; fh=VtmQO2hLz2Xqe+1SrVPr9zE+k5qwfkjpPrFwejcifFo=; b=VEmyjYkajHlD2jmkITfAaMGIsh2I3kK/XJPybhwOCYuh4AC1fArPwkTH8XxmrtCuu9 /1KjAy4iLv0jzonQ6AKnNlkWI4cw4x1u5LOxUgDRkolhHXd/1ftG2Ip+s857iXPlmDex RfWjf7lFeEZpqF6QD002SPAHJ+3KSmv6Ut0H/ouepRSZxGLth0PwVSOFkrnnYvGK0Igh GlpEHqIxOLFTYwLQOakGnGU06eJaDAI9NOPaTYrqwBEijeck6ILxnrhLHEq77hO8UvKU LP7TCEqMcMxqzO0OzWFVpRwRKkW+7MSVOz8ipDCbSqKe5+8CCNiiCHaXQuUNpB0C8JA0 sZKQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782388059; x=1782992859; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=M6tNOa1Yny4EtSazng4/E7ne6JW1eyJFr1mO21hHMu4=; b=Htx57euj+4El5ysbw7M0ozhs9oXJV+y09A+NOXCMRPR4tCx33Ov69EhnwOoq0z1l2I g5qzo1Pi+UbgoBeojMTootrps+gyW9v153Qu+EL7z3FO8ZFSNFydeYagk/vgYhWH2/s8 C8hhNR3auZl/3hmfyiy8x+mbgAU6lvSmg8W/oAngIqRD+dlwcWad5QJ2uNQtCWaqNWQv i4WyRNKmqyIvn/KYbSVHOYWGfh756ORiqcRooSlRDT1mWwhD3rDdATpA/i1nnnMzXI+l U02ndt+W/dfgXJcPluE0ALpNDx7mGAQ8q5NN6SQSJ85i1+9hoS8RJ+M483HEyLRm+I38 y0ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782388059; x=1782992859; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=M6tNOa1Yny4EtSazng4/E7ne6JW1eyJFr1mO21hHMu4=; b=cA5Sb8f+dY0c1Yn80LwMsmeCDM3+APRThur5P4pX8hq9wnBwyOJGVbwian5S7LjU/N 3fiX8jX7o3bm03PUkjlDKrMkfJcerS+Sm6phGGCYYtpDyakaTm0MJcal1Pfwh2mbmADF NhmDlEmkW1e4u58wujoKlQLvbRLuaEay2qXPXLkBinl3cjUltSkcg1fobw8v2TxX02xo b0aIyozRASmHPhVHCLEaS2GQlqXO8MTXcSQ8GbcezjjFL0olKTPbNYpOVb84GUfkHdWW 3NwocXUG+mpxaZ/HVsVGqgBAWpCiqmBMsEecUrCakNHkcCuOvswnCpjweCsSOQMuBjOd 3I/g== X-Forwarded-Encrypted: i=1; AFNElJ9uFNQOFeQc4cEqasia+RH4e+80bLuetGW5DBgfQDxBN2yXWCGQHF/rEz8gJMB4NBEG70A/ZNnVpTmO@lists.postgresql.org X-Gm-Message-State: AOJu0Yy2Pfz+B707XCwIRcjxecqweck8b11TKQF7PCyQQieV760Qsr5e Tf3cVFy6Qbb3dfSlWSdtXARlhx2rk1j68L6RtaSW39vGir0wLxdZQ7+yF+MQNuPhugedPBvX2Us FmXOtdvtO914gpWvPGVZVcQrWvVjWESM= X-Gm-Gg: AfdE7cmQV8izBJ3seEoxw6sWUTJsRXVsxtjyU3N0GUyXcSRNqO1bWmLJIWJZVhNd5PW fr5vNN9L5fJH2KosZ5BZ9eIvYV2PWgXLWroLvSUR6wIxNIYaH+3I13Clzv34couBIQ6SnkTSpeG A5d725L6VRtich191je2eP25TXP8z15JpXEDDzpTyXH1/WRTubIXdLzyAVVEw9P1LGIwO5xp1rs kgysslMEKVJaerPVpoeGCYfRJDpsnDZ7t6XYScrc9RD8SHKGs21n+PS6UxaLHISSIxos7xdpPzG 7Rx6eBWJST2hRobKWfrAniRLPFfRlI58x2RhJEw0wyxULl7JvmYLaA== X-Received: by 2002:aa7:8884:0:b0:845:44c7:5e28 with SMTP id d2e1a72fcca58-845b3b8810amr2749846b3a.31.1782388059289; Thu, 25 Jun 2026 04:47:39 -0700 (PDT) MIME-Version: 1.0 References: <19484-a3cb82c8cde3c8fa@postgresql.org> In-Reply-To: From: Amit Langote Date: Thu, 25 Jun 2026 20:47:22 +0900 X-Gm-Features: AVVi8Ce5mY_XbI9QxoIh_GMxrg6aZnNrXZgnMPZt8mImE2_1O00d-rQpwxDsgMA Message-ID: Subject: Re: BUG #19484: Segmentation fault triggered by FDW To: Etsuro Fujita Cc: Richard Guo , Matheus Alcantara , Ayush Tiwari , Rafia Sabih , 798604270@qq.com, pgsql-bugs@lists.postgresql.org, Amit Langote Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Fujita-san, On Thu, Jun 25, 2026 at 3:15=E2=80=AFPM Etsuro Fujita wrote: > On Thu, Jun 25, 2026 at 8:24=E2=80=AFAM Amit Langote wrote: > > On Thu, Jun 25, 2026 at 2:02=E2=80=AFAM Etsuro Fujita wrote: > > > This might be nitpicking, but: > > > > > > + if (list_length(node->resultRelations) =3D=3D mtstate->mt= _nrels) > > > + fdw_private =3D (List *) list_nth(node->fdwPrivLists,= j); > > > + else > > > + { > > > + Index rti =3D resultRelInfo->ri_RangeTableIndex= ; > > > + ListCell *lc1; > > > + ListCell *lc2; > > > + > > > + fdw_private =3D NIL; > > > + forboth(lc1, node->resultRelations, lc2, node->fdwPri= vLists) > > > + { > > > + if (lfirst_int(lc1) =3D=3D (int) rti) > > > + { > > > + fdw_private =3D (List *) lfirst(lc2); > > > + break; > > > + } > > > + } > > > + } > > > > > > I'd put the if-test outside of the outer loop to save cycles. > > > > Right, it's loop-invariant. v3 attached computes a boolean > > (nopruning), like labeltargets, once before the loop and uses it > > inside. > > > > > Other than that v2 looks good to me. > > > > > > (The forboth loop actually causes an n-squared calculation, but it's > > > done only when pruning occurs, in which case the number of remaining > > > result relations would be reduced, so that wouldn't be a problem.) > > > > Right, though strictly the inner forboth scans node->resultRelations, > > which pruning leaves at its original length, so it's the original > > relation count that bounds the scan rather than the reduced one. > > Either way it's EXPLAIN-only with small counts, so it's not a concern. > > That's right. > > The v3 patch looks good to me. Thanks for updating the patch! Pushed, thanks for checking. --=20 Thanks, Amit Langote