From d723f89f73a63b7a0b7e169f786f5c39db4aa4a2 Mon Sep 17 00:00:00 2001 From: liuly Date: Tue, 10 Aug 2021 09:35:23 +0000 Subject: [PATCH] Fix issue: Fix bugs on the index advisor: handle combined scenario of 'order' and '*' in single query index advisor --- .../dbmind/kernel/index_advisor.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/gausskernel/dbmind/kernel/index_advisor.cpp b/src/gausskernel/dbmind/kernel/index_advisor.cpp index 6e09ce67d..8b49479da 100644 --- a/src/gausskernel/dbmind/kernel/index_advisor.cpp +++ b/src/gausskernel/dbmind/kernel/index_advisor.cpp @@ -1467,6 +1467,27 @@ char *parse_group_clause(List *group_clause, List *target_list) return NULL; } + +bool has_star(List *targetList) +{ + ListCell* target_cell = NULL; + foreach (target_cell, targetList) { + ResTarget* restarget = (ResTarget *)lfirst(target_cell); + if (nodeTag((Node *)restarget->val) == T_ColumnRef) { + ColumnRef* cref = NULL; + cref = (ColumnRef *)restarget->val; + ListCell* field = NULL; + foreach (field, cref->fields) { + if (nodeTag((Node *)lfirst(field)) == T_A_Star) { + return true; + } + } + } + } + return false; +} + + char *parse_order_clause(List *order_clause, List *target_list) { if (order_clause == NULL) @@ -1482,6 +1503,9 @@ char *parse_order_clause(List *order_clause, List *target_list) SortByDir dir = ((SortBy *)(lfirst(order_item)))->sortby_dir; if (nodeTag(node) == T_A_Const) { + if (has_star(target_list)) { + return NULL; + } node = transform_group_order_node(node, target_list); } if (nodeTag(node) != T_ColumnRef)