summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2020-02-14 16:59:52 +0100
committerSergei Golubchik <serg@mariadb.org>2020-03-10 19:24:23 +0100
commit00819d8116a4613a30ca72ed999ec387595a1783 (patch)
tree48f09358f265b75ac2690adfd1b055f030c99a59
parent05779bc6f1a585156c572fbcd89c78b3b1f51f5d (diff)
downloadmariadb-git-00819d8116a4613a30ca72ed999ec387595a1783.tar.gz
perfschema ps instrumentation related changes
-rw-r--r--sql/sql_prepare.cc37
1 files changed, 32 insertions, 5 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index d0f2ca512cc..8f182b66ce0 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -122,6 +122,7 @@ When one supplies long data for a placeholder:
#include "lock.h" // MYSQL_OPEN_FORCE_SHARED_MDL
#include "sql_handler.h"
#include "transaction.h" // trans_rollback_implicit
+#include "mysql/psi/mysql_ps.h" // MYSQL_EXECUTE_PS
#include "wsrep_mysqld.h"
/**
@@ -160,6 +161,7 @@ public:
};
THD *thd;
+ PSI_prepared_stmt* m_prepared_stmt;
Select_fetch_protocol_binary result;
Item_param **param_array;
Server_side_cursor *cursor;
@@ -2664,6 +2666,12 @@ void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length)
thd->protocol= &thd->protocol_binary;
+ /* Create PS table entry, set query text after rewrite. */
+ stmt->m_prepared_stmt= MYSQL_CREATE_PS(stmt, stmt->id,
+ thd->m_statement_psi,
+ stmt->name.str, stmt->name.length,
+ NULL, 0);
+
if (stmt->prepare(packet, packet_length))
{
/* Statement map deletes statement on erase */
@@ -2865,6 +2873,12 @@ void mysql_sql_stmt_prepare(THD *thd)
*/
Item_change_list_savepoint change_list_savepoint(thd);
+ /* Create PS table entry, set query text after rewrite. */
+ stmt->m_prepared_stmt= MYSQL_CREATE_PS(stmt, stmt->id,
+ thd->m_statement_psi,
+ stmt->name.str, stmt->name.length,
+ NULL, 0);
+
if (stmt->prepare(query.str, (uint) query.length))
{
/* Statement map deletes the statement on erase */
@@ -3260,6 +3274,8 @@ static void mysql_stmt_execute_common(THD *thd,
open_cursor= MY_TEST(cursor_flags & (ulong) CURSOR_TYPE_READ_ONLY);
thd->protocol= &thd->protocol_binary;
+ MYSQL_EXECUTE_PS(thd->m_statement_psi, stmt->m_prepared_stmt);
+
if (!bulk_op)
stmt->execute_loop(&expanded_query, open_cursor, packet, packet_end);
else
@@ -3369,6 +3385,8 @@ void mysql_sql_stmt_execute(THD *thd)
CALL p1('x');
*/
Item_change_list_savepoint change_list_savepoint(thd);
+ MYSQL_EXECUTE_PS(thd->m_statement_psi, stmt->m_prepared_stmt);
+
(void) stmt->execute_loop(&expanded_query, FALSE, NULL, NULL);
change_list_savepoint.rollback(thd);
thd->free_items(); // Free items created by execute_loop()
@@ -3787,6 +3805,7 @@ Prepared_statement::Prepared_statement(THD *thd_arg)
STMT_INITIALIZED,
((++thd_arg->statement_id_counter) & STMT_ID_MASK)),
thd(thd_arg),
+ m_prepared_stmt(NULL),
result(thd_arg),
param_array(0),
cursor(0),
@@ -3868,6 +3887,9 @@ Prepared_statement::~Prepared_statement()
DBUG_ENTER("Prepared_statement::~Prepared_statement");
DBUG_PRINT("enter",("stmt: %p cursor: %p",
this, cursor));
+
+ MYSQL_DESTROY_PS(m_prepared_stmt);
+
delete cursor;
/*
We have to call free on the items even if cleanup is called as some items,
@@ -4101,6 +4123,8 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
state= Query_arena::STMT_PREPARED;
flags&= ~ (uint) IS_IN_USE;
+ MYSQL_SET_PS_TEXT(m_prepared_stmt, query(), query_length());
+
/*
Log COM_EXECUTE to the general log. Note, that in case of SQL
prepared statements this causes two records to be output:
@@ -4518,6 +4542,7 @@ Prepared_statement::reprepare()
if (likely(!error))
{
+ MYSQL_REPREPARE_PS(m_prepared_stmt);
swap_prepared_statement(&copy);
swap_parameter_array(param_array, copy.param_array, param_count);
#ifdef DBUG_ASSERT_EXISTS
@@ -4755,17 +4780,13 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
if (query_cache_send_result_to_client(thd, thd->query(),
thd->query_length()) <= 0)
{
- PSI_statement_locker *parent_locker;
MYSQL_QUERY_EXEC_START(thd->query(),
thd->thread_id,
thd->get_db(),
&thd->security_ctx->priv_user[0],
(char *) thd->security_ctx->host_or_ip,
1);
- parent_locker= thd->m_statement_psi;
- thd->m_statement_psi= NULL;
error= mysql_execute_command(thd);
- thd->m_statement_psi= parent_locker;
MYSQL_QUERY_EXEC_DONE(error);
}
else
@@ -4878,7 +4899,12 @@ bool Prepared_statement::execute_immediate(const char *query, uint query_len)
set_sql_prepare();
name= execute_immediate_stmt_name; // for DBUG_PRINT etc
- if (unlikely(prepare(query, query_len)))
+
+ m_prepared_stmt= MYSQL_CREATE_PS(this, id, thd->m_statement_psi,
+ name.str, name.length,
+ NULL, 0);
+
+ if (prepare(query, query_len))
DBUG_RETURN(true);
if (param_count != thd->lex->prepared_stmt.param_count())
@@ -4888,6 +4914,7 @@ bool Prepared_statement::execute_immediate(const char *query, uint query_len)
DBUG_RETURN(true);
}
+ MYSQL_EXECUTE_PS(thd->m_statement_psi, m_prepared_stmt);
(void) execute_loop(&expanded_query, FALSE, NULL, NULL);
deallocate_immediate();
DBUG_RETURN(false);