Skip to content

Commit

Permalink
Optimize select with known bucket_id
Browse files Browse the repository at this point in the history
After this patch, select and pairs requests will no longer fetch
sharding key info and extract sharding key info if bucket_id specified.
Since calls with specified bucket_id already ignore sharding key
values, behavior will not change. Other crud operations already have
this optimization.

Based on test runs on HP ProBook 440 G7 i7/16Gb, performance had
increased by 6-7%.

Part of #234
  • Loading branch information
DifferentialOrange committed Feb 25, 2022
1 parent 920523e commit fc2e693
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Integrate CRUD statistics with [`metrics`](https://github.com/tarantool/metrics) (#224).

### Changed
* Optimize select with known bucket_id (#234).

### Fixed

Expand Down
15 changes: 9 additions & 6 deletions crud/compare/plan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function plan.new(space, conditions, opts)
field_names = '?table',
force_map_call = '?boolean',
sharding_key_as_index_obj = '?table',
bucket_id = '?number|cdata',
})

conditions = conditions ~= nil and conditions or {}
Expand Down Expand Up @@ -274,14 +275,16 @@ function plan.new(space, conditions, opts)
end
end

local sharding_index = opts.sharding_key_as_index_obj or primary_index
local sharding_key = nil
if opts.bucket_id == nil then
local sharding_index = opts.sharding_key_as_index_obj or primary_index

-- get sharding key value
local sharding_key = get_sharding_key_from_scan_value(scan_value, scan_index, scan_iter, sharding_index)
sharding_key = get_sharding_key_from_scan_value(scan_value, scan_index, scan_iter, sharding_index)

if sharding_key == nil then
sharding_key = extract_sharding_key_from_conditions(conditions, sharding_index,
space_indexes, fieldno_map)
if sharding_key == nil then
sharding_key = extract_sharding_key_from_conditions(conditions, sharding_index,
space_indexes, fieldno_map)
end
end

local plan = {
Expand Down
12 changes: 9 additions & 3 deletions crud/select/compat/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ local function build_select_iterator(space_name, user_conditions, opts)
return nil, SelectError:new("Space %q doesn't exist", space_name), true
end
local space_format = space:format()
local sharding_key_as_index_obj, err = sharding_metadata_module.fetch_sharding_key_on_router(space_name)
if err ~= nil then
return nil, err

local sharding_key_as_index_obj = nil
-- We don't need sharding info if bucket_id specified.
if opts.bucket_id == nil then
sharding_key_as_index_obj, err = sharding_metadata_module.fetch_sharding_key_on_router(space_name)
if err ~= nil then
return nil, err
end
end

-- plan select
Expand All @@ -63,6 +68,7 @@ local function build_select_iterator(space_name, user_conditions, opts)
after_tuple = opts.after,
field_names = opts.field_names,
sharding_key_as_index_obj = sharding_key_as_index_obj,
bucket_id = opts.bucket_id,
})

if err ~= nil then
Expand Down
12 changes: 9 additions & 3 deletions crud/select/compat/select_old.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ local function build_select_iterator(space_name, user_conditions, opts)
return nil, SelectError:new("Space %q doesn't exist", space_name), true
end
local space_format = space:format()
local sharding_key_as_index_obj, err = sharding_metadata_module.fetch_sharding_key_on_router(space_name)
if err ~= nil then
return nil, err

local sharding_key_as_index_obj = nil
-- We don't need sharding info if bucket_id specified.
if opts.bucket_id == nil then
sharding_key_as_index_obj, err = sharding_metadata_module.fetch_sharding_key_on_router(space_name)
if err ~= nil then
return nil, err
end
end

-- plan select
Expand All @@ -124,6 +129,7 @@ local function build_select_iterator(space_name, user_conditions, opts)
field_names = opts.field_names,
force_map_call = opts.force_map_call,
sharding_key_as_index_obj = sharding_key_as_index_obj,
bucket_id = opts.bucket_id,
})

if err ~= nil then
Expand Down

0 comments on commit fc2e693

Please sign in to comment.