diff --git a/mysql-test/r/sleep_time.result b/mysql-test/r/sleep_time.result
new file mode 100644
index 0000000..5349ab4
--- /dev/null
+++ b/mysql-test/r/sleep_time.result
@@ -0,0 +1,8 @@
+# wait for some time
+select sleep(5) as reset_time;
+reset_time
+0
+# Wait some more out of a query
+select SUM(TIME < 7) as should_be_1 from INFORMATION_SCHEMA.PROCESSLIST where ID!=CONNECTION_ID();
+should_be_1
+1
diff --git a/mysql-test/t/sleep_time.test b/mysql-test/t/sleep_time.test
new file mode 100644
index 0000000..ecbac6a
--- /dev/null
+++ b/mysql-test/t/sleep_time.test
@@ -0,0 +1,17 @@
+# 
+# Test of sleep time
+#
+
+connect(main,localhost,root,,);
+
+connection main;
+--echo # wait for some time
+select sleep(5) as reset_time;
+--echo # Wait some more out of a query
+--sleep 5
+connection default;
+
+eval select SUM(TIME < 7) as should_be_1 from INFORMATION_SCHEMA.PROCESSLIST where ID!=CONNECTION_ID();
+
+disconnect main;
+
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 8d33c56..08379c2 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -4517,6 +4517,7 @@ void THD::set_command(enum enum_server_command command)
 #ifdef HAVE_PSI_THREAD_INTERFACE
   PSI_CALL(set_thread_command)(m_command);
 #endif
+  set_time();
 }
 
 /** Assign a new value to thd->query.  */
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 3c917c9..0276dc0 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1124,7 +1124,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
   thd->enable_slow_log= TRUE;
   thd->query_plan_flags= QPLAN_INIT;
   thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
-  thd->set_time();
   thd->set_query_id(get_query_id());
   if (!(server_command_flags[command] & CF_SKIP_QUERY_ID))
     next_query_id();
