--source include/have_innodb.inc
--source include/not_embedded.inc
--source include/big_test.inc

--echo # Bug #23481444	OPTIMISER CALL ROW_SEARCH_MVCC() AND READ
--echo #		THE INDEX APPLIED BY UNCOMMITTED ROWS.

CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
		f2 INT NOT NULL, f3 INT NOT NULL,
		KEY(f2, f3))ENGINE=INNODB;

DELIMITER |;
CREATE PROCEDURE populate_t1(IN BASE INT, IN SIZE INT)
BEGIN
	DECLARE i INT DEFAULT BASE;
	WHILE (i <= SIZE) DO
		INSERT INTO t1(f2, f3) values (i, i);
		SET i = i + 1;
	END WHILE;
END|
DELIMITER ;|
CALL populate_t1(1, 10000);
INSERT INTO t1(f2, f3) VALUES(10000, 10000);

BEGIN;
CALL populate_t1(10001, 20000);

connect (con1,localhost,root,,);
connection con1;
SELECT SQL_NO_CACHE f2, f3 FROM t1 WHERE f2=10000 and f3 between 9999 and 10000;
connection default;
DROP TABLE t1;

CREATE TABLE t1(f2 INT NOT NULL, f3 INT NOT NULL,
		PRIMARY KEY(f2, f3))ENGINE=INNODB;

CALL populate_t1(1, 10000);

BEGIN;
CALL populate_t1(10001, 20000);

connection con1;
SELECT SQL_NO_CACHE f2, f3 FROM t1 WHERE f2=10000 and f3 between 9999 and 10000;
connection default;
DROP TABLE t1;

CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
		f2 INT NOT NULL, f3 INT NOT NULL,
		KEY(f2), KEY(f3))ENGINE=INNODB;
CALL populate_t1(1, 10000);

BEGIN;
CALL populate_t1(10001, 20000);

connection con1;
SELECT count(*) FROM t1 FORCE INDEX(f2, f3) WHERE f2 < 10000 or f3 < 10000;
connection default;
DROP TABLE t1;

CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
		f2 INT NOT NULL, f3 INT NOT NULL,
		KEY(f2, f3))ENGINE=INNODB;

CALL populate_t1(1, 10000);
CALL populate_t1(100000, 100200);

BEGIN;
CALL populate_t1(10001, 20000);

connection con1;
SELECT SQL_NO_CACHE COUNT(*) FROM t1
WHERE f2 BETWEEN 9999 AND 10000 OR f2 >= 100000;
disconnect con1;
connection default;

DROP TABLE t1;
DROP PROCEDURE populate_t1;
