pgsql: Optimize generate_orderedappend_paths

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Optimize generate_orderedappend_paths
Date: 2023-02-20 09:50:48
Message-ID: E1pU2op-00246F-Um@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Optimize generate_orderedappend_paths

In generate_orderedappend_paths(), when match_partition_order_desc was
true, we would lcons() items to various lists in a loop over each live
partition. When the number of live partitions was large, the lcons()
could show up in profiles due to it having to perform memmove() to make
way for the new list item.

Here we adjust things so that we just perform the loop over the live
partitions backwards when match_partition_order_desc is true. This allows
us to simplify the logic in the loop. Now, as far as the guts of the loop
knows, there's no difference between match_partition_order and
match_partition_order_desc. We can just set match_partition_order to true
so that we build the correct list of paths for the asc and desc case. Per
idea from Andres Freund.

Discussion: https://postgr.es/m/20230217002351.nyt4y5tdzg6hugdt@awork3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/94cad7a3e6040e23d51b9d4869fc20e3e56ddbf7

Modified Files
--------------
src/backend/optimizer/path/allpaths.c | 57 +++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 23 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alvaro Herrera 2023-02-20 15:15:20 pgsql: Correctly set userid of subquery relations' child rels
Previous Message John Naylor 2023-02-20 08:00:51 pgsql: Add MSVC support for pg_leftmost_one_pos32() and friends