diff --git a/mysql-test/suite/plugins/r/audit_null.result b/mysql-test/suite/plugins/r/audit_null.result index 76aef454b94..79de1f7df80 100644 --- a/mysql-test/suite/plugins/r/audit_null.result +++ b/mysql-test/suite/plugins/r/audit_null.result @@ -44,6 +44,7 @@ insert t2 values ('2020-10-09'); select * from t2; a 2020-10-09 +alter table t2 add column b int; drop table t2; explain select distinct * from t2; id select_type table type possible_keys key key_len ref rows Extra @@ -77,8 +78,8 @@ root[root] @ localhost [] test.t1 : read root[root] @ localhost [] >> rename table t1 to t2 root[root] @ localhost [] test.t1 : rename to test.t2 root[root] @ localhost [] >> alter table t2 add column b int -root[root] @ localhost [] test.t2 : alter root[root] @ localhost [] test.t2 : read +root[root] @ localhost [] test.t2 : alter root[root] @ localhost [] >> create definer=testuser@localhost view v1 as select t2.a+1, t2_copy.a+2 from t2, t2 as t2_copy root[root] @ localhost [] test.t2 : read root[root] @ localhost [] test.t2 : read @@ -89,6 +90,7 @@ root[root] @ localhost [] >> drop view v1 root[root] @ localhost [] >> create temporary table t2 (a date) root[root] @ localhost [] >> insert t2 values ('2020-10-09') root[root] @ localhost [] >> select * from t2 +root[root] @ localhost [] >> alter table t2 add column b int root[root] @ localhost [] >> drop table t2 root[root] @ localhost [] >> explain select distinct * from t2 root[root] @ localhost [] test.t2 : read diff --git a/mysql-test/suite/plugins/t/audit_null.test b/mysql-test/suite/plugins/t/audit_null.test index 60883bbe4f9..3e32154ec3d 100644 --- a/mysql-test/suite/plugins/t/audit_null.test +++ b/mysql-test/suite/plugins/t/audit_null.test @@ -38,6 +38,7 @@ drop view v1; create temporary table t2 (a date); insert t2 values ('2020-10-09'); select * from t2; +alter table t2 add column b int; # MDEV-4565 ALTER on a temporary table generates an audit event drop table t2; # internal temp table generates no audit events diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 51cfdc3e03f..47b1627f8e4 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6064,13 +6064,16 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, mysql_ha_rm_tables(thd, table_list); - mysql_audit_alter_table(thd, table_list); - /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */ if (alter_info->tablespace_op != NO_TABLESPACE_OP) + { + mysql_audit_alter_table(thd, table_list); + /* Conditionally writes to binlog. */ - DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list, - alter_info->tablespace_op)); + bool ret= mysql_discard_or_import_tablespace(thd,table_list, + alter_info->tablespace_op); + DBUG_RETURN(ret); + } /* Code below can handle only base tables so ensure that we won't open a view. @@ -6262,6 +6265,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, my_error(ER_ILLEGAL_HA, MYF(0), table_name); goto err; } + + if (table->s->tmp_table == NO_TMP_TABLE) + mysql_audit_alter_table(thd, table_list); thd_proc_info(thd, "setup"); if (!(alter_info->flags & ~(ALTER_RENAME | ALTER_KEYS_ONOFF)) &&