3

Trying to to send multiple select in a single batch fails with error message:

Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed.

What is the best way to send multiple distinct queries (e.g id=x, id=y, id=z).

Aaron
  • 55,518
  • 11
  • 116
  • 132
Doron Levi
  • 458
  • 4
  • 16

1 Answers1

1

You can't do this for selects, and it's really doesn't make sense imho. Send each query as a separate requests & collect results.

If the where condition is “the same”, you can use IN operator, although it may increase load onto coordinator. Like, where id IN (x, y, z)

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • Why not? I can do this with Dynamodb (which I am trying to migrate from) I just want to send a bunch of selects, actually it is a list of primary keys (partition key + one clustering key) and get back the records in a single call – Doron Levi Nov 22 '21 at 18:50
  • See update about IN. But it won’t work well with multiple columns. Plus, separate queries will be faster because request will be sent to a node that holds there data – Alex Ott Nov 22 '21 at 18:53
  • Thanks Alex, just to nail it down, from your experience, should be more scaleable send like 100 separate requests with single select than on select using id IN (id1, id2... id100)? – Doron Levi Nov 22 '21 at 19:36
  • Yes, single selects could be better - but harder on implementation side. Under the hood IN works as follows - query is sent to random node (because there is no routing key), that node splits it into individual queries that are sent to corresponding nodes, wait for all results, return data to a driver. So there are not necessary network hops, and wait time – Alex Ott Nov 22 '21 at 19:48