Introduce an RTE for the grouping step

247dea89f7616fdf06b7272b74abafc29e8e5860
m3hm3t/pg18_dev_relation_oid_0
Mehmet Yilmaz 2025-06-17 12:06:04 +00:00
parent 8383666109
commit 8db2f4144b
1 changed files with 18 additions and 1 deletions

View File

@ -2218,11 +2218,28 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
{ {
deparse_context context; deparse_context context;
deparse_namespace dpns; deparse_namespace dpns;
int rtable_size;
/* Guard against excessively long or deeply-nested queries */ /* Guard against excessively long or deeply-nested queries */
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
check_stack_depth(); check_stack_depth();
rtable_size = query->hasGroupRTE ?
list_length(query->rtable) - 1 :
list_length(query->rtable);
/*
* Replace any Vars in the query's targetlist and havingQual that
* reference GROUP outputs with the underlying grouping expressions.
*/
if (query->hasGroupRTE)
{
query->targetList = (List *)
flatten_group_exprs(NULL, query, (Node *) query->targetList);
query->havingQual =
flatten_group_exprs(NULL, query, query->havingQual);
}
/* /*
* Before we begin to examine the query, acquire locks on referenced * Before we begin to examine the query, acquire locks on referenced
* relations, and fix up deleted columns in JOIN RTEs. This ensures * relations, and fix up deleted columns in JOIN RTEs. This ensures
@ -2247,7 +2264,7 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
context.targetList = NIL; context.targetList = NIL;
context.windowClause = NIL; context.windowClause = NIL;
context.varprefix = (parentnamespace != NIL || context.varprefix = (parentnamespace != NIL ||
list_length(query->rtable) != 1); rtable_size != 1);
context.prettyFlags = prettyFlags; context.prettyFlags = prettyFlags;
context.wrapColumn = wrapColumn; context.wrapColumn = wrapColumn;
context.indentLevel = startIndent; context.indentLevel = startIndent;