How to get only one field from Tarantool Database by index with go-tarantool - Stack Overflow

admin2025-04-25  2

Is there way to get only one field from tarantool db, not whole table?

Currently my request looks like:

result := Result{}
err := tConn.Do(tarantool.NewSelectRequest(spaceName).
    Context(ctx).
    Index("primary").
    Key(tarantool.IntKey{I: id}).
    Limit(1),
).GetTyped(&result)

but want something like this:

result := Result{}
err := tConn.Do(tarantool.NewSelectRequest(spaceName).
    Context(ctx).
    Index("primary").
    Key(tarantool.IntKey{I: id}).
    QueryFieldName("field_name").
    Limit(1),
).GetTyped(&result)

Is it even possible?

I tried to use sql syntax with go-tarantool. But it's going to be deprecated. And i doubt that perfomance wise, and that it's really getting only one field under the hood. Didn't find anything in official godoc nor googling didn't help me.

Is there way to get only one field from tarantool db, not whole table?

Currently my request looks like:

result := Result{}
err := tConn.Do(tarantool.NewSelectRequest(spaceName).
    Context(ctx).
    Index("primary").
    Key(tarantool.IntKey{I: id}).
    Limit(1),
).GetTyped(&result)

but want something like this:

result := Result{}
err := tConn.Do(tarantool.NewSelectRequest(spaceName).
    Context(ctx).
    Index("primary").
    Key(tarantool.IntKey{I: id}).
    QueryFieldName("field_name").
    Limit(1),
).GetTyped(&result)

Is it even possible?

I tried to use sql syntax with go-tarantool. But it's going to be deprecated. And i doubt that perfomance wise, and that it's really getting only one field under the hood. Didn't find anything in official godoc nor googling didn't help me.

Share Improve this question asked Jan 16 at 11:40 nurbol nurbolnurbol nurbol 231 silver badge2 bronze badges 2
  • I understood it as follows: you want to fetch just one field of a tuple, not the whole tuple. There is no such request in tarantool's binary protocol. However, you can define a server side function in tarantool that takes the field and call this function from the connector. Anyway, what is the root problem? Do you want to optimize network bandwith usage? What are typical tuple and field sizes? – Alexander Turenko Commented Jan 16 at 12:46
  • Ty for comment, i will try your solution. You got it right, i want to optimize network bandwidth usage, by reducing response size. My problem is that tuple is too big, more than hundred fields, but some requests needs only one or two fields. – nurbol nurbol Commented Jan 21 at 7:06
Add a comment  | 

1 Answer 1

Reset to default 1

There is no proper API in select. If you want to fetch a single tuple field from the Tarantool instance (and not "fetch all, extract one on the client"), you should create a Lua store procedure and Call it or send the procedure code in Eval request. Lua code will be something like

return box.space['my_space'].index['my_index']:select({key})[my_field]

You can pass arguments into these procedures as well.

转载请注明原文地址:http://anycun.com/QandA/1745534380a90880.html