Skip to content

WIP: Multipart index single field query #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crud/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ function utils.unflatten(tuple, space_format)
return object
end

function utils.extract_key(tuple, key_parts)
function utils.extract_key(tuple, key_parts, max_len)
local key = {}
for i, part in ipairs(key_parts) do
if max_len ~= nil and i > max_len then
break
end
key[i] = tuple[part.fieldno]
end
return key
Expand Down
13 changes: 0 additions & 13 deletions crud/select/executor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@ function executor.execute(space, index, filter_func, opts)
local tuples_count = 0

local value = opts.scan_value
if opts.after_tuple ~= nil then
if value == nil then
value = opts.after_tuple
else
local cmp_operator = select_comparators.get_cmp_operator(opts.tarantool_iter)
local scan_comparator = select_comparators.gen_tuples_comparator(cmp_operator, index.parts)
local after_tuple_key = utils.extract_key(opts.after_tuple, index.parts)
if scan_comparator(after_tuple_key, opts.scan_value) then
value = after_tuple_key
end
Comment on lines -56 to -61
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually after this change scroll_to_after_tuple makes fullscan. So funny that our tests don't catch it.

end
end

local tuple
local gen = index:pairs(value, {iterator = opts.tarantool_iter})

Expand Down
8 changes: 6 additions & 2 deletions crud/select/plan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,15 @@ function select_plan.new(space, conditions, opts)
if opts.first < 0 then
scan_iter = utils.invert_tarantool_iter(scan_iter)

-- scan condition becomes border consition
-- scan condition becomes border condition
scan_condition_num = nil

if scan_after_tuple ~= nil then
scan_value = utils.extract_key(scan_after_tuple, scan_index.parts)
local len
if scan_value ~= nil then
len = #scan_value
end
scan_value = utils.extract_key(scan_after_tuple, scan_index.parts, len)
else
scan_value = nil
end
Expand Down
34 changes: 32 additions & 2 deletions test/integration/select_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -897,16 +897,46 @@ pgroup:add('test_multipart_primary_index', function(g)
})

local conditions = {{'=', 'primary', 0}}
local result, err = g.cluster.main_server.net_box:call('crud.select', {'coord', conditions})
local result_0, err = g.cluster.main_server.net_box:call('crud.select', {'coord', conditions})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
local objects = crud.unflatten_rows(result_0.rows, result_0.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(coords, {1, 2, 3}))

local result, err = g.cluster.main_server.net_box:call('crud.select', {'coord', conditions,
{after = result_0.rows[1]}})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(coords, {2, 3}))

local result, err = g.cluster.main_server.net_box:call('crud.select', {'coord', conditions,
{after = result_0.rows[3], first = -2}})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(coords, {1, 2}))

local conditions = {{'=', 'primary', {0, 2}}}
local result, err = g.cluster.main_server.net_box:call('crud.select', {'coord', conditions})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(coords, {3}))

local conditions_ge = {{'>=', 'primary', 0}}
local result_ge_0, err = g.cluster.main_server.net_box:call('crud.select', {'coord', conditions_ge})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result_ge_0.rows, result_ge_0.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(coords, {1, 2, 3, 4, 5}))

local result, err = g.cluster.main_server.net_box:call('crud.select', {'coord', conditions_ge,
{after = result_ge_0.rows[1]}})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(coords, {2, 3, 4, 5}))

local result, err = g.cluster.main_server.net_box:call('crud.select', {'coord', conditions_ge,
{after = result_ge_0.rows[3], first = -3}})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(coords, {1, 2}))
end)

pgroup:add('test_select_partial_result_bad_input', function(g)
Expand Down