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 1wcdNJ-003VBk-0s for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jun 2026 06:15:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcdNI-00499N-0W for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jun 2026 06:15:44 +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.96) (envelope-from ) id 1wcdNH-00499F-2r for pgsql-bugs@lists.postgresql.org; Thu, 25 Jun 2026 06:15:43 +0000 Received: from mail-dy1-x1330.google.com ([2607:f8b0:4864:20::1330]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wcdNF-000000009Sh-3wYT for pgsql-bugs@lists.postgresql.org; Thu, 25 Jun 2026 06:15:43 +0000 Received: by mail-dy1-x1330.google.com with SMTP id 5a478bee46e88-30c591fb1cbso2763021eec.1 for ; Wed, 24 Jun 2026 23:15:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782368139; cv=none; d=google.com; s=arc-20260327; b=MSnEVM733uMYGo4IPzS4TQLdC/TFCHmUi3GMJFWsucx7rBlvtYAsmH41Dby0eh9Jzh 5NmECvRBoap4Zc7ffYLFliIar5YUsOInggksL2pob5BtHG5r8fIMD3JWs8YErorNHQ63 37hza88tKg73D1RxdCY+tAHHjx/D4vw2nfH34g8KaNyeTw27MapnmCzG3cxAC2YYsnP3 otaEEjPjBpmDDcPW8YpZpMSk87NpzvL6s5aHbToueEljpKtL3I0kyb+UUIpBFYFA1cOo ka5IqYf+uaxyG5Ncc1meiZJTGLJYqx7zWLij4CfavsVrinWGmlh6Dmz4mocpTacVsEWU +iTA== 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=hZi1BMmEOn1898/sY+gT2hPXwUlPrqQrYgZ99oEJ3WU=; fh=RuPQ9bP0l7og9Wf7TzTBaMKxGjh5/OO5FaKwM0dP8xo=; b=fuI2t2oE+bX9tezkQW/OsCI/ub0UHMh29Z1QvNynH85J7V121+U2FFjIrBP7J47/si jZpOxhZDiIjvABHwCaSEL6AXytQ9uK9y5DDLhWPMCKCaEYPjnahiNuBVqTV/YLiL2ViY MTnfg5eumfDJZ3DzKBAmQCMpW8P2oV7o0dG2dK4MRHTezx+y1ua2LP+9maIFZK7ZllQF /X/MUvYDxuHANww7gSzNu5AEpPfTEPb7X0GnTBU8jpIqRmhtjy+A2iv2RAecAupHLfDQ SNR/uKBHKwnESlx5LBUI9qOvvFvOiveYm4sshUM4VJXzzquW/AASXuAUvCrWzomY4AQW GusQ==; 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=1782368139; x=1782972939; 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=hZi1BMmEOn1898/sY+gT2hPXwUlPrqQrYgZ99oEJ3WU=; b=icplufpKY7nm3S+NW9ixFneQ1taDEOy079XuQIZxIXe2FXxB7257I9mk1o0XAuxg/N X5jlXLC7NRtg116Y5UFw9J6l8AFHeVS7aAKkpZKUxxgpyzBGDMEqUGX4JqvZbt6gAInj xlE3i/+SsyFynxdVN4wMTAvUKVb+cm4RPGfkaXKCks35htzMlrEV679HzegdSRxDfQG1 8GoX5+V9c1dtd7DCA8YVciCjnJnxcDFvXOqa1jec5cA3XRQd1yCOCS9FtajmupAY7AP7 /CJTSFB2zCFDOkI5btRUH4I+kpBLkdB8IcTkepRRwS+rEGa+XjUPW2GSNESoPgjg817U nCFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782368139; x=1782972939; 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=hZi1BMmEOn1898/sY+gT2hPXwUlPrqQrYgZ99oEJ3WU=; b=JonxEo7FkzLhC/SuQQtoydfqXwxGlFjVQFxuAiKgR6cIKY2BqAXpW0xuYX7iYGF4C5 GwCXRN15qJPnMcCdTu4OLqpVcy9cGc3A8jG8ZupRdRUv4whj9V28DQT4K7YQi7aqaO0b Ko+CZN4WCHZSiBe19ZGMEDv9E55FkByyNOc7x70YB+m2sCBJ/OKTuxLynn+ckBIL3kyw s3a76h/TCaoIakVLyo8puaj3dVG1gzpuFgDV/k1UXRBQ3KENVGNut/wyhxtnMPLa05N8 G8Cf90lGwZZAiIHFmSw7IAiTznn5Hf5toA5z1++4/xT6AydOqc4/j1jo6KF73XIMBwkI gKyQ== X-Forwarded-Encrypted: i=1; AHgh+RpO0xb6nzMcqeb71dLY84yGovZrSXoTQr92c/rQmW4hTra9B47qcTxWW5ycVJf52LoXokLXdcVhlt9o@lists.postgresql.org X-Gm-Message-State: AOJu0Yz7cvqgNkq3i3QueuxOX2Tl5/lXYgYAU4ioL0+8dCm3N2uxhmE/ bOoSiq3gVFwug/2nXF6W0dwv2+tFLIVbxoazbHVwy2Zep/gdju9XJSWJhwqbM3WZnlHlPWQw0r/ hNJLr0zc+bDaPZlJT0IGyohn8//ItVtw= X-Gm-Gg: AfdE7ckCcFt/X81A7eL8QQlnqmh+HGO3URaotDTzRMTdjIDqsR+5EEzw0SF8oExDRB3 Evvqz/RdaaLTdQE3cQcX0r1fdB6i8CnK8VbMBujxJ9cIrC1LA0DHTB9IVHbSujHybYiG/oMPJ6J pDtSqVB8MoRmxV3OjnUoI5Woxr9RjzTiNqf9qqZvHprtwoxZ+N0BmevPBlQo5Bvbl87/daFDly6 wSDKnLEfYP3gpUevzx9uyw9RDso2HVXU8RKzVwhH6Eh9zFbaMmiCrX75kOV3yErhvx5UtSWt+Zm kgDAFDUU06A0PM9C9PU954t6ukGVQQ+EflthKSC/w4l1humrDejsHNGy/uAwkJhu1hWkm7XFDx2 zugqFJJSl6LT7iAOdEmF7hPhJVTf5Vw== X-Received: by 2002:a05:7301:658a:b0:2ea:c085:44b1 with SMTP id 5a478bee46e88-30c84d0a117mr1162371eec.19.1782368139442; Wed, 24 Jun 2026 23:15:39 -0700 (PDT) MIME-Version: 1.0 References: <19484-a3cb82c8cde3c8fa@postgresql.org> In-Reply-To: From: Etsuro Fujita Date: Thu, 25 Jun 2026 15:15:22 +0900 X-Gm-Features: AVVi8CexRNtt79_r8U6hbCK5LHKq2PC6X5eBg7U5FxihkJ5ixlxCKe7kCH5bT9A Message-ID: Subject: Re: BUG #19484: Segmentation fault triggered by FDW To: Amit Langote 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 Amit-san, 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_n= rels) > > + 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->fdwPrivL= ists) > > + { > > + 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! Best regards, Etsuro Fujita