From 4c1cc24ce082c1b0198e1c0b7b5e6fa7094222c0 Mon Sep 17 00:00:00 2001 From: hongdongjian Date: Mon, 3 Apr 2023 23:17:20 +0800 Subject: [PATCH 1/2] audit plugin add examined_row_count/affected_row_count/return_row_count --- include/mysql/plugin_audit.h | 3 +++ include/mysql/plugin_audit.h.pp | 3 +++ sql/sql_audit.cc | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/include/mysql/plugin_audit.h b/include/mysql/plugin_audit.h index b5b08f019e1d..1f7095271db8 100644 --- a/include/mysql/plugin_audit.h +++ b/include/mysql/plugin_audit.h @@ -141,6 +141,9 @@ struct mysql_event_general { MYSQL_LEX_CSTRING general_sql_command; MYSQL_LEX_CSTRING general_external_user; MYSQL_LEX_CSTRING general_ip; + unsigned long long general_examined_row_count; + unsigned long long general_affected_row_count; + unsigned long long general_return_row_count; }; #define MYSQL_AUDIT_CONNECTION_ALL \ diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 3738ce41e076..f5b64c16e386 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -398,6 +398,9 @@ MYSQL_LEX_CSTRING general_sql_command; MYSQL_LEX_CSTRING general_external_user; MYSQL_LEX_CSTRING general_ip; + unsigned long long general_examined_row_count; + unsigned long long general_affected_row_count; + unsigned long long general_return_row_count; }; struct mysql_event_connection { mysql_event_connection_subclass_t event_subclass; diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index c56053e19a95..85b3a288c6f4 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -385,6 +385,13 @@ int mysql_audit_notify(THD *thd, mysql_event_general_subclass_t subclass, event.general_external_user = sctx->external_user(); event.general_rows = thd->get_stmt_da()->current_row_for_condition(); event.general_sql_command = sql_statement_names[thd->lex->sql_command]; + event.general_examined_row_count = thd->get_examined_row_count(); + if (thd->get_row_count_func() < 0) { + event.general_affected_row_count = 0; + } else { + event.general_affected_row_count = thd->get_row_count_func(); + } + event.general_return_row_count = thd->get_sent_row_count(); event.general_charset = const_cast( thd_get_audit_query(thd, &event.general_query)); From 32e7265c5a66884d2d7a899c4b24fb471cd99d78 Mon Sep 17 00:00:00 2001 From: hongdongjian Date: Wed, 5 Apr 2023 20:40:13 +0800 Subject: [PATCH 2/2] audit plugin add database parameter --- include/mysql/plugin_audit.h | 1 + include/mysql/plugin_audit.h.pp | 1 + sql/sql_audit.cc | 1 + 3 files changed, 3 insertions(+) diff --git a/include/mysql/plugin_audit.h b/include/mysql/plugin_audit.h index 1f7095271db8..1fc6ec24d3f5 100644 --- a/include/mysql/plugin_audit.h +++ b/include/mysql/plugin_audit.h @@ -141,6 +141,7 @@ struct mysql_event_general { MYSQL_LEX_CSTRING general_sql_command; MYSQL_LEX_CSTRING general_external_user; MYSQL_LEX_CSTRING general_ip; + MYSQL_LEX_CSTRING general_database; unsigned long long general_examined_row_count; unsigned long long general_affected_row_count; unsigned long long general_return_row_count; diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index f5b64c16e386..062394a7a184 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -398,6 +398,7 @@ MYSQL_LEX_CSTRING general_sql_command; MYSQL_LEX_CSTRING general_external_user; MYSQL_LEX_CSTRING general_ip; + MYSQL_LEX_CSTRING general_database; unsigned long long general_examined_row_count; unsigned long long general_affected_row_count; unsigned long long general_return_row_count; diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 85b3a288c6f4..46b19394de86 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -385,6 +385,7 @@ int mysql_audit_notify(THD *thd, mysql_event_general_subclass_t subclass, event.general_external_user = sctx->external_user(); event.general_rows = thd->get_stmt_da()->current_row_for_condition(); event.general_sql_command = sql_statement_names[thd->lex->sql_command]; + event.general_database = thd->db(); event.general_examined_row_count = thd->get_examined_row_count(); if (thd->get_row_count_func() < 0) { event.general_affected_row_count = 0;