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

From Tender Wang
Subject Re: BUG #18902: TRAP:: failed Assert("!is_sorted") in File: "createplan.c"
Date
Msg-id CAHewXNm=PzyhWgBvPJh9MYBhQzSjNYtRh1mq=ieCKWrKD2wMpQ@mail.gmail.com
Whole thread Raw
In response to Re: BUG #18902: TRAP:: failed Assert("!is_sorted") in File: "createplan.c"  (Tender Wang <tndrwang@gmail.com>)
Responses Re: BUG #18902: TRAP:: failed Assert("!is_sorted") in File: "createplan.c"
List 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

pgsql-bugs by date:

Previous
From: Tender Wang
Date:
Subject: Re: BUG #18902: TRAP:: failed Assert("!is_sorted") in File: "createplan.c"
Next
From: Alvaro Herrera
Date:
Subject: Re: Command order bug in pg_dump