[MDEV-21240] found_rows return incorrect value when using aggregate function Created: 2019-12-06  Updated: 2023-04-27

Status: Confirmed
Project: MariaDB Server
Component/s: Data Definition - Procedure
Affects Version/s: 5.5, 10.0, 10.1, 10.4.8, 10.2, 10.3, 10.4
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Jérôme Brauge Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Centos 7


Attachments: File mdev21240.sql    

 Description   

In a stored procedure , Select with an aggregate fonction without group by expression and using an index result in a wrong value of found_rows().



 Comments   
Comment by Alice Sherepa [ 2019-12-17 ]

Thanks for the report! Reproducible on 5.5-10.4:

create table t1 (c1 varchar(30),c2 varchar(150),unique index t1_idx (c2,c1));
insert into t1 values ('a','a'),('b','b'),('c','c');
 
delimiter |;
create procedure p1()
begin
  declare x varchar(30);
  select max(c1) into @x from t1 where c2='a';
  select found_rows();
  select @x;
end;
|
 
delimiter ;|
call p1();
drop index t1_idx on t1;
call p1();
 
drop procedure p1;
drop table t1;

MariaDB [test]> call p1();
+--------------+
| found_rows() |
+--------------+
|            0 |
+--------------+
1 row in set (0.001 sec)
 
+------+
| @x   |
+------+
| a    |
+------+
1 row in set (0.001 sec)
 
Query OK, 1 row affected (0.001 sec)
 
MariaDB [test]> drop index t1_idx on t1;
Query OK, 0 rows affected (0.020 sec)
Records: 0  Duplicates: 0  Warnings: 0
 
MariaDB [test]> call p1();
+--------------+
| found_rows() |
+--------------+
|            1 |
+--------------+
1 row in set (0.000 sec)
 
+------+
| @x   |
+------+
| a    |
+------+
1 row in set (0.000 sec)
 
Query OK, 1 row affected (0.000 sec)

Generated at Thu Feb 08 09:05:39 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.