/*
* pathkeys_are_duplicate
* Check if give pathkeys are already contained the list of
- * PathKeyInfo's.
+ * GroupByOrdering's.
*/
static bool
pathkeys_are_duplicate(List *infos, List *pathkeys)
foreach(lc, infos)
{
- PathKeyInfo *info = lfirst_node(PathKeyInfo, lc);
+ GroupByOrdering *info = lfirst_node(GroupByOrdering, lc);
if (compare_pathkeys(pathkeys, info->pathkeys) == PATHKEYS_EQUAL)
return true;
* get_useful_group_keys_orderings
* Determine which orderings of GROUP BY keys are potentially interesting.
*
- * Returns a list of PathKeyInfo items, each representing an interesting
+ * Returns a list of GroupByOrdering items, each representing an interesting
* ordering of GROUP BY keys. Each item stores pathkeys and clauses in the
* matching order.
*
{
Query *parse = root->parse;
List *infos = NIL;
- PathKeyInfo *info;
+ GroupByOrdering *info;
List *pathkeys = root->group_pathkeys;
List *clauses = root->processed_groupClause;
/* always return at least the original pathkeys/clauses */
- info = makeNode(PathKeyInfo);
+ info = makeNode(GroupByOrdering);
info->pathkeys = pathkeys;
info->clauses = clauses;
infos = lappend(infos, info);
(enable_incremental_sort || n == root->num_groupby_pathkeys) &&
!pathkeys_are_duplicate(infos, pathkeys))
{
- info = makeNode(PathKeyInfo);
+ info = makeNode(GroupByOrdering);
info->pathkeys = pathkeys;
info->clauses = clauses;
(enable_incremental_sort || n == list_length(root->sort_pathkeys)) &&
!pathkeys_are_duplicate(infos, pathkeys))
{
- info = makeNode(PathKeyInfo);
+ info = makeNode(GroupByOrdering);
info->pathkeys = pathkeys;
info->clauses = clauses;
#ifdef USE_ASSERT_CHECKING
{
- PathKeyInfo *pinfo = linitial_node(PathKeyInfo, infos);
+ GroupByOrdering *pinfo = linitial_node(GroupByOrdering, infos);
ListCell *lc;
/* Test consistency of info structures */
ListCell *lc1,
*lc2;
- info = lfirst_node(PathKeyInfo, lc);
+ info = lfirst_node(GroupByOrdering, lc);
Assert(list_length(info->clauses) == list_length(pinfo->clauses));
Assert(list_length(info->pathkeys) == list_length(pinfo->pathkeys));
foreach(lc2, pathkey_orderings)
{
- PathKeyInfo *info = (PathKeyInfo *) lfirst(lc2);
+ GroupByOrdering *info = (GroupByOrdering *) lfirst(lc2);
/* restore the path (we replace it in the loop) */
path = path_save;
/* process all potentially interesting grouping reorderings */
foreach(lc2, pathkey_orderings)
{
- PathKeyInfo *info = (PathKeyInfo *) lfirst(lc2);
+ GroupByOrdering *info = (GroupByOrdering *) lfirst(lc2);
/* restore the path (we replace it in the loop) */
path = path_save;
/* process all potentially interesting grouping reorderings */
foreach(lc2, pathkey_orderings)
{
- PathKeyInfo *info = (PathKeyInfo *) lfirst(lc2);
+ GroupByOrdering *info = (GroupByOrdering *) lfirst(lc2);
/* restore the path (we replace it in the loop) */
path = path_save;
/* process all potentially interesting grouping reorderings */
foreach(lc2, pathkey_orderings)
{
- PathKeyInfo *info = (PathKeyInfo *) lfirst(lc2);
+ GroupByOrdering *info = (GroupByOrdering *) lfirst(lc2);
/* restore the path (we replace it in the loop) */
} PathKey;
/*
- * Combines the information about pathkeys and the associated clauses.
+ * Contains an order of group-by clauses and the corresponding list of
+ * pathkeys.
+ *
+ * The elements of 'clauses' list should have the same order as the head of
+ * 'pathkeys' list. The tleSortGroupRef of the clause should be equal to
+ * ec_sortref of the pathkey equivalence class. If there are redundant
+ * clauses with the same tleSortGroupRef, they must be grouped together.
*/
-typedef struct PathKeyInfo
+typedef struct GroupByOrdering
{
NodeTag type;
+
List *pathkeys;
List *clauses;
-} PathKeyInfo;
+} GroupByOrdering;
/*
* VolatileFunctionStatus -- allows nodes to cache their