Commit cfb47ddd authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-30066 (limit + offset) union all (...) limit = incorrect result

select_union_direct::send_data() only sends a record when
the LIMIT ... OFFSET clause of the individual select won't skip it.

Thus, select_union_direct::send_data() should not do any actions
related to a sending a record if the offset of a select isn't
reached yet
parent da3fc33e
...@@ -2748,5 +2748,20 @@ a b c d ...@@ -2748,5 +2748,20 @@ a b c d
3 4 2 197 3 4 2 197
drop table t1,t2; drop table t1,t2;
# #
# MDEV-30066 (limit + offset) union all (...) limit = incorrect result
#
create table t1(id int primary key auto_increment, c1 int);
insert into t1(c1) values(1),(2),(3);
(select * from t1 where c1>=1 order by c1 desc limit 2,1) union all (select * from t1 where c1>1 order by c1 desc);
id c1
1 1
2 2
3 3
(select * from t1 where c1>=1 order by c1 desc limit 2,1) union all (select * from t1 where c1>1 order by c1 desc) limit 2;
id c1
1 1
2 2
drop table t1;
#
# End of 10.3 tests # End of 10.3 tests
# #
...@@ -1982,6 +1982,15 @@ union (select 0 as a, 99 as b, ...@@ -1982,6 +1982,15 @@ union (select 0 as a, 99 as b,
drop table t1,t2; drop table t1,t2;
--echo #
--echo # MDEV-30066 (limit + offset) union all (...) limit = incorrect result
--echo #
create table t1(id int primary key auto_increment, c1 int);
insert into t1(c1) values(1),(2),(3);
(select * from t1 where c1>=1 order by c1 desc limit 2,1) union all (select * from t1 where c1>1 order by c1 desc);
(select * from t1 where c1>=1 order by c1 desc limit 2,1) union all (select * from t1 where c1>1 order by c1 desc) limit 2;
drop table t1;
--echo # --echo #
--echo # End of 10.3 tests --echo # End of 10.3 tests
--echo # --echo #
...@@ -551,14 +551,17 @@ int select_union_direct::send_data(List<Item> &items) ...@@ -551,14 +551,17 @@ int select_union_direct::send_data(List<Item> &items)
{ {
if (!limit) if (!limit)
return false; return false;
limit--; if (!unit->offset_limit_cnt)
if (offset)
{ {
offset--; limit--;
return false; if (offset)
{
offset--;
return false;
}
send_records++;
} }
send_records++;
fill_record(thd, table, table->field, items, true, false); fill_record(thd, table, table->field, items, true, false);
if (unlikely(thd->is_error())) if (unlikely(thd->is_error()))
return true; /* purecov: inspected */ return true; /* purecov: inspected */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment