Skip to content

Commit a04fd00

Browse files
committed
MDEV-38633: Row events in statement based binlog: optimization possible?
A failing multi-table UPDATE or DELETE marked every target temporary table as not up to date in the binary log, even when nothing had been changed. Any later statement reading such a table was then forced to use row logging. Only mark the tables when something was actually changed—that is, when rows were updated/deleted or a non-transactional table was modified. If nothing changed, set THD::tmp_table_binlog_handled so that mark_tmp_table_as_free_for_reuse() does not mark them either.
1 parent add6399 commit a04fd00

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

sql/sql_delete.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,10 +1501,19 @@ void multi_delete::abort_result_set()
15011501
15021502
***************************************************************************/
15031503

1504-
/* the error was handled or nothing deleted and no side effects return */
1505-
if (error_handled ||
1506-
(!thd->transaction->stmt.modified_non_trans_table && !deleted))
1504+
/*
1505+
Nothing was deleted and there are no side effects: no temporary table
1506+
was changed, so they all stay up to date in the binary log.
1507+
*/
1508+
if (!thd->transaction->stmt.modified_non_trans_table && !deleted)
1509+
{
1510+
thd->tmp_table_binlog_handled= 1;
15071511
DBUG_VOID_RETURN;
1512+
}
1513+
/* The error was already handled */
1514+
if (error_handled)
1515+
goto end;
1516+
15081517

15091518
/* Something already deleted so we have to invalidate cache */
15101519
if (deleted)
@@ -1551,6 +1560,7 @@ void multi_delete::abort_result_set()
15511560
transactional_tables, FALSE, FALSE, errcode);
15521561
}
15531562
}
1563+
end:
15541564
/*
15551565
Mark all temporay tables as not completely binlogged
15561566
All future usage of these tables will enforce row level logging, which

sql/sql_update.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,9 +2564,17 @@ void multi_update::abort_result_set()
25642564
{
25652565
TABLE_LIST *cur_table;
25662566

2567-
/* the error was handled or nothing deleted and no side effects return */
2568-
if (unlikely(error_handled ||
2569-
(!thd->transaction->stmt.modified_non_trans_table && !updated)))
2567+
/*
2568+
Nothing was updated and there are no side effects: no temporary table
2569+
was changed, so they all stay up to date in the binary log.
2570+
*/
2571+
if (unlikely(!thd->transaction->stmt.modified_non_trans_table && !updated))
2572+
{
2573+
thd->tmp_table_binlog_handled= 1;
2574+
return;
2575+
}
2576+
/* The error was already handled */
2577+
if (unlikely(error_handled))
25702578
goto end;
25712579

25722580
/****************************************************************************

0 commit comments

Comments
 (0)