Skip to content

Commit f099f77

Browse files
committed
Do not log ALTER table to ddl log for REPAIR
REPAIR of InnoDB tables was logging ALTER TABLE and REPAIR to ddl log. ALTER TABLE contained the new tableid and REPAIR, wrongly, contained the old rowid. Now only REPAIR is logged ddl.log changes: REPAIR TABLE and OPTIMIZE TABLE that are done through ALTER TABLE will now contain the old and new table id. If not done through ALTER TABLE, only the current rowid will be shown (as before).
1 parent aae9b50 commit f099f77

File tree

7 files changed

+59
-30
lines changed

7 files changed

+59
-30
lines changed

mysql-test/main/backup_log.result

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ ALTER,InnoDB,0,test,t1_innodb,id: 3,InnoDB,0,test,t1_innodb,id: 4
171171
RENAME,InnoDB,0,test,t1_innodb,id: 4,InnoDB,0,test,t2_innodb,id: 4
172172
RENAME,InnoDB,0,test,t2_innodb,id: 4,InnoDB,0,test,t1_innodb,id: 4
173173
TRUNCATE,InnoDB,0,test,t1_innodb,id: 4,,0,,,
174-
ALTER,InnoDB,0,test,t1_innodb,id: 4,InnoDB,0,test,t1_innodb,id: 5
175-
repair,InnoDB,0,test,t1_innodb,id: 4,,0,,,
176-
ALTER,InnoDB,0,test,t1_innodb,id: 5,InnoDB,0,test,t1_innodb,id: 6
174+
repair,InnoDB,0,test,t1_innodb,id: 4,,0,test,t1_innodb,id: 5
175+
optimize,InnoDB,0,test,t1_innodb,id: 5,,0,test,t1_innodb,id: 6
177176
DROP,InnoDB,0,test,t1_innodb,id: 6,,0,,,
178177
CREATE,MyISAM,0,test,t20,id: 7,,0,,,
179178
DROP,MyISAM,0,test,t20,id: 7,,0,,,

mysql-test/suite/parts/r/backup_log.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ RENAME,InnoDB,1,test,t1_innodb,id: 4,InnoDB,1,test,t2_innodb,id: 4
198198
RENAME,InnoDB,1,test,t2_innodb,id: 4,InnoDB,1,test,t1_innodb,id: 4
199199
TRUNCATE,InnoDB,1,test,t1_innodb,id: 4,,0,,,
200200
repair,InnoDB,1,test,t1_innodb,id: 4,,0,,,
201-
ALTER,InnoDB,1,test,t1_innodb,id: 4,InnoDB,1,test,t1_innodb,id: 5
201+
optimize,InnoDB,1,test,t1_innodb,id: 4,,0,test,t1_innodb,id: 5
202202
DROP,InnoDB,1,test,t1_innodb,id: 5,,0,,,
203203
CREATE,MyISAM,1,test,t20,id: 6,,0,,,
204204
DROP,MyISAM,1,test,t20,id: 6,,0,,,

sql/backup.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,10 @@ void backup_log_ddl(const backup_log_info *info)
671671
ptr= add_name_to_buffer(ptr, &info->org_table);
672672
ptr= add_id_to_buffer(ptr, &info->org_table_id);
673673

674-
/* The following fields are only set in case of rename */
674+
/*
675+
The following fields are only set in case of rename, repair or
676+
alter table
677+
*/
675678
ptr= add_str_to_buffer(ptr, &info->new_storage_engine_name);
676679
ptr= add_bool_to_buffer(ptr, info->new_partitioned);
677680
ptr= add_name_to_buffer(ptr, &info->new_database);

