bool error;
bool use_minimal;
+/*
+ * If query string is shorter than this, we do not run
+ * multi_statement_query() to avoid its overhead.
+ */
+#define LENGTHY_QUERY_STRING 1024*10
+
/* Get session context */
session_context = pool_get_session_context(false);
query_context = pool_init_query_context();
MemoryContext old_context = MemoryContextSwitchTo(query_context->memory_context);
- /*
- * Check whether the query is multi statement or not.
- */
- if (multi_statement_query(contents))
- {
- elog(DEBUG5, "multi statement query found");
- query_context->is_multi_statement = true;
- use_minimal = false; /* never use minimal parser */
- }
- else
+ /* Is query string long? */
+ if (len > LENGTHY_QUERY_STRING)
{
- query_context->is_multi_statement = false;
/*
- * Do not use minimal parser if we are in native replication or
- * snapshot isolation mode.
+ * Check whether the query is multi statement or not.
*/
- if (REPLICATION)
- use_minimal = false;
+ if (multi_statement_query(contents))
+ {
+ elog(DEBUG5, "multi statement query found");
+ query_context->is_multi_statement = true;
+ use_minimal = false; /* never use minimal parser */
+ }
else
- use_minimal = true;
+ {
+ query_context->is_multi_statement = false;
+ /*
+ * Do not use minimal parser if we are in native replication or
+ * snapshot isolation mode.
+ */
+ if (REPLICATION)
+ use_minimal = false;
+ else
+ use_minimal = true;
+ }
+ }
+ else
+ {
+ use_minimal = false;
}
- /* parse SQL string */
+ /* Parse SQL string */
parse_tree_list = raw_parser(contents, RAW_PARSE_DEFAULT, len, &error, use_minimal);
+ if (len <= LENGTHY_QUERY_STRING)
+ {
+ /* we have not checked whether multi-statement query or not */
+ if (list_length(parse_tree_list) > 1)
+ query_context->is_multi_statement = true;
+ else
+ query_context->is_multi_statement = false;
+ }
+
if (parse_tree_list == NIL)
{
/* is the query empty? */