Bug #118092 The query result using index is different with not used index
Submitted: 30 Apr 3:31 Modified: 30 Apr 5:36
Reporter: Alice Alice Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S2 (Serious)
Version:8.0.41, 8.0.42, 8.4.5, 9.3.0 OS:Linux
Assigned to: CPU Architecture:Any

[30 Apr 3:31] Alice Alice
Description:
mysql> drop table if exists tt1;
Query OK, 0 rows affected (0.05 sec)

mysql> CREATE TABLE `tt1` (
    -> `char_col` char(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL,
    -> `bit_col` bit(8) DEFAULT b'0',
    -> KEY `ndx_bit_col` (`bit_col`),
    -> FULLTEXT KEY `ndx_char_col` (`char_col`)
    -> ) ENGINE=InnoDB;
Query OK, 0 rows affected, 2 warnings (0.14 sec)

mysql> insert into tt1 values("aaaa", 0xF0),("aaaa", 0xAA),("aaaa", 0x99),("aaaa", 0x00),("aabb", 0xF0),("aabb", 0xAA),("aabb", 0x99),("aabb", 0x00),("aacd", 0xF0),("aacd", 0xAA),("aacd", 0x99),("aacd", 0x00),(NULL, 0xF0),(NULL, 0xAA),(NULL,0x99),(NULL, 0x00);
Query OK, 16 rows affected (0.00 sec)
Records: 16  Duplicates: 0  Warnings: 0

mysql> drop table if exists tt2;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE `tt2` (
    -> `char_col` char(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL,
0xAA),("aabb", 0x99),("aabb", 0x00),("aacd", 0xF0),("aacd", 0xAA),("aacd", 0x99),("aacd", 0x00),(NULL, 0xF0),(NULL, 0xAA),(NULL,0x99),(NULL, 0x00);    -> `bit_col` bit(8) DEFAULT b'0'
    -> ) ENGINE=InnoDB;
Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> insert into tt2 values("aaaa", 0xF0),("aaaa", 0xAA),("aaaa", 0x99),("aaaa", 0x00),("aabb", 0xF0),("aabb", 0xAA),("aabb", 0x99),("aabb", 0x00),("aacd", 0xF0),("aacd", 0xAA),("aacd", 0x99),("aacd", 0x00),(NULL, 0xF0),(NULL, 0xAA),(NULL,0x99),(NULL, 0x00);
Query OK, 16 rows affected (0.01 sec)
Records: 16  Duplicates: 0  Warnings: 0

mysql> SELECT count(*) FROM tt1 AS A force index(ndx_bit_col) right join tt2 AS B ON A.bit_col=B.char_col;
+----------+
| count(*) |
+----------+
|       16 |
+----------+
1 row in set (0.01 sec)

mysql> SELECT count(*) FROM tt1 AS A ignore index(ndx_bit_col) right join tt2 AS B ON A.bit_col=B.char_col;
+----------+
| count(*) |
+----------+
|       52 |
+----------+
1 row in set, 12 warnings (0.00 sec)

How to repeat:
drop table if exists tt1;
CREATE TABLE `tt1` (
`char_col` char(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`bit_col` bit(8) DEFAULT b'0',
KEY `ndx_bit_col` (`bit_col`),
FULLTEXT KEY `ndx_char_col` (`char_col`)
) ENGINE=InnoDB;
insert into tt1 values("aaaa", 0xF0),("aaaa", 0xAA),("aaaa", 0x99),("aaaa", 0x00),("aabb", 0xF0),("aabb", 0xAA),("aabb", 0x99),("aabb", 0x00),("aacd", 0xF0),("aacd", 0xAA),("aacd", 0x99),("aacd", 0x00),(NULL, 0xF0),(NULL, 0xAA),(NULL,0x99),(NULL, 0x00);

drop table if exists tt2;
CREATE TABLE `tt2` (
`char_col` char(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`bit_col` bit(8) DEFAULT b'0'
) ENGINE=InnoDB;
insert into tt2 values("aaaa", 0xF0),("aaaa", 0xAA),("aaaa", 0x99),("aaaa", 0x00),("aabb", 0xF0),("aabb", 0xAA),("aabb", 0x99),("aabb", 0x00),("aacd", 0xF0),("aacd", 0xAA),("aacd", 0x99),("aacd", 0x00),(NULL, 0xF0),(NULL, 0xAA),(NULL,0x99),(NULL, 0x00);

SELECT count(*) FROM tt1 AS A force index(ndx_bit_col) right join tt2 AS B ON A.bit_col=B.char_col;  --with index
SELECT count(*) FROM tt1 AS A ignore index(ndx_bit_col) right join tt2 AS B ON A.bit_col=B.char_col;   --without index
[30 Apr 5:36] MySQL Verification Team
Hello Alice Alice,

Thank you for the report and feedback.

regards,
Umesh
[20 May 12:12] MySQL Verification Team
Bug #118200 marked as duplicate of this one
[4 Jun 11:36] MySQL Verification Team
Bug #118348 marked as duplicate of this one
[6 Aug 12:47] MySQL Verification Team
Bug #118625 marked as duplicate of this one
[6 Aug 12:51] MySQL Verification Team
Bug #118571 marked as duplicate of this one