Below is the list of changes that have just been committed into a local
5.1 repository of guilhem. When guilhem does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2006-09-06 16:07:36+02:00, guilhem@stripped +11 -0
Fixing problems I identified in my auto_increment work pushed in July
(as part of the auto_increment cleanup of WL#3146; let's not be
sad, that monster push still removed serious bugs):
one problem with INSERT DELAYED (unexpected interval releases),
one with stored functions (wrong auto_inc binlogging).
These bugs were not released and will be fixed before release.
mysql-test/extra/binlog_tests/binlog.test@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +9 -3
more tests of binlogging of INSERT DELAYED: with multi-row INSERTs.
I identified why sleeps are needed to get a repeatable row-based
binlogged: because without sleeps rows sometimes get groupped
and so generate different row based events.
mysql-test/extra/rpl_tests/rpl_insert_id.test@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +23 -1
testing that if some statement does not update any row, it does
not pollute the auto_inc binlog variables of the next statement;
the test has to use stored procedures because with plain statements,
mysql_reset_thd_for_next_command() does the resetting (and thus
there is no problem); mysql_reset_thd_for_next_command() is not
called inside routines.
mysql-test/r/binlog_row_binlog.result@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +18 -0
result for new tests
mysql-test/r/binlog_stm_binlog.result@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +14 -0
r
mysql-test/r/rpl_insert_id.result@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +26 -1
result for new tests
mysql-test/r/rpl_loaddata.result@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +3 -3
With the change to log.cc reverted, the result changes and is better:
the change to log.cc had caused some INSERT_ID events to disappear
though they were necessary (but testsuite could not catch that because
it's single-threaded).
sql/log.cc@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +0 -3
LOAD DATA INFILE is binlogged as several events, and the last of them must
have the auto_inc id. So it's wrong to reset the auto_inc id after every
binlog write (because then it's lost after the first event of LOAD
DATA INFILE and so missing for the last one)/
Another problem: MYSQL_LOG::write() is not always called (for example
if no row was updated), so we were missing reset in some cases.
sql/sp_head.cc@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +12 -1
SELECT func1(),func2() generates two binlog events, so needs to
clear auto_increment binlog variables after each binlog event
(it would be more natural to clear them in the log write code,
but LOAD DATA INFILE would suffer from this see the cset comment
for log.cc). Without the clearing, the problem is:
> exec func1()
>> call cleanup_after_query() (which does not clear our vars here)
>> binlog SELECT func1()
<
> exec func2()
and so SELECT func2() is binlogged with the auto_inc of SELECT func1().
sql/sql_class.cc@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +6 -0
after every statement we should clear auto_inc variables used for
binlogging, except if this was a function/trigger (in which case
it may be "INSERT SELECT func()", where the cleanup_after_query()
executed in func() should not reset the auto_inc binlog variables
as they'll be necessary when binlogging the INSERT SELECT later).
sql/sql_insert.cc@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +18 -5
- as INSERT DELAYED uses the same TABLE object as the delayed_insert
system thread, we should not call ha_release_auto_increment()
from INSERT DELAYED (and btw it's logical as we reserve nothing
as we don't perform the insert). Calling the function caused us to
release values being used by the delayed_insert thread.
So I do the call only if this is a non-DELAYED INSERT.
- Assuming two INSERT DELAYED which get grouped by the delayed_insert
thread, the second may use values reserved by the first, which is ok
per se, but is a problem in statement-based binlogging:
the 2nd INSERT gets binlogged with the "interval start" value
of the first INSERT (=> duplicate error in slave).
- no reason to ha_release_auto_increment() after every inserted row
in INSERT SELECT; more efficient to do it only when the statement ends
sql/sql_parse.cc@stripped, 2006-09-06 16:07:17+02:00, guilhem@stripped +7 -2
a comment
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: guilhem
# Host: gbichot3.local
# Root: /home/mysql_src/mysql-5.1-maint
--- 1.223/sql/log.cc 2006-09-06 16:07:43 +02:00
+++ 1.224/sql/log.cc 2006-09-06 16:07:43 +02:00
@@ -3411,9 +3411,6 @@ bool MYSQL_BIN_LOG::write(Log_event *eve
}
}
}
- /* Forget those values, for next binlogger: */
- thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
- thd->auto_inc_intervals_in_cur_stmt_for_binlog.empty();
}
/*
--- 1.287/sql/sql_class.cc 2006-09-06 16:07:43 +02:00
+++ 1.288/sql/sql_class.cc 2006-09-06 16:07:43 +02:00
@@ -634,6 +634,12 @@ bool THD::store_globals()
void THD::cleanup_after_query()
{
+ if (!in_sub_stmt) /* stored functions and triggers are a special case */
+ {
+ /* Forget those values, for next binlogger: */
+ stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
+ auto_inc_intervals_in_cur_stmt_for_binlog.empty();
+ }
if (first_successful_insert_id_in_cur_stmt > 0)
{
/* set what LAST_INSERT_ID() will return */
--- 1.221/sql/sql_insert.cc 2006-09-06 16:07:43 +02:00
+++ 1.222/sql/sql_insert.cc 2006-09-06 16:07:43 +02:00
@@ -563,7 +563,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
free_underlaid_joins(thd, &thd->lex->select_lex);
joins_freed= TRUE;
- table->file->ha_release_auto_increment();
/*
Now all rows are inserted. Time to update logs and sends response to
@@ -582,6 +581,11 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
else
#endif
{
+ /*
+ Do not do this release if this is a delayed insert, it would steal
+ auto_inc values from the delayed_insert thread as they share TABLE.
+ */
+ table->file->ha_release_auto_increment();
if (!thd->prelocked_mode && table->file->ha_end_bulk_insert() && !error)
{
table->file->print_error(my_errno,MYF(0));
@@ -2106,8 +2110,16 @@ bool delayed_insert::handle_inserts(void
thd.start_time=row->start_time;
thd.query_start_used=row->query_start_used;
- /* for the binlog, forget auto_increment ids generated by previous rows */
-// thd.auto_inc_intervals_in_cur_stmt_for_binlog.empty();
+ /*
+ To get the exact auto_inc interval to store in the binlog we must not
+ use values from the previous interval (of the previous rows).
+ */
+ bool log_query= (row->log_query && row->query.str != NULL);
+ if (log_query)
+ {
+ table->file->ha_release_auto_increment();
+ thd.auto_inc_intervals_in_cur_stmt_for_binlog.empty();
+ }
thd.first_successful_insert_id_in_prev_stmt=
row->first_successful_insert_id_in_prev_stmt;
thd.stmt_depends_on_first_successful_insert_id_in_prev_stmt=
@@ -2148,7 +2160,7 @@ bool delayed_insert::handle_inserts(void
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
}
- if (row->log_query && row->query.str != NULL && mysql_bin_log.is_open())
+ if (log_query && mysql_bin_log.is_open())
{
/*
If the query has several rows to insert, only the first row will come
@@ -2544,7 +2556,6 @@ bool select_insert::send_data(List<Item>
table->next_number_field->reset();
}
}
- table->file->ha_release_auto_increment();
DBUG_RETURN(error);
}
@@ -2618,6 +2629,7 @@ void select_insert::send_error(uint errc
}
}
ha_rollback_stmt(thd);
+ table->file->ha_release_auto_increment();
DBUG_VOID_RETURN;
}
@@ -2668,6 +2680,7 @@ bool select_insert::send_eof()
}
if ((error2=ha_autocommit_or_rollback(thd,error)) && ! error)
error=error2;
+ table->file->ha_release_auto_increment();
if (error)
{
table->file->print_error(error,MYF(0));
--- 1.582/sql/sql_parse.cc 2006-09-06 16:07:43 +02:00
+++ 1.583/sql/sql_parse.cc 2006-09-06 16:07:43 +02:00
@@ -5861,9 +5861,14 @@ void mysql_reset_thd_for_next_command(TH
DBUG_ASSERT(!thd->spcont); /* not for substatements of routines */
thd->free_list= 0;
thd->select_number= 1;
+ /*
+ Those two lines below are theoretically unneeded as
+ THD::cleanup_after_query() should take care of this already.
+ */
thd->auto_inc_intervals_in_cur_stmt_for_binlog.empty();
- thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt=
- thd->query_start_used= 0;
+ thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
+
+ thd->query_start_used= 0;
thd->is_fatal_error= thd->time_zone_used= 0;
thd->server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
SERVER_QUERY_NO_INDEX_USED |
--- 1.10/mysql-test/extra/rpl_tests/rpl_insert_id.test 2006-09-06 16:07:43 +02:00
+++ 1.11/mysql-test/extra/rpl_tests/rpl_insert_id.test 2006-09-06 16:07:43 +02:00
@@ -289,8 +289,30 @@ select * from t1;
select * from t2;
connection master;
-drop table t1, t2;
+drop table t1;
drop function insid;
+truncate table t2;
+create table t1 (n int primary key auto_increment not null,
+b int, unique(b));
+delimiter |;
+create procedure foo()
+begin
+ insert into t1 values(null,10);
+ insert ignore into t1 values(null,10);
+ insert ignore into t1 values(null,10);
+ insert into t2 values(null,3);
+end|
+delimiter ;|
+call foo();
+select * from t1;
+select * from t2;
+
sync_slave_with_master;
+select * from t1;
+select * from t2;
+connection master;
+drop table t1, t2;
+drop procedure foo;
+sync_slave_with_master;
--- 1.5/mysql-test/r/binlog_row_binlog.result 2006-09-06 16:07:43 +02:00
+++ 1.6/mysql-test/r/binlog_row_binlog.result 2006-09-06 16:07:43 +02:00
@@ -250,11 +250,21 @@ set @@session.auto_increment_increment=1
insert delayed into t1 values (207);
insert delayed into t1 values (null);
insert delayed into t1 values (300);
+insert delayed into t1 values (null),(null),(null),(null);
+insert delayed into t1 values (null),(null),(400),(null);
select * from t1;
a
207
208
300
+301
+302
+303
+304
+305
+306
+400
+401
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query 1 # use `test`; create table t1 (id tinyint auto_increment primary key)
@@ -262,6 +272,14 @@ master-bin.000001 # Table_map 1 # table_
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
master-bin.000001 # Query 1 # use `test`; drop table t1
master-bin.000001 # Query 1 # use `test`; create table t1 (a int not null auto_increment, primary key (a)) engine=myisam
+master-bin.000001 # Table_map 1 # table_id: # (test.t1)
+master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map 1 # table_id: # (test.t1)
+master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map 1 # table_id: # (test.t1)
+master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map 1 # table_id: # (test.t1)
+master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
master-bin.000001 # Table_map 1 # table_id: # (test.t1)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
master-bin.000001 # Table_map 1 # table_id: # (test.t1)
--- 1.20/mysql-test/r/rpl_insert_id.result 2006-09-06 16:07:43 +02:00
+++ 1.21/mysql-test/r/rpl_insert_id.result 2006-09-06 16:07:43 +02:00
@@ -267,5 +267,30 @@ select * from t2;
id last_id
4 0
8 0
-drop table t1, t2;
+drop table t1;
drop function insid;
+truncate table t2;
+create table t1 (n int primary key auto_increment not null,
+b int, unique(b));
+create procedure foo()
+begin
+insert into t1 values(null,10);
+insert ignore into t1 values(null,10);
+insert ignore into t1 values(null,10);
+insert into t2 values(null,3);
+end|
+call foo();
+select * from t1;
+n b
+1 10
+select * from t2;
+id last_id
+1 3
+select * from t1;
+n b
+1 10
+select * from t2;
+id last_id
+1 3
+drop table t1, t2;
+drop procedure foo;
--- 1.33/mysql-test/r/rpl_loaddata.result 2006-09-06 16:07:43 +02:00
+++ 1.34/mysql-test/r/rpl_loaddata.result 2006-09-06 16:07:43 +02:00
@@ -28,7 +28,7 @@ day id category name
2003-03-22 2416 a bbbbb
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
-slave-bin.000001 1248
+slave-bin.000001 1276
drop table t1;
drop table t2;
drop table t3;
@@ -39,7 +39,7 @@ set global sql_slave_skip_counter=1;
start slave;
show slave status;
Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master
-# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 1765 # # master-bin.000001 Yes Yes # 0 0 1765 # None 0 No #
+# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 1793 # # master-bin.000001 Yes Yes # 0 0 1793 # None 0 No #
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
@@ -49,7 +49,7 @@ change master to master_user='test';
change master to master_user='root';
show slave status;
Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master
-# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 1800 # # master-bin.000001 No No # 0 0 1800 # None 0 No #
+# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 1828 # # master-bin.000001 No No # 0 0 1828 # None 0 No #
set global sql_slave_skip_counter=1;
start slave;
set sql_log_bin=0;
--- 1.235/sql/sp_head.cc 2006-09-06 16:07:43 +02:00
+++ 1.236/sql/sp_head.cc 2006-09-06 16:07:43 +02:00
@@ -794,7 +794,7 @@ int cmp_splocal_locations(Item_splocal *
This set is produced by tracking user variable reads during statement
execution.
- Fo SPs, this has the following implications:
+ For SPs, this has the following implications:
1) thd->user_var_events may contain events from several SP statements and
needs to be valid after exection of these statements was finished. In
order to achieve that, we
@@ -807,6 +807,14 @@ int cmp_splocal_locations(Item_splocal *
reset_dynamic(&thd->user_var_events);
calls in several different places. (TODO cosider moving this into
mysql_bin_log.write() function)
+
+ 4.2 Auto_increment storage in binlog
+
+ As we may write two statements to binlog from one single logical statement
+ (case of "SELECT func1(),func2()": it is binlogged as "SELECT func1()" and
+ then "SELECT func2()"), we need to reset auto_increment binlog variables
+ after each binlogged SELECT. Otherwise, the auto_increment value of the
+ first SELECT would be used for the second too.
*/
@@ -1526,6 +1534,9 @@ sp_head::execute_function(THD *thd, Item
"failed to reflect this change in the binary log");
}
reset_dynamic(&thd->user_var_events);
+ /* Forget those values, in case more function calls are binlogged: */
+ thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
+ thd->auto_inc_intervals_in_cur_stmt_for_binlog.empty();
}
}
--- 1.12/mysql-test/r/binlog_stm_binlog.result 2006-09-06 16:07:43 +02:00
+++ 1.13/mysql-test/r/binlog_stm_binlog.result 2006-09-06 16:07:43 +02:00
@@ -160,11 +160,21 @@ set @@session.auto_increment_increment=1
insert delayed into t1 values (207);
insert delayed into t1 values (null);
insert delayed into t1 values (300);
+insert delayed into t1 values (null),(null),(null),(null);
+insert delayed into t1 values (null),(null),(400),(null);
select * from t1;
a
207
208
300
+301
+302
+303
+304
+305
+306
+400
+401
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query 1 # use `test`; create table t1 (id tinyint auto_increment primary key)
@@ -176,4 +186,8 @@ master-bin.000001 # Query 1 # use `test`
master-bin.000001 # Intvar 1 # INSERT_ID=208
master-bin.000001 # Query 1 # use `test`; insert delayed into t1 values (null)
master-bin.000001 # Query 1 # use `test`; insert delayed into t1 values (300)
+master-bin.000001 # Intvar 1 # INSERT_ID=301
+master-bin.000001 # Query 1 # use `test`; insert delayed into t1 values (null),(null),(null),(null)
+master-bin.000001 # Intvar 1 # INSERT_ID=305
+master-bin.000001 # Query 1 # use `test`; insert delayed into t1 values (null),(null),(400),(null)
drop table t1;
--- 1.12/mysql-test/extra/binlog_tests/binlog.test 2006-09-06 16:07:43 +02:00
+++ 1.13/mysql-test/extra/binlog_tests/binlog.test 2006-09-06 16:07:43 +02:00
@@ -67,14 +67,20 @@ set @@session.auto_increment_increment=1
insert delayed into t1 values (207);
# We use sleeps between statements, that's the only way to get a
-# repeatable binlog in a normal test run and under Valgrind.
-# It may be that the "binlog missing rows" of BUG#20821 shows up
-# here.
+# repeatable binlog in a normal test run and under Valgrind. The
+# reason is that without sleeps, rows of different INSERT DELAYEDs
+# sometimes group together and sometimes not, so the table may be
+# unlocked/relocked causing a different number of table map log
+# events.
sleep 2;
insert delayed into t1 values (null);
sleep 2;
insert delayed into t1 values (300);
sleep 2; # time for the delayed queries to reach disk
+insert delayed into t1 values (null),(null),(null),(null);
+sleep 2;
+insert delayed into t1 values (null),(null),(400),(null);
+sleep 2;
select * from t1;
--replace_column 2 # 5 #
--replace_regex /table_id: [0-9]+/table_id: #/
| Thread |
|---|
| • bk commit into 5.1 tree (guilhem:1.2310) | guilhem | 6 Sep |