[MDEV-7219] SQL_CALC_FOUND_ROWS yields wrong result Created: 2014-11-26  Updated: 2015-01-19  Resolved: 2015-01-19

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.0.12, 10.0.15
Fix Version/s: 10.0.16

Type: Bug Priority: Major
Reporter: Lance Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: None
Environment:

CentOS 6.6 x64


Attachments: Text File found_rows_bug.sql.txt    
Issue Links:
Relates
relates to MDEV-4711 SQL_CALC_FOUND_ROWS yields wrong result Closed
relates to MDEV-5549 Wrong row counter in found_rows() result Closed
relates to MDEV-5898 FOUND_ROWS() return incorrect value w... Closed
relates to MDEV-6221 SQL_CALC_FOUND_ROWS yields wrong resu... Closed
relates to MDEV-6230 Error (too many FOUND_ROWS) for query... Closed

 Description   

SQL_CALC_FOUND_ROWS returns various results depending on table definition, KEY and ORDER BY.



 Comments   
Comment by Elena Stepanova [ 2014-11-27 ]

The problem (re-?)appeared on the 10.0 tree with this revision:

revno: 4226
revision-id: sergii@pisem.net-20140605135941-ytyt69i971b3syle
parent: sergii@pisem.net-20140605135935-vlj5qhr4yr8lp2fn
committer: Sergei Golubchik <sergii@pisem.net>
branch nick: 10.0
timestamp: Thu 2014-06-05 15:59:41 +0200
message:
  revert the fix for MDEV-5898, restore the fix for MDEV-5549.
  simplify test case for MDEV-5898

Test case (exactly the same as in the attachment, just made it MTR-like). For all SELECT FOUND_ROWS() queries the expected result is 75.

DROP DATABASE IF EXISTS bugtest;
CREATE DATABASE bugtest;
USE bugtest;
 
--delimiter //
 
  CREATE PROCEDURE fill_bugtable (len INT)
  BEGIN
    DECLARE i INT DEFAULT 1;
    WHILE i <= len DO
      INSERT INTO bugtable (bugtable_varchar, bugtable_int) VALUES ("foo", i%2);
      SET i = i + 1;
    END WHILE;
  END //
 
--delimiter ;
 
--echo # Tests to reproduce Bug #1 ------------------------------------------------
 
CREATE TABLE `bugtable` (
  `bugtable_int` int,
  `bugtable_varchar` varchar(64),
  KEY (`bugtable_int`)
) ENGINE=MyISAM CHARSET=latin1 COLLATE=latin1_general_ci;
 
CALL fill_bugtable(150);
 
SELECT SQL_CALC_FOUND_ROWS * FROM bugtable WHERE `bugtable_int` = 0 ORDER BY bugtable_varchar LIMIT 59,2;
SELECT FOUND_ROWS();
 
SELECT SQL_CALC_FOUND_ROWS * FROM bugtable WHERE `bugtable_int` = 0 ORDER BY bugtable_varchar LIMIT 60,2;
SELECT FOUND_ROWS();
 
--echo # Tests to reproduce Bug #2 ------------------------------------------------
 
ALTER TABLE `bugtable` DROP INDEX `bugtable_int`;
 
SELECT SQL_CALC_FOUND_ROWS * FROM bugtable WHERE `bugtable_int` = 0 ORDER BY bugtable_varchar LIMIT 59,2;
SELECT FOUND_ROWS();
 
SELECT SQL_CALC_FOUND_ROWS * FROM bugtable WHERE `bugtable_int` = 0 ORDER BY bugtable_varchar LIMIT 60,2;
SELECT FOUND_ROWS();
 
--echo # Tests to reproduce Bug #3 ------------------------------------------------
 
DROP TABLE `bugtable`;
CREATE TABLE `bugtable` (
  `bugtable_int` int,
  `bugtable_varchar` varchar(64),
  KEY (`bugtable_int`)
) ENGINE=MyISAM CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
CALL fill_bugtable(150);
 
SELECT SQL_CALC_FOUND_ROWS * FROM bugtable WHERE `bugtable_int` = 0 ORDER BY bugtable_varchar LIMIT 59,2;
SELECT FOUND_ROWS();
 
SELECT SQL_CALC_FOUND_ROWS * FROM bugtable WHERE `bugtable_int` = 0 ORDER BY bugtable_varchar LIMIT 60,2;
SELECT FOUND_ROWS();
 
--echo # Tests to reproduce Bug #4 ------------------------------------------------
 
ALTER TABLE `bugtable` DROP INDEX `bugtable_int`;
 
SELECT SQL_CALC_FOUND_ROWS * FROM bugtable WHERE `bugtable_int` = 0 ORDER BY bugtable_varchar LIMIT 59,2;
SELECT FOUND_ROWS();
 
SELECT SQL_CALC_FOUND_ROWS * FROM bugtable WHERE `bugtable_int` = 0 ORDER BY bugtable_varchar LIMIT 60,2;
SELECT FOUND_ROWS();
 
drop database bugtest;

Generated at Thu Feb 08 07:17:55 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.