2 ms·
So let’s pick the option that stores highscores and screen names in separate places, and brings them together only when needed in a leaderboard query. Is that
by onion2k 12y ago
So let’s pick the option that stores highscores and screen names in separate places, and brings them together only when needed in a leaderboard query.
Is that actually a good idea though? Leaderboard queries are likely to be the most common things you do with the data. You'd save a join by storing the username with the score data (as you'd never want one without the other), and it wouldn't save that much space by separating them given that usernames are only a few tens of bytes each.
- ifcologne 12y agoI think a more useful example would be adding further information from the users profile to a leaderboard. That could be the name in a particular game or other data from the users profile. Or - limit the leaderboard by filtering on age, region or whatever.
- onion2k 12y agoAssuming they're unique you could do that just by using the username as the key to join the score table to the user table on. Everything would be the same as the example in the article, but without the join needed when you're just getting the names with their scores. Optimising a database for storage is really only a good idea when the additional redundant data is going to take up huge amounts of space. Storage is cheap. Making a query run faster isn't. Generally speaking you're better off optimising to reduce the number of joins and subqueries because they're the things that usually slow you down.
- lobster_johnson 12y agoThat would cause problems when users are renamed. You want foreign keys (which Arango doesn't have?) and transactions, and you also want to make sure that every name change updates all foreign tables. Changing it one place eliminates all possible mistakes, which is why surrogate keys were invented. The way I like to approach performance issues like these is to cache or precompute de normalized data as needed, and make sure the master data is as clean and normalized as possible. You could have a materialized view, or a trigger that produced the denormalized version, or just store the data is Memcached.