James William Pye
After browsing the code a bit more, I realize that the above suggestion is superior to my own. It doesn't require a memory allocation and it's very close to what I'd like to have. I'd like it a bit more generic to allow arbitrary perusal of Query attributes. Like this to be more precise:bool (*SPI_UtilityFilter) (NodeTag aStmt); To a "void SPI_FilterUtilities(void *execPlan, SPI_UtilityFilter fp)".
Throwing an error if deemed necessary by the pointed to function.
typedef bool (*QueryVisitor)(Query* query, void *clientData);
bool
SPI_traverse_query_roots(void *plan, QueryVisitor queryVisitor, void* clientData)
{
List *query_list_list = ((_SPI_plan*)plan)->qtlist;
ListCell *query_list_list_item;
foreach(query_list_list_item, query_list_list)
{
List *query_list = lfirst(query_list_list_item);
ListCell *query_list_item; foreach(query_list_item, query_list)
{
if(!queryVisitor((Query *)lfirst(query_list_item), clientData))
return false;
}
}
return true;
}This will allow me to implement a QueryVisitor like so:
static bool detectTransactCommands(Query* query, void* clientData)
{
return !(query->commandType == CMD_UTILITY &&
IsA(query->utilityStmt, TransactionStmt));
}and then test using:
if(!SPI_traverse_query_roots(myPlan, detectTransactCommands, null)) /* Handle error here */
Any chance a patch containing the SPI_traverse_query_roots would be accepted?
Regards, Thomas Hallgren
---------------------------(end of broadcast)--------------------------- TIP 8: explain analyze is your friend
