Skip to content
Snippets Groups Projects
Commit 6353a3a6 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Fixes and test cases for Bug#729758, Bug#729879

A fix and a test case for

https://bugs.launchpad.net/tarantool/+bug/729758
"SELECT fails with a disjunct and small LIMIT"

and

https://bugs.launchpad.net/tarantool/+bug/729879
"Zero limit is treated the same as no limit"

These were simple coding bugs in SELECT main loop.
parent 7aa6cc8a
No related branches found
No related tags found
No related merge requests found
......@@ -558,6 +558,11 @@ process_select(struct box_txn *txn, u32 limit, u32 offset, struct tbuf *data)
if (txn->index->type == TREE) {
for (u32 i = 0; i < count; i++) {
/* End the loop if reached the limit. */
if (limit == *found)
goto end;
u32 key_len = read_u32(data);
void *key = read_field(data);
......@@ -578,17 +583,19 @@ process_select(struct box_txn *txn, u32 limit, u32 offset, struct tbuf *data)
continue;
}
(*found)++;
tuple_add_iov(txn, tuple);
if (--limit == 0)
if (limit == ++(*found))
break;
}
if (limit == 0)
break;
}
} else {
for (u32 i = 0; i < count; i++) {
/* End the loop if reached the limit. */
if (limit == *found)
goto end;
u32 key_len = read_u32(data);
if (key_len != 1)
box_raise(ERR_CODE_ILLEGAL_PARAMS,
......@@ -603,17 +610,15 @@ process_select(struct box_txn *txn, u32 limit, u32 offset, struct tbuf *data)
continue;
}
(*found)++;
tuple_add_iov(txn, tuple);
if (--limit == 0)
break;
(*found)++;
}
}
if (data->len != 0)
box_raise(ERR_CODE_ILLEGAL_PARAMS, "can't unpack request");
end:
return ERR_CODE_OK;
}
......
A test case for Bug#729758
"SELECT fails with a disjunct and small LIMIT"
https://bugs.launchpad.net/tarantool/+bug/729758
insert into t0 values ('Doe', 'Richard')
Insert OK, 1 row affected
insert into t0 values ('Roe', 'Richard')
......@@ -15,4 +20,32 @@ Insert OK, 1 row affected
insert into t0 values ('Callaghan', 'Tomas')
Insert OK, 1 row affected
select * from t0 where k1='Richard' or k1='Tomas' or k1='Tomas' limit 5
An error occurred: ERR_CODE_ILLEGAL_PARAMS, 'Illegal parameters'
Found 5 tuples:
['Doe', 'Richard']
['Roe', 'Richard']
['Woe', 'Richard']
['Major', 'Tomas']
['Kytes', 'Tomas']
A test case for Bug#729879
"Zero limit is treated the same as no limit"
https://bugs.launchpad.net/tarantool/+bug/729879
select * from t0 where k1='Richard' or k1='Tomas' limit 0
No match
delete from t0 where k0='Doe'
Delete OK, 1 row affected
delete from t0 where k0='Roe'
Delete OK, 1 row affected
delete from t0 where k0='Woe'
Delete OK, 1 row affected
delete from t0 where k0='Major'
Delete OK, 1 row affected
delete from t0 where k0='Kytes'
Delete OK, 1 row affected
delete from t0 where k0='Stiles'
Delete OK, 1 row affected
delete from t0 where k0='Wales'
Delete OK, 1 row affected
delete from t0 where k0='Callaghan'
Delete OK, 1 row affected
# encoding: tarantool
#
print """
A test case for Bug#729758
"SELECT fails with a disjunct and small LIMIT"
https://bugs.launchpad.net/tarantool/+bug/729758
"""
exec sql "insert into t0 values ('Doe', 'Richard')"
exec sql "insert into t0 values ('Roe', 'Richard')"
......@@ -8,7 +14,22 @@ exec sql "insert into t0 values ('Kytes', 'Tomas')"
exec sql "insert into t0 values ('Stiles', 'Tomas')"
exec sql "insert into t0 values ('Wales', 'Tomas')"
exec sql "insert into t0 values ('Callaghan', 'Tomas')"
# xxx: bug
exec sql "select * from t0 where k1='Richard' or k1='Tomas' or k1='Tomas' limit 5"
print """
A test case for Bug#729879
"Zero limit is treated the same as no limit"
https://bugs.launchpad.net/tarantool/+bug/729879
"""
exec sql "select * from t0 where k1='Richard' or k1='Tomas' limit 0"
# Cleanup
exec sql "delete from t0 where k0='Doe'"
exec sql "delete from t0 where k0='Roe'"
exec sql "delete from t0 where k0='Woe'"
exec sql "delete from t0 where k0='Major'"
exec sql "delete from t0 where k0='Kytes'"
exec sql "delete from t0 where k0='Stiles'"
exec sql "delete from t0 where k0='Wales'"
exec sql "delete from t0 where k0='Callaghan'"
# vim: syntax=python
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment