Reputation: 23
I am a new user of RethinkDB. Could anyone tell me if every time that I receive changes on a table, through the Changefeeds feature, the query needs to reevaluated every time?
For example, a query that return all the users from a specified country. Two tables: users and countries. I allways want to know all the users from that country. I ask because if my table has a lot of records (millions) could be a bit expensive...
Thanks in advance, Humberto
Upvotes: 2
Views: 569
Reputation: 4614
The answer is... it depends on what you want to do and how your query is structured.
#1 Simple Queries
If you have a simple filter query that is listening for changes on all 'users' from a particular country, your query won't get reevaluated every single time. RethinkDB handles that automatically and it's not an expensive operation. In terms of performance, this is the preferred strategy.
Example:
r.table('users')
.filter({ country: "China })
.changes()
You can also listen to users from multiple countries in the same query:
var countries = [ 'China', 'India', 'Colombia', 'Mexico', 'United States' ];
r.table('users')
.filter(function (row) {
return r.expr(countries).contains(row('country'));
})
.changes()
#2 Simple Queries with single join
If, when you get an update on the user, but you also want to join the country data from the 'countries' table, you can do that after the changes
with a merge
and a get
.
r.table('users')
.filter({ country_name: "China })
.changes()
.merge(function (row) {
return {
'country': r.table('countries').get(row('country_name'))
}
})
This will join the data every time there's an update, but it's more expensive than the previous one because, every time there is an update, it will have to do a point read in the 'countries' table.
#3 Alternative to #2
If you don't want to do this, but want to still join the countries to the 'users' table, you could do the joins in your application layer.
Upvotes: 2