From 32c1017b25fc00f7a7bfd027b99760826156c56c Mon Sep 17 00:00:00 2001 From: hongdongjian Date: Tue, 4 Apr 2023 00:23:43 +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 e8ead1a3fba7..57b69b03d488 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -382,6 +382,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 704fe36d0881..11803d7de458 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -454,6 +454,13 @@ int mysql_audit_notify(THD *thd, mysql_event_general_subclass_t subclass, event.general_host= sctx->host(); event.general_external_user= sctx->external_user(); event.general_rows= thd->get_stmt_da()->current_row_for_condition(); + 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(); if (thd->lex->sql_command == SQLCOM_END && msg_len > 0 && error_code == 0) { int found_index= -1; From 6df88160b31f5843ad362e463edb428fbb641c5c Mon Sep 17 00:00:00 2001 From: hongdongjian Date: Wed, 5 Apr 2023 20:35:38 +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 57b69b03d488..2e03ad8a87cd 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -382,6 +382,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 11803d7de458..a4d5696ee6d2 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -454,6 +454,7 @@ int mysql_audit_notify(THD *thd, mysql_event_general_subclass_t subclass, event.general_host= sctx->host(); event.general_external_user= sctx->external_user(); event.general_rows= thd->get_stmt_da()->current_row_for_condition(); + 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;