yes or no?
by Guilherme Pereira
@guiferrpereira
We need to scale between datacenters!!!
Work in progress ...
But i love postgres... so what are my options?
Which one?
* ReQL
# PostgresDB ActiveRecord
UR.where(user: user).includes(:user_transaction)
# RethinkDB NoBrainer
UR.where(user: user).eager_load(:transaction)
# PostgresDB ActiveRecord
UR.where(uid: uids)
# RethinkDB NoBrainer
UR.where(:uid.in => uids)
Text
# PostgresDB ActiveRecord
AM.
where(uid: [nil, d.uid]).
where(hd_model: [nil, d.hd.try(:fetch, 'model', nil)]).
order('CAST(uid IS NOT NULL AS INTEGER) + CAST(hd_model IS NOT NULL AS INTEGER) DESC').
pluck(:app_id).
first
# RethinkDB NoBrainer
AM.
where(:uid.in => [nil, d.uid]).
where(:hd_model.in => [nil, d.hd.try(:fetch, 'model', nil)]).
order_by(->(doc) { (doc[:uid].nil? ? 0 : 1) + (doc[:hd_model].nil? ? 0 : 1) } => :desc).
pluck(:app_id).raw.
first.try(:[], "app_id")
# RethinkDB DIRECT ReQL (Slow!)
NoBrainer.run { |r|
r.table("transactions").merge { |transaction|
{
:usage_rights => r.table('usage_rights')
.get_all([transaction['identifier'], transaction['uid']], {
index: 'idx_identifier_uid_multi'
}).coerce_to('array')
}
}
}.count
# PostgresDB
usage_rights.
joins('JOIN transactions ON usage_rights.identifier = transactions.identifier
AND usage_rights.uid = transactions.uid')
!!! Attention this will work with javascript ReQL
You want ruby syntax go check on your irb :P
* For this you have to install python driver...
* And it's a little bit slow...
sudo pip install rethinkdb
rethinkdb dump [options]
*** My advice do table by table :)
* You have to learn new language: ReQL
* Custom querys can be messy (simple joins)
* For Master-Master replication you will need 3 servers
* (LIKE / match) don't have indexes, it will be slow
* Refactor your code to get all stuff working
* Migrate your current data