Re: BUG #19484: Segmentation fault triggered by FDW

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
Cc: Richard Guo <guofenglinux(at)gmail(dot)com>, Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>, Rafia Sabih <rafia(dot)pghackers(at)gmail(dot)com>, 798604270(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, Amit Langote <amitlan(at)postgresql(dot)org>
Subject: Re: BUG #19484: Segmentation fault triggered by FDW
Date: 2026-06-25 12:21:15
Message-ID: CA+HiwqGOcb+ZHon5Tnm7syFW8+t-wa5rBzrSoTgh4LeVt4MrZA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Jun 25, 2026 at 8:47 PM Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
> On Thu, Jun 25, 2026 at 3:15 PM Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com> wrote:
> > On Thu, Jun 25, 2026 at 8:24 AM Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
> > > On Thu, Jun 25, 2026 at 2:02 AM Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com> wrote:
> > > > This might be nitpicking, but:
> > > >
> > > > + if (list_length(node->resultRelations) == mtstate->mt_nrels)
> > > > + fdw_private = (List *) list_nth(node->fdwPrivLists, j);
> > > > + else
> > > > + {
> > > > + Index rti = resultRelInfo->ri_RangeTableIndex;
> > > > + ListCell *lc1;
> > > > + ListCell *lc2;
> > > > +
> > > > + fdw_private = NIL;
> > > > + forboth(lc1, node->resultRelations, lc2, node->fdwPrivLists)
> > > > + {
> > > > + if (lfirst_int(lc1) == (int) rti)
> > > > + {
> > > > + fdw_private = (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.

And crake turns green:

https://buildfarm.postgresql.org/cgi-bin/show_history.pl?nm=crake&br=REL_18_STABLE

--
Thanks, Amit Langote

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Emanuele 2026-06-25 13:14:44 Re: Out-of-Cycle release? (was Re: BUG #19490: Streaming standby on 16.14 stops applying WAL on MultiXactOffsetSLRU when primary is 16.8)
Previous Message Amit Langote 2026-06-25 11:47:22 Re: BUG #19484: Segmentation fault triggered by FDW