I'm getting familiar with Couchbase (I'm getting started with the Server Community Edition), my goal is to migrate our current SQLite database to Couchbase in order to build an efficient real-time synchronization mechanism with mobile devices.
The first steps have been positive so far, we've created buckets (one bucket per SQLite table) and imported all data (one JSON document per SQLite row). Also, in order to allow complex queries and filtering, we've created indices (both primary and secondary) for all buckets.
To summarize, we have two main buckets:
1) players, which contains documents with the following structure
{
"name": "xxx",
"transferred": false,
"value": n,
"playmaker": false,
"role": "y",
"team": "zzz"
}
2) marks, with the following structure (where the "player" field is a reference to a document ID in the players bucket)
{
"drawgoal": 0,
"goal": 0,
"owngoal": 0,
"enter": 1,
"mpenalty": 0,
"gotgoal": 0,
"ycard": 0,
"assist": 0,
"wingoal": 0,
"mark": 6,
"penalty": 0,
"player": "xxx",
"exit": 0,
"fmark": 6,
"team": "yyy",
"rcard": 0,
"source": "zzz",
"day": 1,
"spenalty": 0
}
So good so far, however when I try to run complex N1QL queries that require a JOIN, performances are pretty bad compared to SQLite. For instance, this query takes around 3 seconds to be executed:
select mark.*, player.`role` from players player join marks mark on key mark.player for player where mark.type = "xxx" and mark.day = n order by mark.team asc, player.`role` desc;
We currently have 600 documents in players (disk used = 16MB, RAM used = 12MB) and 20K documents in marks (disk used = 70MB, RAM used = 17MB), which should not be much from my point of view.
Are there any settings I can tune to improve JOIN performance? Any specific index I can create?
Is this performance degradation the price to pay to have more flexibility and more features compared to SQLite?
Should I avoid as much as possible using JOIN in Couchbase and instead duplicate data where needed?
Thanks