From 5626ec5733ee6d33ddbd4c02ff3788a79098b27b Mon Sep 17 00:00:00 2001
From: "cmiller@zippy.cornsilk.net" <>
Date: Fri, 9 Nov 2007 20:29:02 -0500
Subject: [PATCH] Don't start profiling too soon.  Begin timing when the packet
 is read.

Do not store profiling information when there is no query text.  We
don't wish to capture non-COM_QUERY packets.
---
 sql/sql_parse.cc   | 10 ++++++----
 sql/sql_profile.cc |  1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 53835cce7df..aa4456f0f4e 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -668,9 +668,6 @@ bool do_command(THD *thd)
   enum enum_server_command command;
   DBUG_ENTER("do_command");
 
-#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
-  thd->profiling.start_new_query();
-#endif
   /*
     indicator of uninitialized lex => normal flow of errors handling
     (see my_message_sql)
@@ -688,7 +685,12 @@ bool do_command(THD *thd)
   thd->clear_error();				// Clear error message
 
   net_new_transaction(net);
-  if ((packet_length=my_net_read(net)) == packet_error)
+
+  packet_length= my_net_read(net);
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+  thd->profiling.start_new_query();
+#endif
+  if (packet_length == packet_error)
   {
     DBUG_PRINT("info",("Got error %d reading command from socket %s",
 		       net->error,
diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc
index 5b6e0187a92..fd2ae32c711 100644
--- a/sql/sql_profile.cc
+++ b/sql/sql_profile.cc
@@ -378,6 +378,7 @@ void PROFILING::finish_current_query()
 
     if ((enabled) &&                                    /* ON at start? */
         ((thd->options & OPTION_PROFILING) != 0) &&   /* and ON at end? */
+        (current->query_source != NULL) &&
         (! current->entries.is_empty()))
     {
       current->profiling_query_id= next_profile_id();   /* assign an id */
-- 
2.30.9