Skip to content

Commit b0b9690

Browse files
Optimize select with known bucket_id
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
1 parent 920523e commit b0b9690

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
* Integrate CRUD statistics with [`metrics`](https://github.com/tarantool/metrics) (#224).
1313

1414
### Changed
15+
* Optimize select with known bucket_id (#234).
1516

1617
### Fixed
1718

crud/compare/plan.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ function plan.new(space, conditions, opts)
168168
field_names = '?table',
169169
force_map_call = '?boolean',
170170
sharding_key_as_index_obj = '?table',
171+
bucket_id = '?number|cdata',
171172
})
172173

173174
conditions = conditions ~= nil and conditions or {}
@@ -274,14 +275,16 @@ function plan.new(space, conditions, opts)
274275
end
275276
end
276277

277-
local sharding_index = opts.sharding_key_as_index_obj or primary_index
278+
local sharding_key = nil
279+
if opts.bucket_id == nil then
280+
local sharding_index = opts.sharding_key_as_index_obj or primary_index
278281

279-
-- get sharding key value
280-
local sharding_key = get_sharding_key_from_scan_value(scan_value, scan_index, scan_iter, sharding_index)
282+
sharding_key = get_sharding_key_from_scan_value(scan_value, scan_index, scan_iter, sharding_index)
281283

282-
if sharding_key == nil then
283-
sharding_key = extract_sharding_key_from_conditions(conditions, sharding_index,
284-
space_indexes, fieldno_map)
284+
if sharding_key == nil then
285+
sharding_key = extract_sharding_key_from_conditions(conditions, sharding_index,
286+
space_indexes, fieldno_map)
287+
end
285288
end
286289

287290
local plan = {

crud/select/compat/select.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ local function build_select_iterator(space_name, user_conditions, opts)
5252
return nil, SelectError:new("Space %q doesn't exist", space_name), true
5353
end
5454
local space_format = space:format()
55-
local sharding_key_as_index_obj, err = sharding_metadata_module.fetch_sharding_key_on_router(space_name)
56-
if err ~= nil then
57-
return nil, err
55+
56+
local sharding_key_as_index_obj = nil
57+
-- We don't need sharding info if bucket_id specified.
58+
if opts.bucket_id == nil then
59+
sharding_key_as_index_obj, err = sharding_metadata_module.fetch_on_router(space_name)
60+
if err ~= nil then
61+
return nil, err
62+
end
5863
end
5964

6065
-- plan select
@@ -63,6 +68,7 @@ local function build_select_iterator(space_name, user_conditions, opts)
6368
after_tuple = opts.after,
6469
field_names = opts.field_names,
6570
sharding_key_as_index_obj = sharding_key_as_index_obj,
71+
bucket_id = opts.bucket_id,
6672
})
6773

6874
if err ~= nil then

crud/select/compat/select_old.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ local function build_select_iterator(space_name, user_conditions, opts)
112112
return nil, SelectError:new("Space %q doesn't exist", space_name), true
113113
end
114114
local space_format = space:format()
115-
local sharding_key_as_index_obj, err = sharding_metadata_module.fetch_sharding_key_on_router(space_name)
116-
if err ~= nil then
117-
return nil, err
115+
116+
local sharding_key_as_index_obj = nil
117+
-- We don't need sharding info if bucket_id specified.
118+
if opts.bucket_id == nil then
119+
sharding_key_as_index_obj, err = sharding_metadata_module.fetch_on_router(space_name)
120+
if err ~= nil then
121+
return nil, err
122+
end
118123
end
119124

120125
-- plan select
@@ -124,6 +129,7 @@ local function build_select_iterator(space_name, user_conditions, opts)
124129
field_names = opts.field_names,
125130
force_map_call = opts.force_map_call,
126131
sharding_key_as_index_obj = sharding_key_as_index_obj,
132+
bucket_id = opts.bucket_id,
127133
})
128134

129135
if err ~= nil then

0 commit comments

Comments
 (0)