3 ms·
NoSQL is basically a hash table. They are much faster than relational databases since hash table lookups are quick O(1). However they don't provide the ability
by jwegan 16y ago
NoSQL is basically a hash table. They are much faster than relational databases since hash table lookups are quick O(1). However they don't provide the ability to query the database like you can in SQL. For example, you cannot select all the items whose price is > $20 unless you iterate through every item in the NoSQL store yourself and check if the price is > $20.
So why would you use NoSQL rather than just our own hashtable? NoSQL allows you to keep a hash table separate from the application server so you can devote an entire servers RAM to the table to increase performance. It also allows you to distribute the table across multiple machines to in essence create a big distributed hashtable. NoSQL is great replacement for any type of data that you would have previously accessed by doing a "SELECT * FROM table WHERE primary_key = ?". Furthermore since NoSQL doesn't have to do indexing, or any of the other overhead associated with a normal relational database it can be much faster.
- cubes 16y agoThis is not really accurate. Some NoSQL solutions, such as Memcached, MemcacheDB, and REDIS are key-value stores, i.e. hash tables. Other solutions, such as Cassandra, MongoDB, and CouchDB provide richer semantics that make it possible to perform efficient range queries and map-reduce queries. Cassandra and MongoDB both use indices to improve query performance. One of the primary advantages of the various NoSQL solutions is that they make it easy to scale horizontally, i.e. to add capacity by simply adding another host machine. This is in contrast to traditional relational databases, which are typically hard to scale horizontally.
- qq66 16y agoThanks. So when they say Facebook messages use NoSQL, how do they show you all messages WHERE recipient=you if these queries are expensive?
- cubes 16y agoFacebook uses Cassandra, and, with properly designed schema, those queries are actually cheap, and, better yet, distributed across a cluster of machines. You can read about Cassandra here: http://cassandra.apache.org/ http://cassandra.apache.org/
- jwegan 16y agoWell cubes says Cassandra isn't purely a key value store and I haven't used it so I don't know its exact capabilities. However, to answer your question, what you could do is keep another entry in the table where the key is the user id and the value is a vector of all the messages sent to that user id.