2016-03-30 7 views
2

スペースusersからレコードを取得する必要があります。 この領域にはセカンダリインデックスcategory_status_ratingがあります。 は私がcategory=1status=1rating<=123456789をユーザーに選択が必要です。Tarantool:index.indexNameの制限/オフセット:pairs call

for _, user in box.space.users.index.category_status_rating:pairs({ 1, 1, 123456789 }, { limit = 20, offset = 5, iterator = box.index.LE }) do 
    if user[categoryIdx] ~= 1 or user[statusIdx] ~= 1 then break end 
    table.insert(users, user) 
end 

私が知っているように、indexName:pairsとの反復がlimitをサポートしていないと私は、ユーザー自分対抗できます。しかし、offsetはどうですか?このパラメータを使用し、必要な「ページ」から開始できますか?または、私は何もoffsetなしで反復し、役に立たない記録(約100000)を渡し、私の "ページ"が始まるときtable.insert(users, user)に始まるでしょうか? ありがとう!

+1

あなたがしたいことがあれば試してみませんか? – Piglet

答えて

3

オフセットを使用する代わりに、本当に必要な場合は、位置(最後にチェックされたタプル)を保存することができます。 例えば:

local last = 123456789 
for i = 1, 2 do 
    local count = 0 
    for _, user in box.space.users.index.category_status_rating:pairs({1, 1, last}, { iterator = box.index.LE }) do 
     if user[categoryIdx] ~= 1 or user[statusIdx] ~= 1 or count > 20 then 
      break 
     end 
     table.insert(users, user) 
     last = user[LAST_INDEX_FIELD] 
     count = count + 1 
    end 
    -- process your tuples 
end 

または、luafun(drop_nが限界のアナログであり、そしてlastに保存するオフセットのアナログである)を使用して:

local last = 123456789 
for i = 1, 2 do 
    local users = box.space.users.index.category_status_rating:pairs({1, 1, last}, { iterator = box.index.LE }):take_n(20):map(function(user) 
     last = user[LAST_INDEX_FIELD] 
     return user 
    end):totable() 
    -- process your tuples 
end 

Documentation on LuaFunembedded into Tarantoolあります。

+0

Hmm ... しかし、 'rating'が一意の値でない場合はどうなりますか? 「最後の」レコードを位置として使用する場合、「最初の20レコード」のレコードが「次の20レコード」に入ることを意味しますか? –

+0

次に、あなたが処理した 'last'という評価を持つタプルの数を数える必要があります。例えば' drop_n' – bigbes

関連する問題