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 1wcR07-003LRj-1d for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jun 2026 17:02:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcR04-001j9r-2i for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jun 2026 17:02:56 +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 1wcR04-001j9f-1G for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 17:02:56 +0000 Received: from mail-dy1-x1335.google.com ([2607:f8b0:4864:20::1335]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wcR02-000000003Z4-1DRv for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 17:02:55 +0000 Received: by mail-dy1-x1335.google.com with SMTP id 5a478bee46e88-30b6dad2382so2266662eec.0 for ; Wed, 24 Jun 2026 10:02:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782320573; cv=none; d=google.com; s=arc-20240605; b=emQVeEeQeJvJWMkxI3AB7LHXom7sdnZob8aZ3klmZ+NJdkGxNUiqUziC1eBXobAHg7 +wYU1CAORSVFs7TfSPrKekgTT49HMhffcFWiqzVypXbFxZJXVEgI/F8BBv8iR7G0nw/F lF9sObzt4nt49v3co5sLGrA0nxPIKLMfjEQlBD6jF2LrBT12jPYQsB2IpOmG8G5LlMdc Rki8LtulajYP1LddfMihZCWOFnBTIix1/rKpjeKfcLC2obYW8scJEgpJlCuVH0h8Nx6r 2OOMuQYdgZ/YLrssn1AvsfDRWKIqt8Q8bLwhkLedLspirC5/f6bFugf4PQzGpDOOhl5d h0KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LAa4gnKfI2zk/VodWLpp2WfD5T1eTDpqs6AS23ppFUQ=; fh=HVJSznRrxk+V122vpSNNR7fM9X6FcqXkVhx2c5fhCag=; b=aJ4sYqDkNaEvr9m93zyFoy+bzcR2XjaVXc9mWKJl6u9r6EAZrUeDpsVyzluHEgYTHy CVkeFsBEDEheYIVbXpUp454SiEpO7Uh51RJNkr6Ysc5ndVGJgY55yKjrJl8q/q2gmKQe hA+EG9dcIHloVJ7/oNDRhMnYnBXYtD+ExdHpKG8rmkkip/ZXW4rugU+ITfs+pBDq1zrt QDMYJq76FKtjT/V7cd+rjCKuTYAgwadn7c/G9RpjcZNEShmWFxZ4wJ1UMZuhFDgKyg8V 6l49Q6qFUTVqa5NpRaNfo3IiBMnZPEyjP7jtqZSWPiD4eflnyTOnBuTi1DjU1u/pwNHf M7Pw==; 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=1782320573; x=1782925373; 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=LAa4gnKfI2zk/VodWLpp2WfD5T1eTDpqs6AS23ppFUQ=; b=BOV1nnrgAG/YNt24Tqo0ayJq3JlgW9+UFwSzsjwPeuWR1lGZYLtGf6j6aiq3/WmJKx 0q/tom1pNkDUYwhLFNTa2uWslEdNNHOqXAvWk8UZ8WprkLm3/vrhw3c92uBAL44J72kB AxSaT006u0uI8c2ShWQlAGZCceKQNNQuf4HqnT1VejwEUU8GLYd2gmD37RlyN5fcuhz+ f7ekVpJgaGOZ5sVrbjFw2R+dAcsqD8ba05tDAP4Tud680+/HsUuS9rjI+Oi8dwGmDZAj 6C6A++ws7U9+xw1Cn5m+F9t8lXnHpTrIRWA2FxzJkFahWpNpCS1a76cZaTSLkYRJ4QDv tlkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782320573; x=1782925373; 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=LAa4gnKfI2zk/VodWLpp2WfD5T1eTDpqs6AS23ppFUQ=; b=H3VjrepCne9Spz8jUWbTAwzcn5fyTvVmWLasyR/j5t2eojtW0CxrHoDGAj4Nk4FdPO gPl+Vi5JTjq7zOdQwYx8Db9fAfKIjIOunTqUaHAAa01ozsheiU+9VhuXmzNNdvj/eNcA 20SiZmMBPxAmW9SP0bTCvXx15FvfYKzEvhmIjZzH0PlhlelVgVx3nk/GJ24KwBIIx8ou zpiDFlgJ6sXVsgyk9G0oyvm+TZBVWP6Limuam2vb9WsbBml+Bmfp2Pe24G7qY0fZXYZy 90luSVDM/YA1G7nDt/wmh8HeiHpTsBhoib+OYnHrwFU2OfG3IKzO33ZLQLV9i3g/6jgN MFFA== X-Forwarded-Encrypted: i=1; AHgh+RpQQS+qATsIai3yLbTvcMSHiAA/pnpZdfN4F50Eez4J0xcRfWY9FcXjWCOZa47mMN3k2DtJeeSjV7cO@lists.postgresql.org X-Gm-Message-State: AOJu0Yy7GJVL+FJokXXRVDJPZUhgkVlUajMSEJOsdOtGkbbBCbH9P5E+ 1lPshAxUMVCKsuuYU5xy6jpCDS9uldSes/6k+nkJxOL0wOi2gm/TTHHongk9whh+0t5N4zwBlcZ zKtHvdE6LkIMiWzt5KtP1pPtL8kMZP4s= X-Gm-Gg: AfdE7cmIW7U/olOUgpny1bVTS9TYo4tgZBdNQR3MEMnaJO/uZGyyAt4X5RBKmSMKKX2 7FKWWTHUyeWUmn/5l/04Dxfl5E51RXbSL5Dh3tig1YWsuM/n89InKpLLm1Jc7vz7o6de0GsEMm2 unkQFcPqrXCj19oj2EDd0z3Z1bXbpuJNwbS1Kw0fNkynqrin7OOpqaKqdmVY6BAXI+/s+qUkiyk xuq16Vb/r0fnmlpWK6yKdfSJ6OEcslx6ZOqLFUiUhRbn2ta5M9cNrNKC+If0Usi/W61gNKbUuca Q17E/I8FAmR9DVnrUly3S2fUMLKQS+ZQJocckO2cjS0rMdl7MOHjyC21Io90sm7ZSnF8ugHsGbG jXaLyBh4GUTxQlfEuAFxi6HwOuGkklQP4PIS7howG X-Received: by 2002:a05:7300:5412:b0:30c:1865:d9f6 with SMTP id 5a478bee46e88-30c58a44ffdmr8253663eec.6.1782320572859; Wed, 24 Jun 2026 10:02:52 -0700 (PDT) MIME-Version: 1.0 References: <19484-a3cb82c8cde3c8fa@postgresql.org> In-Reply-To: From: Etsuro Fujita Date: Thu, 25 Jun 2026 02:02:41 +0900 X-Gm-Features: AVVi8CeZbxQvJ3k7u_DX1sL07ud0ba9fph2H1N5fqDJL_RI6Qlb3pf2e-EUGlqE 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 Wed, Jun 24, 2026 at 8:20=E2=80=AFPM Amit Langote wrote: > On Wed, Jun 24, 2026 at 6:15=E2=80=AFPM Etsuro Fujita wrote: > > + /* > > + * node->fdwPrivLists is indexed by the original, pre-pruni= ng > > + * result relation order and is parallel to node->resultRel= ations. > > + * Initial pruning may have dropped earlier relations, so t= he kept > > + * index j need not match the original position; find this > > + * relation's entry by its range table index instead. > > + */ > > + forboth(lc1, node->resultRelations, lc2, node->fdwPrivLists= ) > > + { > > + if (lfirst_int(lc1) =3D=3D (int) rti) > > + { > > + fdw_private =3D (List *) lfirst(lc2); > > + break; > > + } > > + } > > > > I think it's good to skip this for efficiency, when there are no > > pruned result relations. > > Thanks for the review. v2 attached implements your suggestion: it > indexes node->fdwPrivLists directly with j when no result relations > were pruned, and only falls back to matching by range table index when > pruning appears to have dropped some. Thank you for doing that work! 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->fdwPrivLists= ) + { + 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. 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.) Best regards, Etsuro Fujita