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 1wcj5N-003ZkV-3D for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jun 2026 12:21:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcj5M-005cHi-2t for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jun 2026 12:21:36 +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 1wcj5M-005cHZ-1y for pgsql-bugs@lists.postgresql.org; Thu, 25 Jun 2026 12:21:36 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wcj5K-00000000CDk-0rAn for pgsql-bugs@lists.postgresql.org; Thu, 25 Jun 2026 12:21:36 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-37de961d1bfso1310568a91.0 for ; Thu, 25 Jun 2026 05:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782390092; cv=none; d=google.com; s=arc-20260327; b=WFKuQwH47F4bb1l1Q87HjePu/VURJy1Q57p7hJ1OSy4Mf7fYopJ9XD7CB1IwMFRb3q 4vWBoPz3naQXpwVfxJp7lt6X8Um17OQA5yM7nHPqnAcgQf9VfgWfpcPpyVrGPltTtd3+ DtnjnJNgx2sJo7affAM8rL30H/KOLDMpR6EssD+QM8uXogcaBOBKDKlThnVj1zI4p12w 5UKnpZSMWBinFAk7GazbX8wnGzQHWZHG+5i7NhFsM48b200eYUgHneXlYYTudEDe3RBN IvMOgzF/d73rpXZn2vWMQiUxhyWEi2mHAJ6/BYfUY1NG0UvsiTpqMp0CSNlHgsSq+G2a DtqQ== 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=YOTBskqviWMxJlURLx1C3gAlDU/K4MWyyd35ajuy+8I=; fh=2piwBPHZQivF6o+zMUAiazWT3xyGifQxzt4nVswEDRI=; b=DTEEhCp7Rbcae9hAFXsrduY8NMbHy7BAo2sDCheGb/A0hhf9HDdB5MH9VLPGkleYf8 wqnXC7bcO/kpzxLfeDxzu/Mgf5sn3ryclcc8mIWbERu6jgS9tf0fXB5osULwwWqr+1sY KoGkjEKEt3hAV01JovRDCZqqpIOVEjJGX7YWs+Va1ZnvEmxVbEG/q6zc+m+0qVBNETiY Vbp21tzo0YfWybI5gMvurcVGgfFiahFrRVtUL5hbvMnhLa1QOTBBLdqCV6alVEPbmICG R/R1e6+wC1QWcAwsuTnvCI9TaU1vZ25O/OrhCLzxDkAGZNgJ9MJh+ACmrpDgGg1KtOh5 GuBA==; 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=1782390092; x=1782994892; 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=YOTBskqviWMxJlURLx1C3gAlDU/K4MWyyd35ajuy+8I=; b=U4KUpw3+RXsqhy43HmFo4/TsL7QtxhAFiHu6FD2VdigvrHERvGOYNJAnXSmtDwsTX6 26DLDM49mbj9D3jIdBv9lbRzEoxliuHYvfyUDaEVhsQ7jZ/ebEP3HsKeMzK4jXbBJp2r M0b8hZfTEmTz66Qa7pnHdxfnQcWR29eksU4jpTUu+efDvJX7nNVdZyMO7E/1Lw2RPQz+ QTIyj36BSr+nORq/+n7QE7qperbszTkmivJeM4OUmKf4uFZVMDZfbNwJ0YGrCg8Ys7aI ki0U/obepFDk+DPg2HkdjDUgvEaMdT8XfTKmIkwtMrg1fOZ5dCiJNsYjASs1kPZnkCB9 Osig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782390092; x=1782994892; 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=YOTBskqviWMxJlURLx1C3gAlDU/K4MWyyd35ajuy+8I=; b=m7vm7Fwfr32YSyde7numPrHJxANCmZXw2nOExtEiMg+1+SXA9ffnqnvJBmYyWbnzzL bs4hNOE+KuQLqsL03kfgYTVsX2EYzjAU5Gt/r7Xc5MBm0j3UKtjjCGJsTS2jM5S6IMwd sds0uI77CPbHk6+aZ0frwrF3SqxHBq/zPhpVf8589RqDwCt6WgXmUa3RZHhzzVjG5qNY GNVCvsGqfGyFH5maietmBNG7ptemhvhtgvioS8vJXhhqMGRZQ2Jiiu2ovSP9FKSenCI1 6q7vQPA0u/Qsbjvj9u3ir/QTJ3/jBg+OvnVgW9BdMTtjr2hpirjoQIfgyU1DECcP9o/6 y2Tw== X-Forwarded-Encrypted: i=1; AHgh+Rofngk7neqH6oJToH0KFjDd8BsRTPtyFdALyhU/Y+2wNrPmkFEGi8cJrrjkwvhDCgMOo4lI0Rn25N60@lists.postgresql.org X-Gm-Message-State: AOJu0YxghW6B1Uxa83JAS2ZCIm2Og80VMXa8HALG0dIze5CY67XgMUt4 I52cAjgp7BFwFvk+HiDtxT7B+q+jGgqsjYU/7+AqHt1utVEGXw/oc5IK1NECtiLaK7Oq4SHll7a xy1NwHl4DQzIxX4BnEsNzQMTteOKuevY= X-Gm-Gg: AfdE7ck1G2I+gy7CvppqiWNlexyO32EyosvkQDYe/O/91XrZfIKtAwsnwsAqiayyaSm hsYB5Hn6J6ZqdZI1+9r5pl6CvKB2LIBnXX+kAe33pQACspSkNAoFd9v41d+XmC9LSQYbAtjd8x7 5pVXSZ6YfYJLVexlcrKntVIvayin4zNfa6NBwXT32vq+BWAyOJL4mdbA7kEE2HlTLfoecFIHBq6 OBlK4DKy9hMLlVrp1X1HSO1kfw0hl5sj5x+rnxWRLBBHfw55RS/q+jElBa9qVep/x6CLiYcJCM/ s0I/Fl0Aq0VyisRsPpOrB5FGMowVzIyKq6w7JFM0p8iGy0+BJ+9ZI5/EzbYmX83X X-Received: by 2002:a17:90b:1fcc:b0:36a:ee1:fc24 with SMTP id 98e67ed59e1d1-37dfa1c919fmr2413459a91.8.1782390091919; Thu, 25 Jun 2026 05:21:31 -0700 (PDT) MIME-Version: 1.0 References: <19484-a3cb82c8cde3c8fa@postgresql.org> In-Reply-To: From: Amit Langote Date: Thu, 25 Jun 2026 21:21:15 +0900 X-Gm-Features: AVVi8Cfn9XL2kMf1c1c4_hOX9VF0RMcHcReKD8Mdsb9ogKXaDO2SdNAbZRI4dIQ 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 On Thu, Jun 25, 2026 at 8:47=E2=80=AFPM Amit Langote wrote: > 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->fdwPrivList= s, j); > > > > + else > > > > + { > > > > + Index rti =3D resultRelInfo->ri_RangeTableInd= ex; > > > > + ListCell *lc1; > > > > + ListCell *lc2; > > > > + > > > > + fdw_private =3D NIL; > > > > + forboth(lc1, node->resultRelations, lc2, node->fdwP= rivLists) > > > > + { > > > > + 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 remainin= g > > > > 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. And crake turns green: https://buildfarm.postgresql.org/cgi-bin/show_history.pl?nm=3Dcrake&br=3DRE= L_18_STABLE --=20 Thanks, Amit Langote