Skip to content

Commit d4ed93a

Browse files
oleg-jukovecDifferentialOrange
authored andcommitted
select: fix LE and after results when the condition value < after
LE with after has always been replaced by LT. The idea was to start traverse not from the after value, but from a next value. The micro-optimization allowed to fetch one less tuple per time. But this caused the condition value to be skipped if the value is less than the after value.
1 parent 1635f16 commit d4ed93a

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
### Changed
1313

1414
### Fixed
15+
* `crud.select()` if a condition is '<=' and it's value < `after`.
16+
17+
Before this patch:
18+
19+
tarantool> crud.select('developers', {{'<=', 'id', 3}}, {first = 10, after = rows[5]}).rows
20+
---
21+
- - [2, 401, 'Sergey', 'Allred', 21]
22+
- [1, 477, 'Alexey', 'Adams', 20]
23+
...
24+
25+
After this patch:
26+
27+
tarantool> crud.select('developers', {{'<=', 'id', 3}}, {first = 10, after = rows[5]}).rows
28+
---
29+
- - [3, 2804, 'Pavel', 'Adams', 27]
30+
- [2, 401, 'Sergey', 'Allred', 21]
31+
- [1, 477, 'Alexey', 'Adams', 20]
32+
...
1533

1634
## [0.11.2] - 23-05-22
1735

crud/compare/plan.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ function plan.new(space, conditions, opts)
266266
-- Moreover, for correct pagination we change iterator
267267
-- to continue iterating in direct and reverse order.
268268
if scan_after_tuple ~= nil then
269-
if scan_iter == box.index.LE then
270-
scan_iter = box.index.LT
271-
elseif scan_iter == box.index.EQ then
269+
if scan_iter == box.index.EQ then
272270
scan_iter = box.index.GE
273271
elseif scan_iter == box.index.REQ then
274272
scan_iter = box.index.LT

test/integration/select_test.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,14 @@ pgroup.test_le_condition_with_index = function(g)
592592
t.assert_equals(err, nil)
593593
local objects = crud.unflatten_rows(result.rows, result.metadata)
594594
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {1})) -- in age order
595+
596+
-- after obj 2
597+
local after = crud_utils.flatten(customers[2], g.space_format)
598+
local result, err = g.cluster.main_server.net_box:call('crud.select', {'customers', conditions, {after=after}})
599+
600+
t.assert_equals(err, nil)
601+
local objects = crud.unflatten_rows(result.rows, result.metadata)
602+
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {3, 1})) -- in age order
595603
end
596604

597605
pgroup.test_lt_condition_with_index = function(g)

test/unit/select_plan_test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ g.test_first = function()
254254
t.assert_equals(plan.scan_value, {777}) -- after_tuple id
255255
t.assert_equals(plan.after_tuple, after_tuple)
256256
t.assert_equals(plan.scan_condition_num, nil)
257-
t.assert_equals(plan.tarantool_iter, box.index.LT) -- inverted iterator
257+
t.assert_equals(plan.tarantool_iter, box.index.LE) -- inverted iterator
258258
t.assert_equals(plan.total_tuples_count, 10)
259259
t.assert_equals(plan.sharding_key, nil)
260260
t.assert_equals(plan.field_names, nil)

0 commit comments

Comments
 (0)