Description:
Table with 1024 rows.
select * from t1 limit 1
properly gives:
Handler_read_rnd_next 1
But
select * from t1 union all select * from t1 limit 1
gives
Handler_read_rnd_next 1027
in 5.5 and 5.6,
Handler_read_rnd_next 2050
in 5.7.
So 5.7 is twice worse than 5.5/6. But even 5.5/6 are inefficient: as soon as the LIMIT has been satisfied (i.e. one row has been effectively sent to the client), there is no reason to continue reading rows from t1 (to just discard them immediately!): statement should stop executing (if there were ORDER BY it would be different). Just like the non-UNION version.
How to repeat:
create table t1(a int);
insert into t1 values(1);
insert into t1 select a+1 from t1;
insert into t1 select a+1 from t1;
insert into t1 select a+1 from t1;
insert into t1 select a+1 from t1;
insert into t1 select a+1 from t1;
insert into t1 select a+1 from t1;
insert into t1 select a+1 from t1;
insert into t1 select a+1 from t1;
insert into t1 select a+1 from t1;
insert into t1 select a+1 from t1;
select count(*) from t1;
flush status; select * from t1 limit 1; show status like "handler_read%";
flush status; select * from t1 union all select * from t1 limit 1; show status like "handler_read%";
drop table t1;