index_object:select() | Tarantool
Check out the new release policy


object index_object
index_object:select(search-key, options)

This is an alternative to…select() which goes via a particular index and can make use of additional parameters that specify the iterator type, and the limit, and the offset.

  • index_object (index_object) – an object reference.
  • key (scalar/table) – values to be matched against the index key
  • options (table/nil) –

    none, any, or all of the following parameters:

    • iterator – type of iterator
    • limit – maximum number of tuples
    • offset – start tuple number (do not use it. See warning)

the tuple or tuples that match the field values.


array of tuples


We do not recommend using the offset option for scanning large values because it linearly increases the number of scanned tuples and leads to the full scan of the space.

For unique indexes you can build cursors with pairs():

index_obj:pairs(key, {iterator = 'GT'})


-- Create a space named tester.
tarantool> sp ='tester')
-- Create a unique index 'primary'
-- which won't be needed for this example.
tarantool> sp:create_index('primary', {parts = {1, 'unsigned' }})
-- Create a non-unique index 'secondary'
-- with an index on the second field.
tarantool> sp:create_index('secondary', {
         >   type = 'tree',
         >   unique = false,
         >   parts = {2, 'string'}
         > })
-- Insert three tuples, values in field[2]
-- equal to 'X', 'Y', and 'Z'.
tarantool> sp:insert{1, 'X', 'Row with field[2]=X'}
tarantool> sp:insert{2, 'Y', 'Row with field[2]=Y'}
tarantool> sp:insert{3, 'Z', 'Row with field[2]=Z'}
-- Select all tuples where the secondary index
-- keys are greater than 'X'.
tarantool> sp.index.secondary:select({'X'}, {
         >   iterator = 'GT',
         >   limit = 1000
         > })

The result will be a table of tuple and will look like this:

- - [2, 'Y', 'Row with field[2]=Y']
  - [3, 'Z', 'Row with field[2]=Z']


The arguments are optional. If you call{}, then every key in the index is considered to be a match, regardless of the iterator type. Therefore, for the example above,{} will select every tuple in the tester space via the first (primary-key) index.


index.index-name is optional. If it is omitted, then the assumed index is the first (primary-key) index. Therefore, for the example above,{1}, {iterator = 'GT'}) would have returned the same two rows, via the ‘primary’ index.


iterator = iterator-type is optional. If it is omitted, then iterator = 'EQ' is assumed.

Note[1]. can be replaced by That is, get can be used as a convenient shorthand to get the first tuple in the tuple set that would be returned by select. However, if there is more than one tuple in the tuple set, then get throws an error.

Found what you were looking for?