Re: BUG #18902: TRAP:: failed Assert("!is_sorted") in File: "createplan.c" - Mailing list pgsql-bugs

From David Rowley
Subject Re: BUG #18902: TRAP:: failed Assert("!is_sorted") in File: "createplan.c"
Date
Msg-id CAApHDvoWRDaw+EsCi3aPpTYC50iP2DLJii+Ms2o+AgBXAY6YGg@mail.gmail.com
Whole thread Raw
In response to Re: BUG #18902: TRAP:: failed Assert("!is_sorted") in File: "createplan.c"  (Richard Guo <guofenglinux@gmail.com>)
List pgsql-bugs
On Fri, 25 Apr 2025 at 14:16, Richard Guo <guofenglinux@gmail.com> wrote:
> Hmm, well, I don't think we can get rid of MergePath.outersortkeys and
> innersortkeys, even if we've cached the number of presorted keys for
> the outer and inner paths.  These fields represent the desired
> ordering to be produced by an explicit Sort node — not the current
> ordering of the outer or inner path.  Without this information, how
> would create_mergejoin_plan know what sort order to generate for the
> outer and inner paths if they are not already sorted?

I misspoke about getting rid of the two List fields.

> Maybe we could cache the number of presorted keys for the outer and
> inner paths in MergePath to save some pathkeys_count_contained_in
> calls.  But I'm not too sure it's worthwhile.  The pathkeys are
> canonical, and can be checked for equality by simple pointer
> comparison.  So it does not seem to cost too much.  Besides, the
> "redundant" pathkey checks actually helped uncover the bug we're
> discussing here — didn't they?

I don't see any reason why we couldn't keep an Assert to ensure the
sorted-ness of the Path matches our expectations. Calculating the
whole thing again in non-assert builds seems a bit silly.  The
previous code took care to avoid recalculations by nullifying the
Lists when no sort was required, you've not followed that with the
incremental sort changes, and to me, that makes it feel a little
half-done.

David



pgsql-bugs by date:

Previous
From: Shlok Kyal
Date:
Subject: Re: BUG #18897: Logical replication conflict after using pg_createsubscriber under heavy load
Next
From: PG Bug reporting form
Date:
Subject: BUG #18904: INTERSECT with an impossible where should eliminate both from the query plan