Commit aebeb479 authored by Tom Lane's avatar Tom Lane

Remove vestigial resolveUnknown arguments from transformSortClause etc.

There's really no situation where we don't want these unknown-to-text
conversions to happen.  The alternative is failure anyway, and the one
caller that was passing "false" did so only because it expected the
case could not arise.  Might as well simplify the code.

Discussion: https://postgr.es/m/CAH2L28uwwbL9HUM-WR=hromW1Cvamkn7O-g8fPY2m=_7muJ0oA@mail.gmail.com
parent 87ecf2d1
...@@ -1232,7 +1232,6 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt) ...@@ -1232,7 +1232,6 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
stmt->sortClause, stmt->sortClause,
&qry->targetList, &qry->targetList,
EXPR_KIND_ORDER_BY, EXPR_KIND_ORDER_BY,
true /* fix unknowns */ ,
false /* allow SQL92 rules */ ); false /* allow SQL92 rules */ );
qry->groupClause = transformGroupClause(pstate, qry->groupClause = transformGroupClause(pstate,
...@@ -1512,7 +1511,6 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt) ...@@ -1512,7 +1511,6 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
stmt->sortClause, stmt->sortClause,
&qry->targetList, &qry->targetList,
EXPR_KIND_ORDER_BY, EXPR_KIND_ORDER_BY,
true /* fix unknowns */ ,
false /* allow SQL92 rules */ ); false /* allow SQL92 rules */ );
qry->limitOffset = transformLimitClause(pstate, stmt->limitOffset, qry->limitOffset = transformLimitClause(pstate, stmt->limitOffset,
...@@ -1736,7 +1734,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt) ...@@ -1736,7 +1734,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
sortClause, sortClause,
&qry->targetList, &qry->targetList,
EXPR_KIND_ORDER_BY, EXPR_KIND_ORDER_BY,
false /* no unknowns expected */ ,
false /* allow SQL92 rules */ ); false /* allow SQL92 rules */ );
/* restore namespace, remove jrte from rtable */ /* restore namespace, remove jrte from rtable */
......
...@@ -155,8 +155,7 @@ transformAggregateCall(ParseState *pstate, Aggref *agg, ...@@ -155,8 +155,7 @@ transformAggregateCall(ParseState *pstate, Aggref *agg,
tlist = lappend(tlist, tle); tlist = lappend(tlist, tle);
torder = addTargetToSortList(pstate, tle, torder = addTargetToSortList(pstate, tle,
torder, tlist, sortby, torder, tlist, sortby);
true /* fix unknowns */ );
} }
/* Never any DISTINCT in an ordered-set agg */ /* Never any DISTINCT in an ordered-set agg */
...@@ -196,7 +195,6 @@ transformAggregateCall(ParseState *pstate, Aggref *agg, ...@@ -196,7 +195,6 @@ transformAggregateCall(ParseState *pstate, Aggref *agg,
aggorder, aggorder,
&tlist, &tlist,
EXPR_KIND_ORDER_BY, EXPR_KIND_ORDER_BY,
true /* fix unknowns */ ,
true /* force SQL99 rules */ ); true /* force SQL99 rules */ );
/* /*
......
...@@ -89,8 +89,7 @@ static int get_matching_location(int sortgroupref, ...@@ -89,8 +89,7 @@ static int get_matching_location(int sortgroupref,
static List *resolve_unique_index_expr(ParseState *pstate, InferClause *infer, static List *resolve_unique_index_expr(ParseState *pstate, InferClause *infer,
Relation heapRel); Relation heapRel);
static List *addTargetToGroupList(ParseState *pstate, TargetEntry *tle, static List *addTargetToGroupList(ParseState *pstate, TargetEntry *tle,
List *grouplist, List *targetlist, int location, List *grouplist, List *targetlist, int location);
bool resolveUnknown);
static WindowClause *findWindowClause(List *wclist, const char *name); static WindowClause *findWindowClause(List *wclist, const char *name);
static Node *transformFrameOffset(ParseState *pstate, int frameOptions, static Node *transformFrameOffset(ParseState *pstate, int frameOptions,
Node *clause); Node *clause);
...@@ -2011,8 +2010,7 @@ transformGroupClauseExpr(List **flatresult, Bitmapset *seen_local, ...@@ -2011,8 +2010,7 @@ transformGroupClauseExpr(List **flatresult, Bitmapset *seen_local,
if (!found) if (!found)
*flatresult = addTargetToGroupList(pstate, tle, *flatresult = addTargetToGroupList(pstate, tle,
*flatresult, *targetlist, *flatresult, *targetlist,
exprLocation(gexpr), exprLocation(gexpr));
true);
/* /*
* _something_ must have assigned us a sortgroupref by now... * _something_ must have assigned us a sortgroupref by now...
...@@ -2300,7 +2298,6 @@ transformSortClause(ParseState *pstate, ...@@ -2300,7 +2298,6 @@ transformSortClause(ParseState *pstate,
List *orderlist, List *orderlist,
List **targetlist, List **targetlist,
ParseExprKind exprKind, ParseExprKind exprKind,
bool resolveUnknown,
bool useSQL99) bool useSQL99)
{ {
List *sortlist = NIL; List *sortlist = NIL;
...@@ -2319,8 +2316,7 @@ transformSortClause(ParseState *pstate, ...@@ -2319,8 +2316,7 @@ transformSortClause(ParseState *pstate,
targetlist, exprKind); targetlist, exprKind);
sortlist = addTargetToSortList(pstate, tle, sortlist = addTargetToSortList(pstate, tle,
sortlist, *targetlist, sortby, sortlist, *targetlist, sortby);
resolveUnknown);
} }
return sortlist; return sortlist;
...@@ -2382,7 +2378,6 @@ transformWindowDefinitions(ParseState *pstate, ...@@ -2382,7 +2378,6 @@ transformWindowDefinitions(ParseState *pstate,
windef->orderClause, windef->orderClause,
targetlist, targetlist,
EXPR_KIND_WINDOW_ORDER, EXPR_KIND_WINDOW_ORDER,
true /* fix unknowns */ ,
true /* force SQL99 rules */ ); true /* force SQL99 rules */ );
partitionClause = transformGroupClause(pstate, partitionClause = transformGroupClause(pstate,
windef->partitionClause, windef->partitionClause,
...@@ -2553,8 +2548,7 @@ transformDistinctClause(ParseState *pstate, ...@@ -2553,8 +2548,7 @@ transformDistinctClause(ParseState *pstate,
continue; /* ignore junk */ continue; /* ignore junk */
result = addTargetToGroupList(pstate, tle, result = addTargetToGroupList(pstate, tle,
result, *targetlist, result, *targetlist,
exprLocation((Node *) tle->expr), exprLocation((Node *) tle->expr));
true);
} }
/* /*
...@@ -2671,8 +2665,7 @@ transformDistinctOnClause(ParseState *pstate, List *distinctlist, ...@@ -2671,8 +2665,7 @@ transformDistinctOnClause(ParseState *pstate, List *distinctlist,
parser_errposition(pstate, exprLocation(dexpr)))); parser_errposition(pstate, exprLocation(dexpr))));
result = addTargetToGroupList(pstate, tle, result = addTargetToGroupList(pstate, tle,
result, *targetlist, result, *targetlist,
exprLocation(dexpr), exprLocation(dexpr));
true);
} }
/* /*
...@@ -2906,17 +2899,11 @@ transformOnConflictArbiter(ParseState *pstate, ...@@ -2906,17 +2899,11 @@ transformOnConflictArbiter(ParseState *pstate,
* list, add it to the end of the list, using the given sort ordering * list, add it to the end of the list, using the given sort ordering
* info. * info.
* *
* If resolveUnknown is TRUE, convert TLEs of type UNKNOWN to TEXT. If not,
* do nothing (which implies the search for a sort operator will fail).
* pstate should be provided if resolveUnknown is TRUE, but can be NULL
* otherwise.
*
* Returns the updated SortGroupClause list. * Returns the updated SortGroupClause list.
*/ */
List * List *
addTargetToSortList(ParseState *pstate, TargetEntry *tle, addTargetToSortList(ParseState *pstate, TargetEntry *tle,
List *sortlist, List *targetlist, SortBy *sortby, List *sortlist, List *targetlist, SortBy *sortby)
bool resolveUnknown)
{ {
Oid restype = exprType((Node *) tle->expr); Oid restype = exprType((Node *) tle->expr);
Oid sortop; Oid sortop;
...@@ -2927,7 +2914,7 @@ addTargetToSortList(ParseState *pstate, TargetEntry *tle, ...@@ -2927,7 +2914,7 @@ addTargetToSortList(ParseState *pstate, TargetEntry *tle,
ParseCallbackState pcbstate; ParseCallbackState pcbstate;
/* if tlist item is an UNKNOWN literal, change it to TEXT */ /* if tlist item is an UNKNOWN literal, change it to TEXT */
if (restype == UNKNOWNOID && resolveUnknown) if (restype == UNKNOWNOID)
{ {
tle->expr = (Expr *) coerce_type(pstate, (Node *) tle->expr, tle->expr = (Expr *) coerce_type(pstate, (Node *) tle->expr,
restype, TEXTOID, -1, restype, TEXTOID, -1,
...@@ -3055,22 +3042,16 @@ addTargetToSortList(ParseState *pstate, TargetEntry *tle, ...@@ -3055,22 +3042,16 @@ addTargetToSortList(ParseState *pstate, TargetEntry *tle,
* to a SELECT item that matches the GROUP BY item; it'd be pretty confusing * to a SELECT item that matches the GROUP BY item; it'd be pretty confusing
* to report such a location. * to report such a location.
* *
* If resolveUnknown is TRUE, convert TLEs of type UNKNOWN to TEXT. If not,
* do nothing (which implies the search for an equality operator will fail).
* pstate should be provided if resolveUnknown is TRUE, but can be NULL
* otherwise.
*
* Returns the updated SortGroupClause list. * Returns the updated SortGroupClause list.
*/ */
static List * static List *
addTargetToGroupList(ParseState *pstate, TargetEntry *tle, addTargetToGroupList(ParseState *pstate, TargetEntry *tle,
List *grouplist, List *targetlist, int location, List *grouplist, List *targetlist, int location)
bool resolveUnknown)
{ {
Oid restype = exprType((Node *) tle->expr); Oid restype = exprType((Node *) tle->expr);
/* if tlist item is an UNKNOWN literal, change it to TEXT */ /* if tlist item is an UNKNOWN literal, change it to TEXT */
if (restype == UNKNOWNOID && resolveUnknown) if (restype == UNKNOWNOID)
{ {
tle->expr = (Expr *) coerce_type(pstate, (Node *) tle->expr, tle->expr = (Expr *) coerce_type(pstate, (Node *) tle->expr,
restype, TEXTOID, -1, restype, TEXTOID, -1,
......
...@@ -31,7 +31,7 @@ extern List *transformGroupClause(ParseState *pstate, List *grouplist, ...@@ -31,7 +31,7 @@ extern List *transformGroupClause(ParseState *pstate, List *grouplist,
ParseExprKind exprKind, bool useSQL99); ParseExprKind exprKind, bool useSQL99);
extern List *transformSortClause(ParseState *pstate, List *orderlist, extern List *transformSortClause(ParseState *pstate, List *orderlist,
List **targetlist, ParseExprKind exprKind, List **targetlist, ParseExprKind exprKind,
bool resolveUnknown, bool useSQL99); bool useSQL99);
extern List *transformWindowDefinitions(ParseState *pstate, extern List *transformWindowDefinitions(ParseState *pstate,
List *windowdefs, List *windowdefs,
...@@ -47,8 +47,7 @@ extern void transformOnConflictArbiter(ParseState *pstate, ...@@ -47,8 +47,7 @@ extern void transformOnConflictArbiter(ParseState *pstate,
Oid *constraint); Oid *constraint);
extern List *addTargetToSortList(ParseState *pstate, TargetEntry *tle, extern List *addTargetToSortList(ParseState *pstate, TargetEntry *tle,
List *sortlist, List *targetlist, SortBy *sortby, List *sortlist, List *targetlist, SortBy *sortby);
bool resolveUnknown);
extern Index assignSortGroupRef(TargetEntry *tle, List *tlist); extern Index assignSortGroupRef(TargetEntry *tle, List *tlist);
extern bool targetIsInSortList(TargetEntry *tle, Oid sortop, List *sortList); extern bool targetIsInSortList(TargetEntry *tle, Oid sortop, List *sortList);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment