Re: BUG #18902: TRAP:: failed Assert("!is_sorted") in File: "createplan.c"

Tender Wang <tndrwang@gmail.com>

From: Tender Wang <tndrwang@gmail.com>
To: n.kalinin@postgrespro.ru, pgsql-bugs@lists.postgresql.org, Richard Guo <guofenglinux@gmail.com>
Date: 2025-04-23T11:47:42Z
Lists: pgsql-bugs
Tender Wang <tndrwang@gmail.com> 于2025年4月23日周三 19:03写道:

>
> I remove the Assert(!is_sorted), its plan looks like as below after adding
> below codes:
> if (presorted_keys > 0 && presorted_keys <
> list_length(best_path->outersortkeys))
>        use_incremental_sort = true;
>
>                                          QUERY PLAN
>
>
> ---------------------------------------------------------------------------------------------
>  LockRows
>    ->  Merge Join
>          Merge Cond: (local_tbl.c1 = ft1.c2)
>          ->  Index Scan using local_tbl_pkey on local_tbl
>          ->  Sort
>                Sort Key: ft1.c2
>                ->  Foreign Scan
>                      Relations: (((ft1) INNER JOIN (ft2)) INNER JOIN
> (ft4)) INNER JOIN (ft5)
>                      ->  Merge Join
>                            Merge Cond: (ft1.c2 = ft5.c1)
>                            ->  Sort
>                                  Sort Key: ft1.c2
>                                  ->  Merge Join
>                                        Merge Cond: (ft1.c2 = ft4.c1)
>                                        ->  Sort
>                                              Sort Key: ft1.c2
>                                              ->  Merge Join
>                                                    Merge Cond: (ft1.c1 =
> ft2.c1)
>                                                    ->  Sort
>                                                          Sort Key: ft1.c1
>                                                          ->  Foreign Scan
> on ft1
>                                                    ->  Sort
>                                                          Sort Key: ft2.c1
>                                                          ->  Foreign Scan
> on ft2
>                                        ->  Sort
>                                              Sort Key: ft4.c1
>                                              ->  Foreign Scan on ft4
>                            ->  Sort
>                                  Sort Key: ft5.c1
>                                  ->  Foreign Scan on ft5
>

If is_sorted is true, it means that it's already fully sorted,  the Sort
node doesn't need any more.
I suspect something went wrong somewhere else.  I didn't look into the
details.


-- 
Thanks,
Tender Wang

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Track the number of presorted outer pathkeys in MergePath

  2. Suppress unnecessary explicit sorting for EPQ mergejoin path

  3. Re-enable SSL connect_fails tests, and fix related race conditions.

  4. Consider explicit incremental sort for mergejoins