[MDEV-24364] Alter rename table does not remove PFS share Created: 2020-12-08  Updated: 2020-12-22  Resolved: 2020-12-22

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Performance Schema
Affects Version/s: 10.5
Fix Version/s: 10.5.9

Type: Bug Priority: Major
Reporter: Aleksey Midenkov Assignee: Aleksey Midenkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-21053 Crash safety of foreign key DDL In Review

 Description   

Reproduce

--source include/have_perfschema.inc
 
create or replace table yt4 (x int);
alter table yt4 rename to t1, algorithm=copy;
drop tables t1;
 
SELECT object_type, object_schema, object_name
FROM performance_schema.objects_summary_global_by_type
WHERE object_schema="test";

Result

object_type     object_schema   object_name
TABLE   test    yt4

Expected

Empty resultset.

Notes

10.3, 10.4 look good:

create or replace table yt4 (x int);
alter table yt4 rename to t1, algorithm=copy;
drop tables t1;
SELECT object_type, object_schema, object_name
FROM performance_schema.objects_summary_global_by_type
WHERE object_schema="test";
object_type     object_schema   object_name

algorithm=inplace on 10.5 looks good:

create or replace table yt4 (x int) engine innodb;
alter table yt4 rename to t1, algorithm=inplace;
drop tables t1;
SELECT object_type, object_schema, object_name
FROM performance_schema.objects_summary_global_by_type
WHERE object_schema="test";
object_type     object_schema   object_name



 Comments   
Comment by Aleksey Midenkov [ 2020-12-10 ]

Good (10.3): PFS share released

#0  0x000000000141c738 in PFS_atomic::store_u32 (ptr=0x7f290f3dc9c0, value=4) at /home/midenok/src/mariadb/10.3/src/storage/perfschema/pfs_atomic.h:76
#1  0x000000000141c60f in pfs_lock::allocated_to_free (this=0x7f290f3dc9c0) at /home/midenok/src/mariadb/10.3/src/storage/perfschema/pfs_lock.h:209
#2  0x000000000142da65 in drop_table_share (thread=0x7f290e14db40, temporary=false, schema_name=0x7f289c014370 "test", schema_name_length=4, table_name=0x7f289c013ce0 "yt4", table_name_length=3) at /home/midenok/src/mariadb/10.3/src/storage/perfschema/pfs_instr_class.cc:1422
#3  0x000000000145612c in drop_table_share_v1 (temporary=0 '\000', schema_name=0x7f289c014370 "test", schema_name_length=4, table_name=0x7f289c013ce0 "yt4", table_name_length=3) at /home/midenok/src/mariadb/10.3/src/storage/perfschema/pfs.cc:1612
#4  0x000000000089aaf4 in mysql_rename_table (base=0x33f67d8, old_db=0x7f28d00f4338, old_name=0x7f28d00f4348, new_db=0x7f28d00f4338, new_name=0x7f28d00f38d0, flags=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_table.cc:5564
#5  0x00000000008a3333 in mysql_alter_table (thd=0x7f289c000d28, new_db=0x7f289c005400, new_name=0x7f289c0057c8, create_info=0x7f28d00f5648, table_list=0x7f289c013d18, alter_info=0x7f28d00f5590, order_num=0, order=0x0, ignore=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_table.cc:10161
#6  0x0000000000950bf5 in Sql_cmd_alter_table::execute (this=0x7f289c0143b8, thd=0x7f289c000d28) at /home/midenok/src/mariadb/10.3/src/sql/sql_alter.cc:512
#7  0x00000000007a31be in mysql_execute_command (thd=0x7f289c000d28) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:6052
#8  0x0000000000795206 in mysql_parse (thd=0x7f289c000d28, rawbuf=0x7f289c013c10 "alter table yt4 rename to t1, algorithm=copy", length=44, parser_state=0x7f28d00f85e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7837

frame 4

5558      /*
5559        Remove the old table share from the pfs table share array. The new table
5560        share will be created when the renamed table is first accessed.
5561       */
5562      if (likely(error == 0))
5563      {
5564        PSI_CALL_drop_table_share(flags & FN_FROM_IS_TMP,
5565                                  old_db->str, (uint)old_db->length,
5566                                  old_name->str, (uint)old_name->length);
5567      }

frame 5

10161     if (mysql_rename_table(old_db_type, &alter_ctx.db, &alter_ctx.table_name,
10162                            &alter_ctx.db, &backup_name, FN_TO_IS_TMP))
10163     {
10164       // Rename to temporary name failed, delete the new table, abort ALTER.
10165       (void) quick_rm_table(thd, new_db_type, &alter_ctx.new_db,
10166                             &alter_ctx.tmp_name, FN_IS_TMP);
10167       goto err_with_mdl;
10168     }

Bad (10.5): mysql_rename_table() on old table is not called:

10930     if (!alter_ctx.is_table_renamed())
10931     {
10932       backup_name.length= my_snprintf(backup_name_buff, sizeof(backup_name_buff),
10933                                       "%s-backup-%lx-%llx", tmp_file_prefix,
10934                                       current_pid, thd->thread_id);
10935       if (lower_case_table_names)
10936         my_casedn_str(files_charset_info, backup_name_buff);
10937       if (mysql_rename_table(old_db_type, &alter_ctx.db, &alter_ctx.table_name,
10938                              &alter_ctx.db, &backup_name,
10939                              FN_TO_IS_TMP |
10940                              (engine_changed ? NO_HA_TABLE | NO_PAR_TABLE : 0)))
10941       {
10942         // Rename to temporary name failed, delete the new table, abort ALTER.
10943         (void) quick_rm_table(thd, new_db_type, &alter_ctx.new_db,
10944                               &alter_ctx.tmp_name, FN_IS_TMP);
10945         goto err_with_mdl;
10946       }
10947     }
10948     else
10949     {
10950       /* The original table is the backup */
10951       backup_name= alter_ctx.table_name;
10952     }

Fix

Do PSI_CALL_drop_table_share() in "The original table is the backup" branch.

Notes

Caused by 043a3a0176e2

Comment by Aleksey Midenkov [ 2020-12-14 ]

https://github.com/MariaDB/server/commit/88f5559d5f4db0d819cdfef97bbeb65828e18e29

Comment by Oleksandr Byelkin [ 2020-12-16 ]

OK to push

Generated at Thu Feb 08 09:29:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.