N1QL Join Vs Batch get


We are considering moving our implementation to N1QL join, from our current bulk get implementations, but we have some performance question raised.
Given the following keys/documents:
primary:0 => { “id” : 0, “_foreignKey” : “fk:0” }
fk:0 => { “id” : 0, “content” : “more content for primary 0” }

Performance wise, what is better:
A. Performing a bulk get for the two keys, then join them in the application code.
B. Performing a N1QL query (i.e select: SELECT * from test a USE KEYS “primary:0” left join test pk ON KEYS a._foreignKey).

Some of my observations:
A. Code readability and maintain: the second one is much better.
B. Performance wise: the first one looks better as the client will request directly the relevant nodes for the keys, while in the second option the client will go to one node (I assume the one having the “primary:0” key), and this node will query the other nodes for the foreign keys (scatter getter) and return the result to the client.

Any elaborations on how performance can be effected moving the implementation to N1QL ?



Hi Idan,

Under the covers, N1QL joins do not perform a scatter gather. Given the keys from the left hand term, N1QL is able to go to the correct nodes to fetch the right hand terms. This is the same as what your application would do.