1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-29 13:56:47 +03:00

Enable WRITE_READ_PARSE_PLAN_TREES of rewritten utility statements

This was previously disabled because we lacked outfuncs/readfuncs
support for most utility statement types.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/4159834.1657405226@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2022-09-26 16:32:16 +02:00 committed by Peter Eisentraut
parent 40ad8f9dee
commit 787102b563

View File

@ -801,7 +801,7 @@ pg_rewrite_query(Query *query)
new_list = copyObject(querytree_list); new_list = copyObject(querytree_list);
/* This checks both copyObject() and the equal() routines... */ /* This checks both copyObject() and the equal() routines... */
if (!equal(new_list, querytree_list)) if (!equal(new_list, querytree_list))
elog(WARNING, "copyObject() failed to produce equal parse tree"); elog(WARNING, "copyObject() failed to produce an equal rewritten parse tree");
else else
querytree_list = new_list; querytree_list = new_list;
} }
@ -813,35 +813,25 @@ pg_rewrite_query(Query *query)
List *new_list = NIL; List *new_list = NIL;
ListCell *lc; ListCell *lc;
/*
* We currently lack outfuncs/readfuncs support for most utility
* statement types, so only attempt to write/read non-utility queries.
*/
foreach(lc, querytree_list) foreach(lc, querytree_list)
{ {
Query *query = lfirst_node(Query, lc); Query *query = lfirst_node(Query, lc);
if (query->commandType != CMD_UTILITY)
{
char *str = nodeToString(query); char *str = nodeToString(query);
Query *new_query = stringToNodeWithLocations(str); Query *new_query = stringToNodeWithLocations(str);
/* /*
* queryId is not saved in stored rules, but we must preserve * queryId is not saved in stored rules, but we must preserve it
* it here to avoid breaking pg_stat_statements. * here to avoid breaking pg_stat_statements.
*/ */
new_query->queryId = query->queryId; new_query->queryId = query->queryId;
new_list = lappend(new_list, new_query); new_list = lappend(new_list, new_query);
pfree(str); pfree(str);
} }
else
new_list = lappend(new_list, query);
}
/* This checks both outfuncs/readfuncs and the equal() routines... */ /* This checks both outfuncs/readfuncs and the equal() routines... */
if (!equal(new_list, querytree_list)) if (!equal(new_list, querytree_list))
elog(WARNING, "outfuncs/readfuncs failed to produce equal parse tree"); elog(WARNING, "outfuncs/readfuncs failed to produce an equal rewritten parse tree");
else else
querytree_list = new_list; querytree_list = new_list;
} }