In MySQL I can do something like this:
-- post_id-user_id is unique pair
INSERT INTO userviews(post_id, user_id, view_count)
VALUES(1,1,1),(2,1,1),(3,1,1),(4,1,1)
ON DUPLICATE KEY UPDATE
view_count = view_count + 1;
Or in PostgreSQL:
INSERT INTO userviews(post_id, user_id, view_count)
VALUES(1,1,1),(2,1,1),(3,1,1),(4,1,1)
ON CONFLICT DO UPDATE SET view_count = view_count + 1;
How to do this kind of thing in Tarantool? (Currently I'm using Tarantool's library to upsert in a loop):
import "github.com/tarantool/go-tarantool"
type AX []interface{}
...
for ... {
conn.Upsert(`userviews`, tuple, AX{AX{`+`,viewCountColumn, 1}})
}
I guess the problem you aim to solve is about performance. The naive variant (perform an operation, wait for a response, continue with the next operation) would give about (1 / network RTT) RPS at max: it is about 1000 RPS for 1ms RTT.
There are the following options:
You can also use 'eval' operation without having a function on the server side, but it requires 'execute' permission on 'universe' and so usually discouraged (except for testing and experimenting purposes).