Bug #118808 Different result with range scan and table scan in sql with subquery

Submitted: 10 Aug 2025 11:26 Modified: 11 Aug 2025 6:36
Reporter: zkong kong Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:9.4.0, 8.4.3, 8.4.6 OS:Any
Assigned to: CPU Architecture:Any
Tags: regression

[10 Aug 2025 11:26] zkong kong
Description:
mysql> select count(*) from t2 where c < (select c from t1);
+----------+
| count(*) |
+----------+
|      972 |
+----------+
1 row in set (0.001 sec)

mysql> select count(*) from t2 ignore index(k1) where c < (select c from t1);
+----------+
| count(*) |
+----------+
|      999 |
+----------+
1 row in set (0.001 sec)

How to repeat:
create table t1(id int primary key, c date);

insert into t1 values(1,'1972-03-18');

create table t2(id int primary key, c int, key k1(c));

delimiter $$
create procedure load_data()
begin
declare v_max int unsigned default 1000;
declare v_counter int unsigned default 1;
  while v_counter < v_max do
    insert into t2 (id, c) values (v_counter, v_counter + 1000);
    set v_counter=v_counter+1;
  end while;
  commit;
end 
$$

delimiter ;

call load_data();

select count(*) from t2 where c < (select c from t1);

select count(*) from t2 ignore index(k1) where c < (select c from t1);

The result of the two sql is 972 and 999
[11 Aug 2025 6:36] MySQL Verification Team
Hello zkong kong,

Thank you for the report and test case.
Verified as described.

regards,
Umesh

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.054 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.