# ticket 895 is a query optimization problem with the primary key

--source include/have_tokudb.inc
--source include/not_5_5.inc
SET DEFAULT_STORAGE_ENGINE = 'tokudb';

--echo # Establish connection conn1 (user = root)
connect (conn1,localhost,root,,);

--disable_warnings
DROP TABLE IF EXISTS foo;
--enable_warnings

connection default;
set session transaction isolation level repeatable read;
create table foo (a int, b int, c int, primary key (a))engine=TokuDB;
insert into foo values (1,10,100),(2,20,200),(3,30,300),(4,40,400);
begin;
--echo # should read all four values
select * from foo;

connection conn1;
set session transaction isolation level repeatable read;
set session tokudb_load_save_space=0;
alter table foo add index (b);

connection default;
--echo # should read all four values
select * from foo;
--echo # should fail
--error ER_TABLE_DEF_CHANGED
select sum(b) from foo;
commit;
--echo # should return 100
select sum(b) from foo;

connection default;
disconnect conn1;

connection default;
# Final cleanup.
set session transaction isolation level serializable;
DROP TABLE foo;