From 9b7cb831ed10a37b560761b1b796fed86f5a4990 Mon Sep 17 00:00:00 2001 From: Jan Nidzwetzki Date: Sat, 4 Nov 2023 23:33:44 +0100 Subject: [PATCH] Simplified aggregation type detection logic a094f175eb7c98173c78f557880ccd2d89b791f8 changes the contains_path_plain_or_sorted_agg function. However, a return statement is missing to properly return the result of subpaths. This pull request addresses the logic issues and simplifies the check. --- src/planner/partialize.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/planner/partialize.c b/src/planner/partialize.c index e53f8f48d83..c0cd9b2ee26 100644 --- a/src/planner/partialize.c +++ b/src/planner/partialize.c @@ -660,7 +660,7 @@ get_best_total_path(RelOptInfo *output_rel) /* Is the provided path a agg path that uses a sorted or plain agg strategy? */ -static bool +static bool pg_nodiscard is_path_sorted_or_plain_agg_path(Path *path) { AggPath *agg_path = castNode(AggPath, path); @@ -686,21 +686,25 @@ contains_path_plain_or_sorted_agg(Path *path) if (IsA(subpath, AggPath)) return is_path_sorted_or_plain_agg_path(subpath); - - List *subsubpaths = get_subpaths_from_append_path(path, true); - - ListCell *lc2; - foreach (lc2, subsubpaths) - { - Path *subsubpath = lfirst(lc2); - - if (IsA(subsubpath, AggPath)) - is_path_sorted_or_plain_agg_path(subsubpath); - } } - /* No dedicated aggregation nodes found (e.g., only vectorized aggregation is used). The sorted - * finalizer is used in that case to finalize the aggregation. */ + /* + * No dedicated aggregation nodes found directly underneath the append node. This could be + * due to two reasons. + * + * (1) Only vectorized aggregation is used and we don't have dedicated Aggregation nods. + * (2) The query plan uses multi-level appends to keep a certain sorting + * - ChunkAppend + * - Merge Append + * - Agg Chunk 1 + * - Agg Chunk 2 + * - Merge Append + * - Agg Chunk 3 + * - Agg Chunk 4 + * + * in both cases, we use a sorted aggregation node to finalize the partial aggregation and + * produce a proper sorting. + */ return true; }