mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-13 09:57:02 +08:00
It's possible that inlining of SQL functions (or perhaps other changes?) has exposed typmod information not known at parse time. In such cases, Vars generated by query_planner might have valid typmod values while the original grouping columns only have typmod -1. This isn't a semantic problem since the behavior of grouping only depends on type not typmod, but it breaks locate_grouping_columns' use of tlist_member to locate the matching entry in query_planner's result tlist. We can fix this without an excessive amount of new code or complexity by relying on the fact that locate_grouping_columns only gets called when make_subplanTargetList has set need_tlist_eval == false, and that can only happen if all the grouping columns are simple Vars. Therefore we only need to search the sub_tlist for a matching Var, and we can reasonably define a "match" as being a match of the Var identity fields varno/varattno/varlevelsup. The code still Asserts that vartype matches, but ignores vartypmod. Per bug #8393 from Evan Martin. The added regression test case is basically the same as his example. This has been broken for a very long time, so back-patch to all supported branches.
50 lines
1.7 KiB
C
50 lines
1.7 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* tlist.h
|
|
* prototypes for tlist.c.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/optimizer/tlist.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef TLIST_H
|
|
#define TLIST_H
|
|
|
|
#include "optimizer/var.h"
|
|
|
|
|
|
extern TargetEntry *tlist_member(Node *node, List *targetlist);
|
|
extern TargetEntry *tlist_member_ignore_relabel(Node *node, List *targetlist);
|
|
extern TargetEntry *tlist_member_match_var(Var *var, List *targetlist);
|
|
|
|
extern List *flatten_tlist(List *tlist, PVCAggregateBehavior aggbehavior,
|
|
PVCPlaceHolderBehavior phbehavior);
|
|
extern List *add_to_flat_tlist(List *tlist, List *exprs);
|
|
|
|
extern List *get_tlist_exprs(List *tlist, bool includeJunk);
|
|
|
|
extern bool tlist_same_exprs(List *tlist1, List *tlist2);
|
|
|
|
extern bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK);
|
|
extern bool tlist_same_collations(List *tlist, List *colCollations, bool junkOK);
|
|
|
|
extern TargetEntry *get_sortgroupref_tle(Index sortref,
|
|
List *targetList);
|
|
extern TargetEntry *get_sortgroupclause_tle(SortGroupClause *sgClause,
|
|
List *targetList);
|
|
extern Node *get_sortgroupclause_expr(SortGroupClause *sgClause,
|
|
List *targetList);
|
|
extern List *get_sortgrouplist_exprs(List *sgClauses,
|
|
List *targetList);
|
|
|
|
extern Oid *extract_grouping_ops(List *groupClause);
|
|
extern AttrNumber *extract_grouping_cols(List *groupClause, List *tlist);
|
|
extern bool grouping_is_sortable(List *groupClause);
|
|
extern bool grouping_is_hashable(List *groupClause);
|
|
|
|
#endif /* TLIST_H */
|