Hi

po 30. 11. 2026 v 14:34 odesílatel Pavel Stehule <[email protected]>
napsal:

> Hi
>
> i rechecked this test on Postgres compiled without asserts, and the
> overhead of DISTINCT is not too strong, but still it is visible
>
> cca 3ms x 0.5 ms. There is dependency on the number of columns - the real
> slow query has 220 columns in the DISTINCT clause and planning is about 50
> ms.
>
> I tested pg13 - master and the overhead is visible on all versions
>

with more columns the overhead is more visible (the test is attached)

the profile

+  100,00%     0,00%  postgres  postgres           [.] _start
                                                           ▒
+  100,00%     0,00%  postgres  libc.so.6          [.]
__libc_start_main@@GLIBC_2.34
                                                  ▒
+  100,00%     0,00%  postgres  libc.so.6          [.] call_init (inlined)
                                                            ◆
+  100,00%     0,00%  postgres  libc.so.6          [.]
__libc_start_call_main
     ▒
+  100,00%     0,00%  postgres  postgres           [.] main
                                                           ▒
+  100,00%     0,00%  postgres  postgres           [.] PostmasterMain
                                                           ▒
+  100,00%     0,00%  postgres  postgres           [.] ServerLoop
                                                           ▒
+  100,00%     0,00%  postgres  postgres           [.] BackendStartup
                                                           ▒
+  100,00%     0,00%  postgres  postgres           [.]
postmaster_child_launch
    ▒
+  100,00%     0,00%  postgres  postgres           [.] BackendInitialize
                                                            ▒
+  100,00%     0,00%  postgres  postgres           [.] PostgresMain
                                                           ▒
+   99,99%     0,00%  postgres  postgres           [.] exec_simple_query
                                                            ▒
+   99,87%     0,00%  postgres  postgres           [.] PortalRun
                                                            ▒
+   99,87%     0,00%  postgres  postgres           [.] FillPortalStore
                                                            ▒
+   99,87%     0,00%  postgres  postgres           [.] PortalRunUtility
                                                           ▒
+   99,87%     0,00%  postgres  postgres           [.] ProcessUtility
                                                           ▒
+   99,87%     0,00%  postgres  postgres           [.]
standard_ProcessUtility
    ▒
+   99,87%     0,00%  postgres  postgres           [.] ExplainQuery
                                                           ▒
+   99,86%     0,00%  postgres  postgres           [.] ExplainOneQuery
                                                            ▒
+   99,86%     0,00%  postgres  postgres           [.]
standard_ExplainOneQuery
     ▒
+   99,76%     0,00%  postgres  postgres           [.] pg_plan_query
                                                            ▒
+   99,76%     0,00%  postgres  postgres           [.] planner
                                                            ▒
+   99,76%     0,00%  postgres  postgres           [.] standard_planner
                                                           ▒
+   99,00%     0,00%  postgres  postgres           [.] subquery_planner
                                                           ▒
+   98,99%     0,00%  postgres  postgres           [.] grouping_planner
                                                           ▒
+   98,40%     0,00%  postgres  postgres           [.]
create_distinct_paths
    ▒
+   98,40%     0,00%  postgres  postgres           [.]
create_final_distinct_paths
    ▒
+   98,37%     0,00%  postgres  postgres           [.] estimate_num_groups
                                                            ▒
+   98,34%     0,06%  postgres  postgres           [.] add_unique_group_var
                                                           ▒
+   97,67%     6,65%  postgres  postgres           [.] exprs_known_equal
                                                            ▒
+   92,33%    89,05%  postgres  postgres           [.] equal
                                                            ▒
+    2,03%     1,99%  postgres  postgres           [.] _equalVar
                                                            ▒
+    1,32%     0,47%  postgres  postgres           [.] check_stack_depth
                                                            ▒
+    0,84%     0,69%  postgres  postgres           [.] stack_is_too_deep


Regards

Pavel



>
> Regards
>
> Pavel
>

Attachment: slow-plan-distinct.sql
Description: application/sql

Reply via email to