on the concatMap api page in RethinkDB website, it's saying eqJoin is implemented with concatMap + getAll, which should provide better performance than other joins.
in my case, I'd like to join multiple tables, here's an example, let's assume I have 3 tables, users
, departments
and companies
. in every user
document would contain a department id
and company id
. eg:
var user = {
name: 'Peter',
company: '12345',
department: '8888',
otherDetails: 'abc 123'
}
the result I'd like to get after the join query is very similar to the result of a concatMap/eqJoin, but with all 3 tables:
[{
user: {...},
company: {...},
department: {...}
}, ...]
here is a query I've written that could get the result:
r.table('users')
.concatMap(function(user) {
return r.table("companies").getAll(
user("company")
).map(function(company) {
return { user: user, company: company }
})
})
.concatMap(function(row) {
return r.table("departments").getAll(
row("user")("department")
).map(function(department) {
return { user: row("user"), company: row("company"), department: department }
})
})
my questions:
- is there a better way to do this?
- is the performance of the above query still as good as usual eqJoin on 2 tables?
- is the performance of using merge much worse than using eqJoin (concatMap) in these cases?
thanks much.