sql/handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,12 +2359,14 @@ struct HA_CREATE_INFO: public Table_scope_and_contents_source_st,
23592359
{
23602360
/* TODO: remove after MDEV-20865 */
23612361
Alter_info *alter_info;
2362+
bool repair;
23622363

23632364
void init()
23642365
{
23652366
Table_scope_and_contents_source_st::init();
23662367
Schema_specification_st::init();
23672368
alter_info= NULL;
2369+
repair= 0;
23682370
}
23692371
ulong table_options_with_row_type()
23702372
{

sql/sql_admin.cc

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,25 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
817817
/* purecov: end */
818818
}
819819

820+
/*
821+
This has to be tested separately from the following test as
822+
optimizer table takes a MDL_SHARED_WRITE lock but we want to
823+
log this to the ddl log.
824+
*/
825+
826+
if (lock_type == TL_WRITE && table->mdl_request.type >= MDL_SHARED_WRITE)
827+
{
828+
/* Store information about table for ddl log */
829+
storage_engine_partitioned= table->table->file->partition_engine();
830+
strmake(storage_engine_name, table->table->file->real_table_type(),
831+
sizeof(storage_engine_name)-1);
832+
tabledef_version.str= tabledef_version_buff;
833+
if ((tabledef_version.length= table->table->s->tabledef_version.length))
834+
memcpy((char*) tabledef_version.str,
835+
table->table->s->tabledef_version.str,
836+
MY_UUID_SIZE);
837+
}
838+
820839
/*
821840
Close all instances of the table to allow MyISAM "repair"
822841
(which is internally also used from "optimize") to rename files.
@@ -835,16 +854,6 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
835854
thd->close_unused_temporary_table_instances(table);
836855
else
837856
{
838-
/* Store information about table for ddl log */
839-
storage_engine_partitioned= table->table->file->partition_engine();
840-
strmake(storage_engine_name, table->table->file->real_table_type(),
841-
sizeof(storage_engine_name)-1);
842-
tabledef_version.str= tabledef_version_buff;
843-
if ((tabledef_version.length= table->table->s->tabledef_version.length))
844-
memcpy((char*) tabledef_version.str,
845-
table->table->s->tabledef_version.str,
846-
MY_UUID_SIZE);
847-
848857
if (wait_while_table_is_used(thd, table->table, HA_EXTRA_NOT_USED))
849858
goto err;
850859
DEBUG_SYNC(thd, "after_admin_flush");
@@ -1476,6 +1485,14 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
14761485
ddl_log.org_database= table->db;
14771486
ddl_log.org_table= table->table_name;
14781487
ddl_log.org_table_id= tabledef_version;
1488+
if (recreate_used)
1489+
{
1490+
LEX_CUSTRING tabledef_version=
1491+
{ recreate_info.tabledef_version, MY_UUID_SIZE };
1492+
ddl_log.new_database= table->db;
1493+
ddl_log.new_table= table->table_name;
1494+
ddl_log.new_table_id= tabledef_version;
1495+
}
14791496
backup_log_ddl(&ddl_log);
14801497
}
14811498

sql/sql_class.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,23 +268,22 @@ class CSET_STRING
268268

269269
class Recreate_info
270270
{
271-
ha_rows m_records_copied;
272-
ha_rows m_records_duplicate;
273271
public:
272+
ha_rows copied;
273+
ha_rows duplicate;
274+
uchar tabledef_version[MY_UUID_SIZE];
275+
274276
Recreate_info()
275-
:m_records_copied(0),
276-
m_records_duplicate(0)
277-
{ }
278-
Recreate_info(ha_rows records_copied,
279-
ha_rows records_duplicate)
280-
:m_records_copied(records_copied),
281-
m_records_duplicate(records_duplicate)
282-
{ }
283-
ha_rows records_copied() const { return m_records_copied; }
284-
ha_rows records_duplicate() const { return m_records_duplicate; }
277+
:copied(0),
278+
duplicate(0)
279+
{
280+
bzero(tabledef_version, sizeof(tabledef_version));
281+
}
282+
ha_rows records_copied() const { return copied; }
283+
ha_rows records_duplicate() const { return duplicate; }
285284
ha_rows records_processed() const
286285
{
287-
return m_records_copied + m_records_duplicate;
286+
return copied + duplicate;
288287
}
289288
};
290289

sql/sql_table.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12236,7 +12236,11 @@ do_continue:;
1223612236
inplace_alter_table_committed= 0;
1223712237
}
1223812238

12239-
if (!alter_ctx.tmp_table)
12239+
/*
12240+
We do not log ALTER ENTRY, when used with REPAIR, to the ddl.log as the
12241+
logging will done in mysql_admin_table()
12242+
*/
12243+
if (!alter_ctx.tmp_table && !create_info->repair)
1224012244
{
1224112245
backup_log_info ddl_log;
1224212246
bzero(&ddl_log, sizeof(ddl_log));
@@ -12253,6 +12257,9 @@ do_continue:;
1225312257
ddl_log.new_table_id= alter_ctx.tmp_id;
1225412258
backup_log_ddl(&ddl_log);
1225512259
}
12260+
if (create_info->repair)
12261+
memcpy(recreate_info->tabledef_version, alter_ctx.tmp_id.str,
12262+
sizeof(recreate_info->tabledef_version));
1225612263

1225712264
table_list->table= NULL;// For query cache
1225812265
query_cache_invalidate3(thd, table_list, false);
@@ -12272,7 +12279,8 @@ do_continue:;
1227212279
thd->variables.option_bits&= ~OPTION_BIN_COMMIT_OFF;
1227312280

1227412281
thd_progress_end(thd);
12275-
*recreate_info= Recreate_info(copied, deleted);
12282+
recreate_info->copied= copied;
12283+
recreate_info->duplicate= deleted;
1227612284
thd->my_ok_with_recreate_info(*recreate_info,
1227712285
(ulong) thd->get_stmt_da()->
1227812286
current_statement_warn_count());
@@ -13061,6 +13069,7 @@ bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list,
1306113069
create_info.row_type=ROW_TYPE_NOT_USED;
1306213070
create_info.alter_info= &alter_info;
1306313071
create_info.recreate_identical_table= 1;
13072+
create_info.repair= 1; // Don't write ALTER TABLE to ddl log
1306413073
/* Force alter table to recreate table */
1306513074
alter_info.flags= (ALTER_CHANGE_COLUMN | ALTER_RECREATE);
1306613075
alter_info.partition_flags= thd->lex->alter_info.partition_flags;

0 commit comments

Comments
 (0)