diff --git a/mod/silverbox/box.c b/mod/silverbox/box.c index 069cd7a339396244f3c3872a959ce2097dbe1eae..0432b436a9f604fda40aecae64627ab5f984e235 100644 --- a/mod/silverbox/box.c +++ b/mod/silverbox/box.c @@ -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; } diff --git a/test/box_big/sql.result b/test/box_big/sql.result index 5e9737fdf00dd47ddea9836312a004a97daf8bd7..0aacd2ae1b46e7d498f66e35bea217886025a90e 100644 --- a/test/box_big/sql.result +++ b/test/box_big/sql.result @@ -1,3 +1,8 @@ + +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 diff --git a/test/box_big/sql.test b/test/box_big/sql.test index 8fc4b331350db63cbb06aab32befde1f537d067b..5d94e8911db648736450ce5e13640cbd75fce905 100644 --- a/test/box_big/sql.test +++ b/test/box_big/sql.test @@ -1,4 +1,10 @@ # 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