Bug #119156 Query returns incorrect result (12 vs 2) when using FORCE INDEX compared to optimizer's automatic index selection, when
Submitted: 15 Oct 2025 2:01 Modified: 13 Jan 11:13
Reporter: Alice Alice Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.41 OS:CentOS
Assigned to: Øystein Grøvlen CPU Architecture:x86

[15 Oct 2025 2:01] Alice Alice
Description:
I discovered a very interesting phenomenon. On a small data table I constructed, when I execute the following statement:
SELECT count(*) FROM tb3 WHERE (tb3.c20 = '') OR (b'00111000001100110011100000111010001101010011100100111010001101010011100100101110001110010011100100111001' >= tb3.c10) ORDER BY 1;
The optimizer chooses the tb3_ind_19 index I set up, and the returned result is correct at this point.

However, when I use FORCE INDEX in the statement to specify the tb3_ind_19 index, the optimizer chooses a full table scan, but the returned result is incorrect at this point. The statement is as follows - the only difference between the two is the FORCE INDEX command:
SELECT count(*) FROM tb3 FORCE INDEX (tb3_ind_19) WHERE (tb3.c20 = '') OR (b'00111000001100110011100000111010001101010011100100111010001101010011100100101110001110010011100100111001' >= tb3.c10) ORDER BY 1;

The specific execution plan and query results are as follows:

mysql> explain SELECT count(*) FROM tb3  WHERE (tb3.c20 = '') OR (b'00111000001100110011100000111010001101010011100100111010001101010011100100101110001110010011100100111001' >= tb3.c10) ORDER BY 1;
+----+-------------+-------+------------+-------+----------------------+------------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type  | possible_keys        | key        | key_len | ref  | rows | filtered | Extra       |
+----+-------------+-------+------------+-------+----------------------+------------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | tb3   | NULL       | range | tb3_ind_9,tb3_ind_19 | tb3_ind_19 | 255     | NULL |    1 |   100.00 | Using where |
+----+-------------+-------+------------+-------+----------------------+------------+---------+------+------+----------+-------------+
1 row in set, 3 warnings (0.00 sec)

mysql> SELECT count(*) FROM tb3  WHERE (tb3.c20 = '') OR (b'00111000001100110011100000111010001101010011100100111010001101010011100100101110001110010011100100111001' >= tb3.c10) ORDER BY 1;
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set, 2 warnings (0.00 sec)

mysql> explain SELECT count(*) FROM tb3 FORCE INDEX (tb3_ind_19)  WHERE (tb3.c20 = '') OR (b'00111000001100110011100000111010001101010011100100111010001101010011100100101110001110010011100100111001' >= tb3.c10) ORDER BY 1;
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | tb3   | NULL       | ALL  | tb3_ind_19    | NULL | NULL    | NULL |   20 |    21.25 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 3 warnings (0.00 sec)

mysql> SELECT count(*) FROM tb3 FORCE INDEX (tb3_ind_19)  WHERE (tb3.c20 = '') OR (b'00111000001100110011100000111010001101010011100100111010001101010011100100101110001110010011100100111001' >= tb3.c10) ORDER BY 1;
+----------+
| count(*) |
+----------+
|       12 |
+----------+
1 row in set, 3 warnings (0.00 sec)

How to repeat:
"Sorry, when I tried to simplify the use case, I was unable to reproduce the issue." So I can only provide you with the complete reproduction steps.
create table tb3 (c1 tinyint, 
c2 tinyint unsigned, 
c3 smallint, 
c4 smallint unsigned, 
c5 integer, 
c6 integer unsigned, 
c7 bigint, 
c8 bigint unsigned, 
c9 mediumint, 
c10 mediumint unsigned, 
c11 float, 
c12 double, 
c13 decimal(60,30), 
c14 boolean, 
c15 binary, 
c16 varbinary(64), 
c17 blob, 
c18 char, 
c19 varchar(64), 
c20 text, 
c21 date, 
c22 time, 
c23 time(3), 
c24 time(6), 
c25 datetime, 
c26 datetime(3), 
c27 datetime(6), 
c28 timestamp, 
c29 timestamp(3), 
c30 timestamp(6), 
c31 year, 
c32 bit, 
c33 json, 
c34 enum('1','abc','@#$',' ','111111111111111111','-111111111111111111','1970-1-1','-838:59:59.000000','1901','-9223372036854775808','0','9223372036854775807','-9223372036854775807','9e99'), 
c35 set('1','abc','@#$',' ','111111111111111111','-111111111111111111','1970-1-1','-838:59:59.000000','1901','0','9e99')) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

insert into tb3 values (-128,0,-32768,0,-2147483648,0,-9223372036854775808,0,-8388608,0,-9999999999.9999999999,-9999999999.9999999999,-9999999999.9999999999,0,b'0',b'10111111111',' 高斯aA!@#¥%……&*()—+-=,./<>[]{;:| ','a',' 高斯aA!@#¥%……&*()—+-=,./<>[]{;:| ',' 高斯aA!@#¥%……&*()—+-=,./<>[]{;:| ','1970-1-1','-838:59:59.000000','-838:59:59','-838:59:59','1000-01-01 00:00:00','1000-01-01 00:00:00.000','1000-01-01 00:00:00.000000',timestamp('1970-01-02 00:00:01'),timestamp('1970-01-02 00:00:01.000'),timestamp('1970-01-02 00:00:01.000000'),'1901',b'0','{}','','');
insert into tb3 values (0,255,0,65535,0,4294967295,0,18446744073709551615,0,16777215,0,0,0,1,b'1',b'111111111000000000000','','#','','','2069-12-31','838:59:59.000000','838:59:59','838:59:59','1000-01-01 00:00:01','1000-01-01 00:00:00.001','1000-01-01 00:00:00.000001',timestamp('2038-01-19 03:14:07'),timestamp('2038-01-19 03:14:07.000'),timestamp('2038-01-19 03:14:07.000000'),'2155',b'1','111111111111111111',' ','111111111111111111');
insert into tb3 values (127,255,32767,65535,2147483647,0,9223372036854775807,999999999999999999,8388607,0,9999999999.9999999999,9999999999.9999999999,9999999999.9999999999,0,b'0',b'111111111000000000000',' ','0',' ',' ','2024-12-31','00:00:00','00:00:00.000','00:00:00.000000','9999-12-31 23:59:59','9999-12-31 23:59:59.999','9999-12-31 23:59:59.999999',timestamp('2024-12-31 23:59:59'),timestamp('2024-12-31 23:59:59.999'),timestamp('2024-12-31 23:59:59.999999'),'2024',b'0','-111111111111111111','111111111111111111','-111111111111111111');
insert into tb3 values (0,255,0,0,2147483647,0,999999999999999999,999999999999999999,8388607,16777215,-99999999999999999.99999999999999999999,-99999999999999999.99999999999999999999,-99999999999999999.99999999999999999999,0,b'1',b'111111111000000000000',repeat('{', 255),'1',repeat('9', 17),repeat('{', 255),'2025-01-01','-00:00:00','-00:00:00.000','-00:00:00.000000','2024-12-31 23:59:59','2024-12-31 23:59:59.999','2024-12-31 23:59:59.999999',timestamp('2025-01-01 00:00:00'),timestamp('2025-01-01 00:00:00.000'),timestamp('2025-01-01 00:00:00.000000'),'2025',b'1','1901','-111111111111111111','1970-1-1');
insert into tb3 values (0,0,32767,65535,2147483647,4294967295,-999999999999999999,0,0,0,99999999999999999.99999999999999999999,99999999999999999.99999999999999999999,99999999999999999.99999999999999999999,1,b'1',b'10111111111',repeat('9', 255),'9',repeat('1', 17),repeat('9', 255),'2016-12-31','23:59:59','00:00:00.001','00:00:00.000001','2025-01-01 00:00:00','2025-01-01 00:00:00.000','2025-01-01 00:00:00.000000',timestamp('2025-01-01 00:00:01'),timestamp('2025-01-01 00:00:00.001'),timestamp('2025-01-01 00:00:00.000001'),'2016',b'0','0','1970-1-1','-838:59:59.000000');
insert into tb3 values (0,0,-32768,65535,-2147483648,4294967295,-9223372036854775807,18446744073709551615,0,0,-99999999999999999.99999999999999999999,99999999999999999,99999999999999999,0,b'0',b'111111111000000000000',repeat('9', 17),'#',' 高斯aA!@#¥%……&*()—+-=,./<>[]{;:| ',repeat('9', 17),'2020-02-29','-23:59:59','-00:00:00.001','-00:00:00.000001','2025-01-01 00:00:01','2025-01-01 00:00:00.001','2025-01-01 00:00:00.000001',timestamp('2016-12-31 23:59:59'),timestamp('2025-01-01 00:00:01.000'),timestamp('2025-01-01 00:00:01.000000'),'2020',b'0','9e99','-838:59:59.000000','1901');
insert into tb3 values (127,255,-32768,0,-2147483648,0,-9223372036854775807,18446744073709551615,-8388608,0,-99999999999999999.99999999999999999999,-99999999999999999,-99999999999999999,1,b'0',b'10111111111',repeat('1', 255),'1',repeat('1', 17),repeat('1', 255),'2020-03-01','00:00:01','23:59:59.999','23:59:59.999999','2016-12-31 23:59:59','2025-01-01 00:00:01.000','2025-01-01 00:00:01.000000',timestamp('2020-02-29 23:59:59'),timestamp('2016-12-31 23:59:59.999'),timestamp('2016-12-31 23:59:59.999999'),'1901',b'1','{}','1901','0');
insert into tb3 values (127,0,0,65535,0,4294967295,9223372036854775807,0,0,0,9999999999.9999999999,-9999999999.9999999999,-9999999999.9999999999,1,b'1',b'10111111111',repeat('1', 17),'a',repeat('9', 17),repeat('1', 17),'2025-01-01','-00:00:01','-23:59:59.999','-23:59:59.999999','2020-02-29 23:59:59','2016-12-31 23:59:59.000','2016-12-31 23:59:59.000000',timestamp('2020-03-01 00:00:00'),timestamp('2020-02-29 23:59:59.000'),timestamp('2020-02-29 23:59:59.000000'),'1901',b'0','{}','-9223372036854775808','9e99');
insert into tb3 values (127,255,32767,0,0,4294967295,-9223372036854775807,999999999999999999,8388607,16777215,99999999999999999.99999999999999999999,9999999999.9999999999,-99999999999999999,0,b'0',b'10111111111',repeat('9', 17),'1',repeat('1', 17),repeat('9', 17),'2016-12-31','23:59:59','00:00:01.000','00:00:01.000000','2020-03-01 00:00:00','2020-02-29 23:59:59.999','2020-02-29 23:59:59.999999',timestamp('2020-03-01 00:00:01'),timestamp('2020-03-01 00:00:00.000'),timestamp('2020-03-01 00:00:00.000000'),'2155',b'1','1901','0','0');
insert into tb3 values (-128,0,0,0,0,4294967295,-9223372036854775808,0,-8388608,16777215,-9999999999.9999999999,-99999999999999999.99999999999999999999,99999999999999999.99999999999999999999,1,b'0',b'10111111111',repeat('1', 255),'a',' ','','2020-03-01','-838:59:59.000000','-00:00:01.000','-00:00:01.000000','2020-03-01 00:00:01','2020-03-01 00:00:00.000','2020-03-01 00:00:00.000000',timestamp('2020-03-01 00:00:00'),timestamp('2020-03-01 00:00:00.001'),timestamp('2020-03-01 00:00:00.000001'),'2024',b'1','111111111111111111','9223372036854775807','-111111111111111111');
insert into tb3 values (127,255,0,65535,0,0,999999999999999999,999999999999999999,0,0,0,0,9999999999.9999999999,0,b'1',b'10111111111',repeat('9', 255),'1',repeat('1', 17),' 高斯aA!@#¥%……&*()—+-=,./<>[]{;:| ','2024-12-31','-00:00:00','00:00:01.001','00:00:01.000001','2020-02-29 23:59:59','2020-03-01 00:00:00.001','2020-03-01 00:00:00.000001',timestamp('2024-12-31 23:59:59'),timestamp('2020-03-01 00:00:01.000'),timestamp('2020-03-01 00:00:01.000000'),'2016',b'1','111111111111111111','9e99','9e99');
insert into tb3 values (0,255,-32768,65535,0,4294967295,999999999999999999,999999999999999999,-8388608,16777215,-9999999999.9999999999,99999999999999999,0,0,b'1',b'10111111111',repeat('{', 255),'#',' 高斯aA!@#¥%……&*()—+-=,./<>[]{;:| ',repeat('1', 17),'2020-02-29','00:00:00','-00:00:01.001','-00:00:01.000001','2024-12-31 23:59:59','2020-03-01 00:00:01.000','2020-03-01 00:00:01.000000',timestamp('2020-03-01 00:00:01'),timestamp('2025-01-01 00:00:01.000'),timestamp('2025-01-01 00:00:00.000000'),'1901',b'1','9e99','0','-111111111111111111');
insert into tb3 values (0,0,32767,0,-2147483648,4294967295,-999999999999999999,0,8388607,16777215,-99999999999999999.99999999999999999999,-9999999999.9999999999,0,0,b'1',b'10111111111',' ','1',repeat('1', 17),repeat('9', 17),'2020-02-29','-838:59:59.000000','-00:00:01.000','-00:00:01.000000','2025-01-01 00:00:00','2025-01-01 00:00:01.000','2020-03-01 00:00:01.000000',timestamp('2020-03-01 00:00:01'),timestamp('2020-03-01 00:00:00.000'),timestamp('2016-12-31 23:59:59.999999'),'2020',b'1','-111111111111111111','-9223372036854775808','1970-1-1');
insert into tb3 values (127,255,0,65535,0,4294967295,-999999999999999999,18446744073709551615,-8388608,16777215,-9999999999.9999999999,9999999999.9999999999,99999999999999999.99999999999999999999,1,b'0',b'111111111000000000000',repeat('9', 255),'1',repeat('9', 17),' 高斯aA!@#¥%……&*()—+-=,./<>[]{;:| ','2020-02-29','-838:59:59.000000','-00:00:01.001','-838:59:59','1000-01-01 00:00:01','1000-01-01 00:00:00.001','2020-03-01 00:00:00.000001',timestamp('2025-01-01 00:00:01'),timestamp('2025-01-01 00:00:00.000'),timestamp('2016-12-31 23:59:59.999999'),'2016',b'0','-111111111111111111','9e99','');
insert into tb3 values (0,255,0,65535,2147483647,0,9223372036854775807,18446744073709551615,0,16777215,-99999999999999999.99999999999999999999,99999999999999999,99999999999999999,0,b'0',b'111111111000000000000',repeat('9', 255),'1',repeat('1', 17),repeat('1', 17),'2016-12-31','-838:59:59.000000','-838:59:59','00:00:00.000001','2016-12-31 23:59:59','2020-03-01 00:00:01.000','1000-01-01 00:00:00.000001',timestamp('2020-02-29 23:59:59'),timestamp('2025-01-01 00:00:01.000'),timestamp('1970-01-02 00:00:01.000000'),'2155',b'0','0','0','0');
insert into tb3 values (127,255,32767,0,2147483647,4294967295,-9223372036854775808,999999999999999999,0,0,99999999999999999.99999999999999999999,-99999999999999999,99999999999999999,0,b'1',b'111111111000000000000','','a','',' ','2069-12-31','00:00:00','-00:00:01.001','-00:00:00.000001','2020-02-29 23:59:59','2025-01-01 00:00:00.000','2024-12-31 23:59:59.999999',timestamp('2016-12-31 23:59:59'),timestamp('2020-03-01 00:00:00.000'),timestamp('2016-12-31 23:59:59.999999'),'1901',b'0','{}','1901','-111111111111111111');
insert into tb3 values (127,255,0,0,0,0,-999999999999999999,999999999999999999,0,16777215,-99999999999999999.99999999999999999999,99999999999999999,-99999999999999999.99999999999999999999,0,b'1',b'10111111111',' ','1',repeat('9', 17),repeat('9', 255),'2024-12-31','-00:00:00','-838:59:59','00:00:00.000001','2024-12-31 23:59:59','2016-12-31 23:59:59.000','2020-02-29 23:59:59.999999',timestamp('2024-12-31 23:59:59'),timestamp('2025-01-01 00:00:01.000'),timestamp('2025-01-01 00:00:00.000001'),'2020',b'0','0','-111111111111111111','-111111111111111111');
insert into tb3 values (0,255,32767,65535,0,4294967295,999999999999999999,999999999999999999,0,0,0,-9999999999.9999999999,-9999999999.9999999999,1,b'1',b'111111111000000000000','','#','',repeat('{', 255),'2016-12-31','00:00:01','00:00:00.000','23:59:59.999999','1000-01-01 00:00:00','2020-03-01 00:00:00.000','2020-03-01 00:00:01.000000',timestamp('2016-12-31 23:59:59'),timestamp('2024-12-31 23:59:59.999'),timestamp('1970-01-02 00:00:01.000000'),'2016',b'0','111111111111111111','111111111111111111','9e99');
insert into tb3 values (-128,255,-32768,65535,0,4294967295,0,18446744073709551615,0,16777215,-99999999999999999.99999999999999999999,99999999999999999,-99999999999999999.99999999999999999999,1,b'0',b'10111111111',repeat('9', 17),'1',repeat('9', 17),repeat('{', 255),'2020-03-01','-00:00:00','00:00:00.000','-00:00:00.000000','2020-02-29 23:59:59','9999-12-31 23:59:59.999','2020-03-01 00:00:00.000001',timestamp('2020-03-01 00:00:01'),timestamp('2020-03-01 00:00:00.001'),timestamp('2020-03-01 00:00:00.000001'),'1901',b'0','-111111111111111111','-9223372036854775808','111111111111111111');
insert into tb3 values (127,0,-32768,65535,0,0,-999999999999999999,999999999999999999,-8388608,0,0,99999999999999999.99999999999999999999,9999999999.9999999999,1,b'0',b'111111111000000000000',repeat('{', 255),'#',' 高斯aA!@#¥%……&*()—+-=,./<>[]{;:| ',' ','2016-12-31','-00:00:01','00:00:00.001','-00:00:01.000000','2025-01-01 00:00:00','2020-03-01 00:00:00.001','2024-12-31 23:59:59.999999',timestamp('2038-01-19 03:14:07'),timestamp('2025-01-01 00:00:00.000'),timestamp('2016-12-31 23:59:59.999999'),'2024',b'0','111111111111111111','-9223372036854775808','-111111111111111111');

create index tb3_ind_0 on tb3(c1);
create index tb3_ind_1 on tb3(c2);
create index tb3_ind_2 on tb3(c3);
create index tb3_ind_3 on tb3(c4);
create index tb3_ind_4 on tb3(c5);
create index tb3_ind_5 on tb3(c6);
create index tb3_ind_6 on tb3(c7);
create index tb3_ind_7 on tb3(c8);
create index tb3_ind_8 on tb3(c9);
create index tb3_ind_9 on tb3(c10);
create index tb3_ind_10 on tb3(c11);
create index tb3_ind_11 on tb3(c12);
create index tb3_ind_12 on tb3(c13);
create index tb3_ind_13 on tb3(c14);
create index tb3_ind_14 on tb3(c15);
create index tb3_ind_15 on tb3(c16);
create index tb3_ind_16 on tb3(c17(63));
create index tb3_ind_17 on tb3(c18);
create index tb3_ind_18 on tb3(c19);
create index tb3_ind_19 on tb3(c20(63));
create index tb3_ind_20 on tb3(c21);
create index tb3_ind_21 on tb3(c22);
create index tb3_ind_22 on tb3(c23);
create index tb3_ind_23 on tb3(c24);
create index tb3_ind_24 on tb3(c25);
create index tb3_ind_25 on tb3(c26);
create index tb3_ind_26 on tb3(c27);
create index tb3_ind_27 on tb3(c28);
create index tb3_ind_28 on tb3(c29);
create index tb3_ind_29 on tb3(c30);
create index tb3_ind_30 on tb3(c31);
create index tb3_ind_31 on tb3(c32);
create index tb3_ind_33 on tb3(c34);
create index tb3_ind_34 on tb3(c35);
[13 Jan 11:13] Øystein Grøvlen
Thank you for the bug report.
Verified as described.