* exec_parse_message * * Execute a "Parse" protocol message. */
| 2061 | * Execute a "Parse" protocol message. |
| 2062 | */ |
| 2063 | static void |
| 2064 | exec_parse_message(const char *query_string, /* string to execute */ |
| 2065 | const char *stmt_name, /* name for prepared stmt */ |
| 2066 | Oid *paramTypes, /* parameter types */ |
| 2067 | int numParams) /* number of parameters */ |
| 2068 | { |
| 2069 | MemoryContext unnamed_stmt_context = NULL; |
| 2070 | MemoryContext oldcontext; |
| 2071 | List *parsetree_list; |
| 2072 | RawStmt *raw_parse_tree; |
| 2073 | List *querytree_list; |
| 2074 | CachedPlanSource *psrc; |
| 2075 | bool is_named; |
| 2076 | bool save_log_statement_stats = log_statement_stats; |
| 2077 | char msec_str[32]; |
| 2078 | NodeTag sourceTag = T_Query; |
| 2079 | |
| 2080 | /* |
| 2081 | * Report query to various monitoring facilities. |
| 2082 | */ |
| 2083 | debug_query_string = query_string; |
| 2084 | |
| 2085 | pgstat_report_activity(STATE_RUNNING, query_string); |
| 2086 | |
| 2087 | set_ps_display("PARSE"); |
| 2088 | |
| 2089 | if (save_log_statement_stats) |
| 2090 | ResetUsage(); |
| 2091 | |
| 2092 | ereport(DEBUG2, |
| 2093 | (errmsg_internal("parse %s: %s", |
| 2094 | *stmt_name ? stmt_name : "<unnamed>", |
| 2095 | query_string))); |
| 2096 | |
| 2097 | /* |
| 2098 | * Start up a transaction command so we can run parse analysis etc. (Note |
| 2099 | * that this will normally change current memory context.) Nothing happens |
| 2100 | * if we are already in one. This also arms the statement timeout if |
| 2101 | * necessary. |
| 2102 | */ |
| 2103 | start_xact_command(); |
| 2104 | |
| 2105 | /* |
| 2106 | * Switch to appropriate context for constructing parsetrees. |
| 2107 | * |
| 2108 | * We have two strategies depending on whether the prepared statement is |
| 2109 | * named or not. For a named prepared statement, we do parsing in |
| 2110 | * MessageContext and copy the finished trees into the prepared |
| 2111 | * statement's plancache entry; then the reset of MessageContext releases |
| 2112 | * temporary space used by parsing and rewriting. For an unnamed prepared |
| 2113 | * statement, we assume the statement isn't going to hang around long, so |
| 2114 | * getting rid of temp space quickly is probably not worth the costs of |
| 2115 | * copying parse trees. So in this case, we create the plancache entry's |
| 2116 | * query_context here, and do all the parsing work therein. |
| 2117 | */ |
| 2118 | is_named = (stmt_name[0] != '\0'); |
| 2119 | if (is_named) |
| 2120 | { |
no test coverage detected