@@ -6,7 +6,8 @@ local dev_checks = require('crud.common.dev_checks')
66local call = require (' crud.common.call' )
77local utils = require (' crud.common.utils' )
88local schema = require (' crud.common.schema' )
9- local Keydef = require (' crud.compare.keydef' )
9+ local has_keydef , Keydef = pcall (require , ' crud.compare.keydef' )
10+ local select_comparators = require (' crud.compare.comparators' )
1011
1112local BorderError = errors .new_class (' BorderError' , {capture_stack = false })
1213
@@ -44,14 +45,25 @@ function borders.init()
4445 _G ._crud .get_border_on_storage = get_border_on_storage
4546end
4647
47- local is_closer = function (compare_sign , keydef , tuple , res_tuple )
48- if res_tuple == nil then
49- return true
50- end
48+ local is_closer
49+
50+ if has_keydef then
51+ is_closer = function (compare_sign , keydef , tuple , res_tuple )
52+ if res_tuple == nil then
53+ return true
54+ end
5155
52- local cmp = keydef :compare (tuple , res_tuple )
56+ local cmp = keydef :compare (tuple , res_tuple )
5357
54- return cmp * compare_sign > 0
58+ return cmp * compare_sign > 0
59+ end
60+ else
61+ is_closer = function (_ , comparator , tuple , res_tuple )
62+ if res_tuple == nil then
63+ return true
64+ end
65+ return comparator (tuple , res_tuple )
66+ end
5567end
5668
5769local function call_get_border_on_router (border_name , space_name , index_name , opts )
@@ -100,7 +112,20 @@ local function call_get_border_on_router(border_name, space_name, index_name, op
100112 end
101113
102114 local compare_sign = border_name == ' max' and 1 or - 1
103- local keydef = Keydef .new (space , field_names , index .id )
115+ local comparator
116+ if has_keydef then
117+ comparator = Keydef .new (space , field_names , index .id )
118+ else
119+ local tarantool_iter
120+ if compare_sign > 0 then
121+ tarantool_iter = box .index .GT
122+ else
123+ tarantool_iter = box .index .LT
124+ end
125+ local key_parts = utils .merge_primary_key_parts (index .parts , primary_index .parts )
126+ local cmp_operator = select_comparators .get_cmp_operator (tarantool_iter )
127+ comparator = select_comparators .gen_tuples_comparator (cmp_operator , key_parts , field_names , space :format ())
128+ end
104129
105130 local res_tuple = nil
106131 for _ , storage_result in pairs (results ) do
@@ -111,7 +136,7 @@ local function call_get_border_on_router(border_name, space_name, index_name, op
111136 end
112137
113138 local tuple = storage_result .res
114- if tuple ~= nil and is_closer (compare_sign , keydef , tuple , res_tuple ) then
139+ if tuple ~= nil and is_closer (compare_sign , comparator , tuple , res_tuple ) then
115140 res_tuple = tuple
116141 end
117142 end
0 commit comments