* Generate a plan for a single already-rewritten query. * This is a thin wrapper around planner() and takes the same parameters. */
| 974 | * This is a thin wrapper around planner() and takes the same parameters. |
| 975 | */ |
| 976 | PlannedStmt * |
| 977 | pg_plan_query(Query *querytree, const char *query_string, int cursorOptions, |
| 978 | ParamListInfo boundParams) |
| 979 | { |
| 980 | PlannedStmt *plan; |
| 981 | |
| 982 | /* Utility commands have no plans. */ |
| 983 | if (querytree->commandType == CMD_UTILITY) |
| 984 | return NULL; |
| 985 | |
| 986 | /* Planner must have a snapshot in case it calls user-defined functions. */ |
| 987 | Assert(ActiveSnapshotSet()); |
| 988 | |
| 989 | TRACE_POSTGRESQL_QUERY_PLAN_START(); |
| 990 | |
| 991 | if (log_planner_stats) |
| 992 | ResetUsage(); |
| 993 | |
| 994 | /* call the optimizer */ |
| 995 | plan = planner(querytree, query_string, cursorOptions, boundParams); |
| 996 | |
| 997 | if (log_planner_stats) |
| 998 | ShowUsage("PLANNER STATISTICS"); |
| 999 | |
| 1000 | #ifdef COPY_PARSE_PLAN_TREES |
| 1001 | /* Optional debugging check: pass plan tree through copyObject() */ |
| 1002 | { |
| 1003 | PlannedStmt *new_plan = copyObject(plan); |
| 1004 | |
| 1005 | /* |
| 1006 | * equal() currently does not have routines to compare Plan nodes, so |
| 1007 | * don't try to test equality here. Perhaps fix someday? |
| 1008 | */ |
| 1009 | #ifdef NOT_USED |
| 1010 | /* This checks both copyObject() and the equal() routines... */ |
| 1011 | if (!equal(new_plan, plan)) |
| 1012 | elog(WARNING, "copyObject() failed to produce an equal plan tree"); |
| 1013 | else |
| 1014 | #endif |
| 1015 | plan = new_plan; |
| 1016 | } |
| 1017 | #endif |
| 1018 | |
| 1019 | #ifdef WRITE_READ_PARSE_PLAN_TREES |
| 1020 | /* Optional debugging check: pass plan tree through outfuncs/readfuncs */ |
| 1021 | { |
| 1022 | char *str; |
| 1023 | PlannedStmt *new_plan; |
| 1024 | |
| 1025 | str = nodeToString(plan); |
| 1026 | new_plan = stringToNodeWithLocations(str); |
| 1027 | pfree(str); |
| 1028 | |
| 1029 | /* |
| 1030 | * equal() currently does not have routines to compare Plan nodes, so |
| 1031 | * don't try to test equality here. Perhaps fix someday? |
| 1032 | */ |
| 1033 | #ifdef NOT_USED |
no test coverage detected