Bug #68194 | Wrong result (missing row) with index_merge | ||
---|---|---|---|
Submitted: | 27 Jan 2013 22:50 | Modified: | 31 Jan 2013 16:03 |
Reporter: | Elena Stepanova | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.1, 5.5, 5.6.9 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[27 Jan 2013 22:50]
Elena Stepanova
[27 Jan 2013 22:54]
Elena Stepanova
Sorry, the last fragment in the test is not needed, it's just a duplicate remained from an intermediate test case (starting from the second 'SET optimizer_switch').
[28 Jan 2013 12:02]
Simon Martin
I think the bug on the reported test case is when index_merge is off. The final "AND ( f4 LIKE 'Wyoming' OR f5 LIKE 'Oregon' )" is outside the OR so should be satisfied along with the PK condition, but in the returned result with index_merge=off it is not. However if you move the bracket to put the last AND inside the OR the bug seems to move, as now index_merge=on still returns no result (which it should I think). So the bug as stated by Elena is there too? On 5.5: mysql> set query_cache_type = 0; Query OK, 0 rows affected (0.00 sec) mysql> set optimizer_switch='index_merge=on'; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM t1 WHERE -> pk IN ( 255, 2, 193, 255, 106 ) -> OR ( -> ( f5 IN ( 'why' , 'uv' ) OR NOT ( f4 = 'mm' ) ) -> AND -> ( ( pk = 1 ) OR f1 NOT BETWEEN 8 AND 3 + 133 ) -> ) -> AND ( f4 LIKE 'Wyoming' OR f5 LIKE 'Oregon' ) -> ; Empty set (0.00 sec) mysql> set optimizer_switch='index_merge=off'; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM t1 WHERE -> pk IN ( 255, 2, 193, 255, 106 ) -> OR ( -> ( f5 IN ( 'why' , 'uv' ) OR NOT ( f4 = 'mm' ) ) -> AND -> ( ( pk = 1 ) OR f1 NOT BETWEEN 8 AND 3 + 133 ) -> ) -> AND ( f4 LIKE 'Wyoming' OR f5 LIKE 'Oregon' ) -> ; +----+------+------+------+------+------+ | pk | f1 | f2 | f3 | f4 | f5 | +----+------+------+------+------+------+ | 2 | 345 | 123 | h | M | w | +----+------+------+------+------+------+ 1 row in set (0.00 sec) mysql> set optimizer_switch='index_merge=on'; Query OK, 0 rows affected (0.00 sec) mysql> SELECT sql_no_cache * FROM t1 WHERE -> pk IN ( 255, 2, 193, 255, 106 ) -> OR ( -> ( f5 IN ( 'why' , 'uv' ) OR NOT ( f4 = 'mm' ) ) -> AND -> ( ( pk = 1 ) OR f1 NOT BETWEEN 8 AND 3 + 133 ) -> AND -> ( f4 LIKE 'Wyoming' OR f5 LIKE 'Oregon' ) -> ) -> ; Empty set (0.00 sec) mysql> mysql> set optimizer_switch='index_merge=off'; Query OK, 0 rows affected (0.00 sec) mysql> SELECT sql_no_cache * FROM t1 WHERE -> pk IN ( 255, 2, 193, 255, 106 ) -> OR ( -> ( f5 IN ( 'why' , 'uv' ) OR NOT ( f4 = 'mm' ) ) -> AND -> ( ( pk = 1 ) OR f1 NOT BETWEEN 8 AND 3 + 133 ) -> AND -> ( f4 LIKE 'Wyoming' OR f5 LIKE 'Oregon' ) -> ) -> ; +----+------+------+------+------+------+ | pk | f1 | f2 | f3 | f4 | f5 | +----+------+------+------+------+------+ | 2 | 345 | 123 | h | M | w | +----+------+------+------+------+------+ 1 row in set (0.00 sec)
[28 Jan 2013 13:07]
MySQL Verification Team
Thank you for the bug report. mysql 5.5 > SELECT sql_no_cache * FROM t1 WHERE -> pk IN ( 255, 2, 193, 255, 106 ) -> OR ( -> ( f5 IN ( 'why' , 'uv' ) OR NOT ( f4 = 'mm' ) ) -> AND -> ( ( pk = 1 ) OR f1 NOT BETWEEN 8 AND 3 + 133 ) -> AND -> ( f4 LIKE 'Wyoming' OR f5 LIKE 'Oregon' ) -> ) -> ; +----+------+------+------+------+------+ | pk | f1 | f2 | f3 | f4 | f5 | +----+------+------+------+------+------+ | 2 | 345 | 123 | h | M | w | +----+------+------+------+------+------+ 1 row in set (0.00 sec) mysql 5.5 >show variables like "%version%"; +-------------------------+---------------------+ | Variable_name | Value | +-------------------------+---------------------+ | innodb_version | 5.5.31 | | protocol_version | 10 | | slave_type_conversions | | | version | 5.5.31 | | version_comment | Source distribution | | version_compile_machine | x86 | | version_compile_os | Win64 | +-------------------------+---------------------+ 7 rows in set (0.00 sec)
[28 Jan 2013 13:36]
Elena Stepanova
@Godofredo Miguel Solorzano Hi, I don't quite understand the verification comment -- do you consider the *non*-empty result set to be a bug? Not sure how you got it though, is it with index_merge ON or OFF? Or do you mean that it's been already fixed in 5.5.31 (why 'verified', then?) @Simon Martin Hi, Given the order of precedence for OR and AND, your change does not make a difference. In an essence, we initially have A || ( ( B || C ) && ( D || E ) ) && ( F || G ) so, A is self-sufficient. They all are equivalents A || ( ( B || C ) && ( D || E ) ) && ( F || G ) A || ( B || C ) && ( D || E ) && ( F || G ) A || ( ( B || C ) && ( D || E ) && ( F || G ) ) The last of which is yours.
[28 Jan 2013 14:24]
Simon Martin
@Elena Thanks, you're right of course. I missed that.
[28 Jan 2013 14:51]
Jørgen Løland
@Elena: The bug is confirmed as described. Thank you for the bug report.
[28 Jan 2013 15:58]
MySQL Verification Team
@Elena the bug was verified, sorry I pasted partial results. Thanks.
[31 Jan 2013 16:03]
Paul DuBois
Noted in 5.6.11 changelog. A bug in range optimization sometimes led to incorrect condition calculation for index merge union. This could lead to missing rows.