Commit 9545eb96 authored by Sergei Golubchik's avatar Sergei Golubchik

Fix recalculation of vcols in binlog_row_image=minimal

unpack_row() must calculate all stored and indexed vcols
(in fill_extra_persistent_columns()).

Also Update and Delete row events must mark in read_set
all columns needed for calculating all stored and indexed vcols.

If it's done properly in do_apply_event(), it no longer needs
to be repeated per row.
parent e499b25c
include/master-slave.inc
[connection master]
set binlog_row_image=minimal;
connection slave;
stop slave;
set global binlog_row_image=minimal;
include/reset_slave.inc
create table t1 (
a int key, b blob, c char(5),
d char(10) as (concat(trim(c), '-U')) unique,
e char(10) as (concat('S', b)) stored) engine=innodb;
connection master;
create table t1 (a int primary key, b blob, c char(5)) engine=innodb;
reset master;
connection slave;
start slave;
connection master;
set timestamp=unix_timestamp('2010-10-10 10:10:10');
insert t1 values (1,'.','Kyle'),(2,'?','JOE'),(3,'!','QA'), (4, '$', '4TH');
update t1 set c='UPD' where a=3;
update t1 set b='#' where a=2;
delete from t1 where a=4;
select * from t1;
a b c
1 . Kyle
2 # JOE
3 ! UPD
connection slave;
select * from t1;
a b c d e
1 . Kyle Kyle-U S.
2 # JOE JOE-U S#
3 ! UPD UPD-U S!
select d from t1;
d
JOE-U
Kyle-U
UPD-U
select * from t1 where d='JOE-U';
a b c d e
2 # JOE JOE-U S#
connection master;
drop table t1;
connection slave;
set global binlog_row_image=full;
include/rpl_end.inc
--source include/have_binlog_format_row.inc
--source include/have_innodb.inc
--source include/master-slave.inc
set binlog_row_image=minimal;
connection slave;
stop slave;
set global binlog_row_image=minimal;
--source include/reset_slave.inc
create table t1 (
a int key, b blob, c char(5),
d char(10) as (concat(trim(c), '-U')) unique,
e char(10) as (concat('S', b)) stored) engine=innodb;
connection master;
create table t1 (a int primary key, b blob, c char(5)) engine=innodb;
reset master;
connection slave;
start slave;
connection master;
set timestamp=unix_timestamp('2010-10-10 10:10:10');
insert t1 values (1,'.','Kyle'),(2,'?','JOE'),(3,'!','QA'), (4, '$', '4TH');
update t1 set c='UPD' where a=3;
update t1 set b='#' where a=2;
delete from t1 where a=4;
--sorted_result
select * from t1;
--sorted_result
sync_slave_with_master;
--sorted_result
select * from t1;
select d from t1; # no --sorted_result here, this must be KEYREAD, so must be sorted
select * from t1 where d='JOE-U';
connection master;
drop table t1;
sync_slave_with_master;
set global binlog_row_image=full;
--source include/rpl_end.inc
......@@ -5077,7 +5077,12 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi)
bitmap_set_all(table->read_set);
if (get_general_type_code() == DELETE_ROWS_EVENT ||
get_general_type_code() == UPDATE_ROWS_EVENT)
{
bitmap_intersect(table->read_set,&m_cols);
table->mark_columns_per_binlog_row_image();
if (table->vfield)
table->mark_virtual_columns_for_write(0);
}
bitmap_set_all(table->write_set);
table->rpl_write_set= table->write_set;
......@@ -7336,12 +7341,6 @@ int Rows_log_event::find_row(rpl_group_info *rgi)
// We can't use position() - try other methods.
/*
We need to retrieve all fields
TODO: Move this out from this function to main loop
*/
table->use_all_columns();
/*
Save copy of the record in table->record[1]. It might be needed
later if linear search is used to find exact match.
......@@ -7651,7 +7650,6 @@ int Delete_rows_log_event::do_exec_row(rpl_group_info *rgi)
error= HA_ERR_GENERIC; // in case if error is not set yet
if (likely(!error))
{
m_table->mark_columns_per_binlog_row_image();
if (m_vers_from_plain && m_table->versioned(VERS_TIMESTAMP))
{
Field *end= m_table->vers_end_field();
......@@ -7789,11 +7787,6 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi)
#endif /* WSREP_PROC_INFO */
thd_proc_info(thd, message);
// Temporary fix to find out why it fails [/Matz]
memcpy(m_table->read_set->bitmap, m_cols.bitmap, (m_table->read_set->n_bits + 7) / 8);
memcpy(m_table->write_set->bitmap, m_cols_ai.bitmap, (m_table->write_set->n_bits + 7) / 8);
m_table->mark_columns_per_binlog_row_image();
int error= find_row(rgi);
if (unlikely(error))
......@@ -7884,7 +7877,6 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi)
error= vers_insert_history_row(m_table);
restore_record(m_table, record[2]);
}
m_table->default_column_bitmaps();
if (invoke_triggers && likely(!error) &&
unlikely(process_triggers(TRG_EVENT_UPDATE, TRG_ACTION_AFTER, TRUE)))
......
......@@ -143,6 +143,8 @@ pack_row(TABLE *table, MY_BITMAP const* cols,
}
#endif
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
static int fill_extra_persistent_columns(TABLE *table, int master_cols);
/**
Unpack a row into @c table->record[0].
......@@ -188,7 +190,6 @@ pack_row(TABLE *table, MY_BITMAP const* cols,
@retval HA_ERR_CORRUPT_EVENT
Found error when trying to unpack fields.
*/
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
int
unpack_row(rpl_group_info *rgi,
TABLE *table, uint const colcnt,
......@@ -490,7 +491,7 @@ int prepare_record(TABLE *const table, const uint skip, const bool check)
@param master_cols No of columns on master
@returns 0 on success
*/
int fill_extra_persistent_columns(TABLE *table, int master_cols)
static int fill_extra_persistent_columns(TABLE *table, int master_cols)
{
int error= 0;
Field **vfield_ptr, *vfield;
......@@ -500,7 +501,8 @@ int fill_extra_persistent_columns(TABLE *table, int master_cols)
for (vfield_ptr= table->vfield; *vfield_ptr; ++vfield_ptr)
{
vfield= *vfield_ptr;
if (vfield->field_index >= master_cols && vfield->stored_in_db())
if (vfield->field_index >= master_cols && (vfield->stored_in_db() ||
(vfield->flags & (PART_KEY_FLAG | PART_INDIRECT_KEY_FLAG))))
{
bitmap_set_bit(table->write_set, vfield->field_index);
error= vfield->vcol_info->expr->save_in_field(vfield,0);
......
......@@ -37,7 +37,6 @@ int unpack_row(rpl_group_info *rgi,
// Fill table's record[0] with default values.
int prepare_record(TABLE *const table, const uint skip, const bool check);
int fill_extra_persistent_columns(TABLE *table, int master_cols);
#endif
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment