0

box.space.test.index.secondary:select({1,'RU', 2})

---
- - [47, 6, 1, 'RU', 2, 11, 6]
  - [44, 3, 1, 'RU', 2, 101, 6]
  - [42, 1, 1, 'RU', 2, 189, 6]
  - [34, 3, 1, 'RU', 2, 260, 5]
  - [49, 8, 1, 'RU', 2, 290, 6]
  - [41, 0, 1, 'RU', 2, 303, 6]
  - [37, 6, 1, 'RU', 2, 494, 5]
  - [35, 4, 1, 'RU', 2, 633, 5]
  - [45, 4, 1, 'RU', 2, 694, 6]
  - [43, 2, 1, 'RU', 2, 780, 6]
  - [46, 5, 1, 'RU', 2, 833, 6]
  - [40, 9, 1, 'RU', 2, 870, 5]
  - [48, 7, 1, 'RU', 2, 927, 6]
  - [50, 9, 1, 'RU', 2, 930, 6]
...

box.space.test.index.secondary

---
- unique: false
  parts:
  - type: NUM
    fieldno: 3
  - type: STR
    fieldno: 4
  - type: NUM
    fieldno: 5
  - type: NUM
    fieldno: 6
  id: 2
  space_id: 512
  name: secondary
  type: TREE
...

local r='' for k,tuple in box.space.test.index.secondary:pairs({1, 'RU', 2}) do r=r..', found ('..tuple[1]..')' if (tuple[7]<6) then r = r .. ', delete(' ..tuple[1] .. ')' box.space.test:delete(tuple[1]) end end return r

---
- ', found (47), found (44), found (42), found (34), delete(34), found (41), found(37), delete(37), found (45), found (43), found (46), found (40), delete(40), found(50)'
...

box.space.test.index.secondary:select({1,'RU', 2})

---
- - [47, 6, 1, 'RU', 2, 11, 6]
  - [44, 3, 1, 'RU', 2, 101, 6]
  - [42, 1, 1, 'RU', 2, 189, 6]
  - [49, 8, 1, 'RU', 2, 290, 6]
  - [41, 0, 1, 'RU', 2, 303, 6]
  - [35, 4, 1, 'RU', 2, 633, 5]
  - [45, 4, 1, 'RU', 2, 694, 6]
  - [43, 2, 1, 'RU', 2, 780, 6]
  - [46, 5, 1, 'RU', 2, 833, 6]
  - [48, 7, 1, 'RU', 2, 927, 6]
  - [50, 9, 1, 'RU', 2, 930, 6]
...

local r='' for k,tuple in box.space.test.index.secondary:pairs({1, 'RU', 2}) do r=r..', found ('..tuple[1]..')' if (tuple[7]<6) then r = r .. ', delete(' ..tuple[1] .. ')' box.space.test:delete(tuple[1]) end end return r

---
- ', found (47), found (44), found (42), found (49), found (41), found (35), delete(35), found (43), found (46), found (48), found (50)'
...

box.space.test.index.secondary:select({1,'RU', 2})

---
- - [47, 6, 1, 'RU', 2, 11, 6]
  - [44, 3, 1, 'RU', 2, 101, 6]
  - [42, 1, 1, 'RU', 2, 189, 6]
  - [49, 8, 1, 'RU', 2, 290, 6]
  - [41, 0, 1, 'RU', 2, 303, 6]
  - [45, 4, 1, 'RU', 2, 694, 6]
  - [43, 2, 1, 'RU', 2, 780, 6]
  - [46, 5, 1, 'RU', 2, 833, 6]
  - [48, 7, 1, 'RU', 2, 927, 6]
  - [50, 9, 1, 'RU', 2, 930, 6]
...

As I see :pairs don't see 35 tuple in first run, and see it only on second execution. Why?

p.s.: sorry for long explanation...

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sergey
  • 11
  • 2
  • It return only unique (by fields from index) tuples?... – Sergey Jun 01 '17 at 14:12
  • Or maybe tarantool move internal pointer to next tuple in list, when we :delete tuple by primary key..? – Sergey Jun 01 '17 at 14:22
  • I found answer myself. Tarantool rebuild index during loop, so when i iterate in pairs I skip some records. Correct is get portion of tuples by select, iterate it deleting each one, get new portion .... while data exists. – Sergey Jun 01 '17 at 16:21

0 Answers0