From 2200aba421228081f6152089081c95252e8e892d Mon Sep 17 00:00:00 2001 From: hongdongjian Date: Mon, 3 Apr 2023 23:24:10 +0800 Subject: [PATCH 1/2] audit plugin add examined_row_count/affected_row_count/return_row_count parameter --- 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 12dc8b84073a..9c7bc99c5861 100644 --- a/include/mysql/plugin_audit.h +++ b/include/mysql/plugin_audit.h @@ -138,6 +138,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; }; /** diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 5c6597e84ce5..20740f02bbc3 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -350,6 +350,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; }; typedef enum { diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 5228c274ea12..a5b5b75512a2 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -453,6 +453,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(); thd_get_audit_query(thd, &event.general_query, (const charset_info_st**)&event.general_charset); From 2dac5957dfb84af134d3380e555dfeaf90acf627 Mon Sep 17 00:00:00 2001 From: hongdongjian Date: Wed, 5 Apr 2023 20:38:04 +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 9c7bc99c5861..63ad7ae22954 100644 --- a/include/mysql/plugin_audit.h +++ b/include/mysql/plugin_audit.h @@ -138,6 +138,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 20740f02bbc3..b62ab0cabe67 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -350,6 +350,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 a5b5b75512a2..2e05bed6c875 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -453,6 +453,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;