Bug #71024 | Safe statement marked as unsafe | ||
---|---|---|---|
Submitted: | 27 Nov 2013 11:35 | Modified: | 29 Nov 2013 13:30 |
Reporter: | Paul Keenan | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Replication | Severity: | S3 (Non-critical) |
Version: | 5.6.14 | OS: | MacOS (10.8) |
Assigned to: | CPU Architecture: | Any |
[27 Nov 2013 11:35]
Paul Keenan
[27 Nov 2013 15:37]
MySQL Verification Team
Thank you for the bug report.
[29 Nov 2013 4:00]
Jesper wisborg Krogh
Note given the example, the INSERT ... SELECT ... ORDER BY is only deterministic because t1 only has one column. The ORDER BY is for a non-unique column, so two rows can have the same value in which case the order of those rows is not known. With just that one column, the order doesn't matter, but that is not the general case. The INSERT also results in a warning if t1.f1 is turned into a primary key. ALTER TABLE t1 ADD PRIMARY KEY (f1); Of course the issue then becomes more tricky as whether the auto-increment on t2 is deterministic also depends on the value of innodb_autoinc_lock_mode.
[29 Nov 2013 13:30]
Paul Keenan
Thanks for taking the time to look into this. I meant to make the wording a little clearer on the bug report. It's certainly the case that whether the statement is deterministic depends on what's mentioned in the ORDER BY and the contents of the table. However, in the case where the ORDER BY contains all of the columns in the SELECT statement, then it's guaranteed to be deterministic. I thought that's what MySQL must be doing behind the scenes when I read the documentation "Statement-based replication of AUTO_INCREMENT [...] is done correctly, subject to [...]". The same page also mentions (although under the ALTER TABLE example) "Important - To guarantee the same ordering on both master and slave, the ORDER BY clause must name all columns of t1." This confirmed my belief that this optimisation would cause statement based replication to work. FYI, I've been trying to use MIXED mode replication for my production database, but am having separate issues there where statements executed quickly on the master never complete on the slave depsite identical setups (h/w, s/w, tables & data). I therefore am using statement based, which I know will work for my queries because I can see that the statement is deterministic. I get the warnings but my reading of the documentation suggested that MySQL shouldn't produce them in this case. If it can't be fixed easily, I would suggest another course of action would be to reword the documentation so that it's clear that any INSERT INTO ... SELECT will be marked as Unsafe for replication. I'd obviously prefer if the statement wasn't marked as Unsafe in cases like the example given. I'd also suggest changing the wording in error 1592 regardless of the outcome. It's not accurate to say the the order cannot be predicted. Perhaps change "cannot" to "cannot always". Cheers, Paul